<commit_before><?php
namespace NBasnet\CodeWriter\Components;

use NBasnet\CodeWriter\FileWriter;
use NBasnet\CodeWriter\ISyntaxGrammar;

/**
 * Class VariableComponent
 * @package App\Services\File\Writer
 */
class VariableComponent extends BaseComponent
{
    /** @var  ISyntaxGrammar $grammar */
    protected $grammar;
    protected $variableName;
    protected $constant = FALSE;
    protected $static   = FALSE;
    protected $variableAccess;
    protected $value;

    /**
     * VariableComponent constructor.
     * @param string $variableName
     */
    protected function __construct($variableName)
    {
        $this->variableName = $variableName;
    }

    /**
     * @param string $variableName
     * @return static
     */
    public static function create($variableName)
    {
        return new static($variableName);
    }

    /**
     * @param ISyntaxGrammar $grammar
     * @return $this
     */
    public function setGrammar($grammar)
    {
        $this->grammar = $grammar;

        return $this;
    }

    /**
     * set constant to true
     * @return $this
     */
    public function makeConstant()
    {
        $this->constant = TRUE;

        return $this;
    }

    /**
     * sets static to true
     * @return $this
     */
    public function makeStatic()
    {
        $this->static = TRUE;

        return $this;
    }

    /**
     * @param mixed $value
     * @return $this
     */
    public function setValue($value)
    {
        $this->value = $value;

        return $this;
    }

    /**
     * Method to handle writing component
     * @return mixed
     */
    public function writeComponent()
    {
        return FileWriter::addLine(
            sprintf("{$this->generateVariableName()} = %s;", FileWriter::quoteValue($this->value)),
            $this->indent,
            $this->indent_space
        );
    }

    /**
     * @return string
     */
    public function generateVariableName()
    {
        $variable_name = "";
        if ($this->grammar->getProgram() === ISyntaxGrammar::PHP) {
            if (!empty($this->variableAccess)) $variable_name = $this->variableAccess;
            if ($this->static) $variable_name .= $this->grammar->getStatic();
            if ($this->constant) $variable_name .= " {$this->grammar->constant()} ";
            if (!$this->constant) $variable_name .= ' $';
            $variable_name .= "{$this->variableName}";
        }

        //handle other languages here

        return $variable_name;
    }
}<commit_msg>fixing how variable names are generated<commit_after><?php
namespace NBasnet\CodeWriter\Components;

use NBasnet\CodeWriter\FileWriter;
use NBasnet\CodeWriter\ISyntaxGrammar;

/**
 * Class VariableComponent
 * @package App\Services\File\Writer
 */
class VariableComponent extends BaseComponent
{
    /** @var  ISyntaxGrammar $grammar */
    protected $grammar;
    protected $variableName;
    protected $constant = FALSE;
    protected $static   = FALSE;
    protected $variableAccess;
    protected $value;

    /**
     * VariableComponent constructor.
     * @param string $variableName
     */
    protected function __construct($variableName)
    {
        $this->variableName = $variableName;
    }

    /**
     * @param string $variableName
     * @return static
     */
    public static function create($variableName)
    {
        return new static($variableName);
    }

    /**
     * @param ISyntaxGrammar $grammar
     * @return $this
     */
    public function setGrammar($grammar)
    {
        $this->grammar = $grammar;

        return $this;
    }

    /**
     * set constant to true
     * @return $this
     */
    public function makeConstant()
    {
        $this->constant = TRUE;

        return $this;
    }

    /**
     * sets static to true
     * @return $this
     */
    public function makeStatic()
    {
        $this->static = TRUE;

        return $this;
    }

    /**
     * @param mixed $value
     * @return $this
     */
    public function setValue($value)
    {
        $this->value = $value;

        return $this;
    }

    /**
     * Method to handle writing component
     * @return mixed
     */
    public function writeComponent()
    {
        return FileWriter::addLine(
            sprintf("{$this->generateVariableName()} = %s;", FileWriter::quoteValue($this->value)),
            $this->indent,
            $this->indent_space
        );
    }

    /**
     * @return string
     */
    public function generateVariableName()
    {
        $name_parts = [];
        if ($this->grammar->getProgram() === ISyntaxGrammar::PHP) {
            if (!empty($this->variableAccess)) $name_parts[] = $this->variableAccess;
            if ($this->static) $name_parts[] = $this->grammar->getStatic();
            if ($this->constant) $name_parts[] = $this->grammar->constant();
            $name_parts[] = ($this->constant) ? $this->variableName : '$' . $this->variableName;
        }

        //handle other languages here
        return implode(" ", $name_parts);
    }
}
{'fraction_non_alphanumeric': 0.132896305125149, 'fraction_numerical': 0.0, 'mean_word_length': 2.1176470588235294, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '6610585', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1430, 'n_words': 311}