<commit_before><?php

namespace Triun\ModelBase\Modifiers;

use ReflectionClass;
use Illuminate\Database\Query\Builder;
use Triun\ModelBase\Lib\ModifierBase;
use Triun\ModelBase\Definitions\Skeleton;
use Triun\ModelBase\Definitions\PhpDocTag;

class PhpDocModifier extends ModifierBase
{
    /**
     * Apply the modifications of the class.
     *
     * @param \Triun\ModelBase\Definitions\Skeleton
     */
    public function apply(Skeleton $skeleton)
    {
        foreach ($this->table()->getColumns() as $column) {
            $skeleton->addPhpDocTag(new PhpDocTag(
                '$'.$column->snakeName,
                'property',
                $column->phpDocType,
                str_pad($column->dbType, 11).' '.$column->getComment()
            ));

            // Avoid existent methods as whereDate or WhereColumn
            $method = "where{$column->studName}";
            if (!$skeleton->hasMethod($method) && !$this->hasMethod($method, Builder::class)) {
                $skeleton->addPhpDocTag(new PhpDocTag(
                    "{$method}(\$value)",
                    'method',
                    'static \\Illuminate\\Database\\Query\\Builder|\DummyNamespace\DummyClass',
                    $column->getComment()
                ));
            }
        }
    }

    public function hasMethod($method, $className)
    {
        $reflectionClass = new ReflectionClass($className);

        return $reflectionClass->hasMethod($method);
    }
}<commit_msg>PhpDocModifier refactoring<commit_after><?php

namespace Triun\ModelBase\Modifiers;

use ReflectionClass;
use Illuminate\Database\Query\Builder;
use Triun\ModelBase\Lib\ModifierBase;
use Triun\ModelBase\Definitions\Skeleton;
use Triun\ModelBase\Definitions\PhpDocTag;

/**
 * Class PhpDocModifier
 * @package Triun\ModelBase\Modifiers
 */
class PhpDocModifier extends ModifierBase
{
    /**
     * Apply the modifications of the class.
     *
     * @param \Triun\ModelBase\Definitions\Skeleton
     */
    public function apply(Skeleton $skeleton)
    {
        $BuilderReflectionClass = new ReflectionClass(Builder::class);

        foreach ($this->table()->getColumns() as $column) {
            $skeleton->addPhpDocTag(new PhpDocTag(
                '$'.$column->snakeName,
                'property',
                $column->phpDocType,
                str_pad($column->dbType, 11).' '.$column->getComment()
            ));

            // Avoid existent methods as whereDate or WhereColumn
            $method = "where{$column->studName}";
            if ($skeleton->hasMethod($method) || $BuilderReflectionClass->hasMethod($method)) {
                continue;
            }

            $skeleton->addPhpDocTag(new PhpDocTag(
                "{$method}(\$value)",
                'method',
                'static \\Illuminate\\Database\\Query\\Builder|\DummyNamespace\DummyClass',
                $column->getComment()
            ));
        }
    }
}
{'fraction_non_alphanumeric': 0.12873641304347827, 'fraction_numerical': 0.001358695652173913, 'mean_word_length': 2.1734913793103448, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '3082027', 'n_tokens_mistral': 838, 'n_tokens_neox': 817, 'n_words': 139}