<commit_before><?php

namespace WsdlToPhp\PackageGenerator\Model;

use WsdlToPhp\PackageGenerator\Generator\Generator;
use WsdlToPhp\PackageGenerator\Generator\Utils;

/**
 * Class StructValue stands for an enumeration value
 */
class StructValue extends AbstractModel
{
    /**
     * @var string
     */
    const MATCH_PATTERN = '/([[:upper:]]+[[:lower:]]*)|([[:lower:]]+)|(\d+)/';
    /**
     * @var string
     */
    const REAPLCEMENT_PATTERN = '$1$2$3_';
    /**
     * Store the constants generated per structName
     * @var array
     */
    private static $uniqueConstants = array();
    /**
     * The index of the value in the enumeration struct
     * @var int
     */
    private $index = 0;
    /**
     * Main constructor
     * @see AbstractModel::__construct()
     * @uses AbstractModel::setOwner()
     * @uses StructValue::setIndex()
     * @param Generator $generator
     * @param string $name the original name
     * @param string $index the index of the value in the enumeration struct
     * @param Struct $struct defines the struct which owns this value
     */
    public function __construct(Generator $generator, $name, $index, Struct $struct)
    {
        parent::__construct($generator, $name);
        $this->setIndex($index);
        $this->setOwner($struct);
    }
    /**
     * Returns the name of the value as constant
     * @see AbstractModel::getCleanName()
     * @uses AbstractModel::getCleanName()
     * @uses AbstractModel::getName()
     * @uses AbstractModel::getOwner()
     * @uses StructValue::constantSuffix()
     * @uses StructValue::getIndex()
     * @uses StructValue::getOwner()
     * @uses Generator::getOptionGenericConstantsNames()
     * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores
     * @return string
     */
    public function getCleanName($keepMultipleUnderscores = false)
    {
        if ($this->getGenerator()->getOptionGenericConstantsNames()) {
            return 'ENUM_VALUE_' . $this->getIndex();
        } else {
            $nameWithSeparatedWords = $this->getNameWithSeparatedWords($keepMultipleUnderscores);
            $key = self::constantSuffix($this->getOwner()->getName(), $nameWithSeparatedWords, $this->getIndex());
            return 'VALUE_' . strtoupper($nameWithSeparatedWords . ($key ? '_' . $key : ''));
        }
    }
    /**
     * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores
     * @return string
     */
    public function getNameWithSeparatedWords($keepMultipleUnderscores = false)
    {
        return trim(self::cleanString(preg_replace(self::MATCH_PATTERN, self::REAPLCEMENT_PATTERN, $this->getName()), $keepMultipleUnderscores), '_');
    }
    /**
     * Returns the value with good type
     * @uses AbstractModel::getName()
     * @uses Utils::getValueWithinItsType()
     * @return mixed
     */
    public function getValue()
    {
        return Utils::getValueWithinItsType($this->getName());
    }
    /**
     * Gets the index attribute value
     * @return int
     */
    public function getIndex()
    {
        return $this->index;
    }
    /**
     * Sets the index attribute value<commit_msg>issue #54 - fix minor typo, use fluent methods calls<commit_after><?php

namespace WsdlToPhp\PackageGenerator\Model;

use WsdlToPhp\PackageGenerator\Generator\Generator;
use WsdlToPhp\PackageGenerator\Generator\Utils;

/**
 * Class StructValue stands for an enumeration value
 */
class StructValue extends AbstractModel
{
    /**
     * @var string
     */
    const MATCH_PATTERN = '/([[:upper:]]+[[:lower:]]*)|([[:lower:]]+)|(\d+)/';
    /**
     * @var string
     */
    const REPLACEMENT_PATTERN = '$1$2$3_';
    /**
     * Store the constants generated per structName
     * @var array
     */
    private static $uniqueConstants = array();
    /**
     * The index of the value in the enumeration struct
     * @var int
     */
    private $index = 0;
    /**
     * Main constructor
     * @see AbstractModel::__construct()
     * @uses AbstractModel::setOwner()
     * @uses StructValue::setIndex()
     * @param Generator $generator
     * @param string $name the original name
     * @param string $index the index of the value in the enumeration struct
     * @param Struct $struct defines the struct which owns this value
     */
    public function __construct(Generator $generator, $name, $index, Struct $struct)
    {
        parent::__construct($generator, $name);
        $this
            ->setIndex($index)
            ->setOwner($struct);
    }
    /**
     * Returns the name of the value as constant
     * @see AbstractModel::getCleanName()
     * @uses AbstractModel::getCleanName()
     * @uses AbstractModel::getName()
     * @uses AbstractModel::getOwner()
     * @uses StructValue::constantSuffix()
     * @uses StructValue::getIndex()
     * @uses StructValue::getOwner()
     * @uses Generator::getOptionGenericConstantsNames()
     * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores
     * @return string
     */
    public function getCleanName($keepMultipleUnderscores = false)
    {
        if ($this->getGenerator()->getOptionGenericConstantsNames()) {
            return 'ENUM_VALUE_' . $this->getIndex();
        } else {
            $nameWithSeparatedWords = $this->getNameWithSeparatedWords($keepMultipleUnderscores);
            $key = self::constantSuffix($this->getOwner()->getName(), $nameWithSeparatedWords, $this->getIndex());
            return 'VALUE_' . strtoupper($nameWithSeparatedWords . ($key ? '_' . $key : ''));
        }
    }
    /**
     * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores
     * @return string
     */
    public function getNameWithSeparatedWords($keepMultipleUnderscores = false)
    {
        return trim(self::cleanString(preg_replace(self::MATCH_PATTERN, self::REPLACEMENT_PATTERN, $this->getName()), $keepMultipleUnderscores), '_');
    }
    /**
     * Returns the value with good type
     * @uses AbstractModel::getName()
     * @uses Utils::getValueWithinItsType()
     * @return mixed
     */
    public function getValue()
    {
        return Utils::getValueWithinItsType($this->getName());
    }
    /**
     * Gets the index attribute value
     * @return int
     */
    public function getIndex()
    {
        return $this->index;
    }
    /**
     * Sets the index attribute value
{'fraction_non_alphanumeric': 0.12692307692307692, 'fraction_numerical': 0.0015384615384615385, 'mean_word_length': 2.9447815533980584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2979915', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1797, 'n_words': 446}