<commit_before><?php

/**
 * This file is part of the Cubiche package.
 *
 * Copyright (c) Cubiche
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Cubiche\Core\Validator\Mapping\Driver;

use Cubiche\Core\Validator\Assert;
use Cubiche\Core\Validator\Mapping\ClassMetadata;
use Cubiche\Core\Validator\Mapping\Exception\MappingException;
use Metadata\Driver\DriverInterface;

/**
 * StaticDriver class.
 *
 * @author <NAME> <<EMAIL>>
 */
class StaticDriver implements DriverInterface
{
    /**
     * The name of the method to call.
     *
     * @var string
     */
    protected $methodName;

    /**
     * @var string
     */
    protected $defaultGroup;

    /**
     * StaticDriver constructor.
     *
     * @param string $methodName
     * @param string $defaultGroup
     */
    public function __construct($methodName = 'loadValidatorMetadata', $defaultGroup = Assert::DEFAULT_GROUP)
    {
        $this->methodName = $methodName;
        $this->defaultGroup = $defaultGroup;
    }

    /**
     * {@inheritdoc}
     */
    public function loadMetadataForClass(\ReflectionClass $reflClass)
    {
        if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
            $reflMethod = $reflClass->getMethod($this->methodName);

            if ($reflMethod->isAbstract()) {
                throw MappingException::withMessage(
                    'The class %s should not be and abstract class',
                    $reflClass->name,
                    $this->methodName
                );
            }

            if (!$reflMethod->isStatic()) {
                throw MappingException::withMessage(
                    'The method %s::%s should be static',
                    $reflClass->name,
                    $this->methodName
                );
            }

            if ($reflMethod->getDeclaringClass()->name != $reflClass->name) {
                throw MappingException::withMessage(
                    'The method %s should be declared in %s class',
                    $this->methodName,
                    $reflClass->name
                );
            }

            $metadata = new ClassMetadata($reflClass->getName());
            $metadata->defaultGroup = $this->defaultGroup;

            $reflMethod->invoke(null, $metadata);

            return $metadata;
        }
    }
}
<commit_msg>allowing static validator method inheritance<commit_after><?php

/**
 * This file is part of the Cubiche package.
 *
 * Copyright (c) Cubiche
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Cubiche\Core\Validator\Mapping\Driver;

use Cubiche\Core\Validator\Assert;
use Cubiche\Core\Validator\Mapping\ClassMetadata;
use Cubiche\Core\Validator\Mapping\Exception\MappingException;
use Metadata\Driver\DriverInterface;

/**
 * StaticDriver class.
 *
 * @author <NAME> <<EMAIL>>
 */
class StaticDriver implements DriverInterface
{
    /**
     * The name of the method to call.
     *
     * @var string
     */
    protected $methodName;

    /**
     * @var string
     */
    protected $defaultGroup;

    /**
     * StaticDriver constructor.
     *
     * @param string $methodName
     * @param string $defaultGroup
     */
    public function __construct($methodName = 'loadValidatorMetadata', $defaultGroup = Assert::DEFAULT_GROUP)
    {
        $this->methodName = $methodName;
        $this->defaultGroup = $defaultGroup;
    }

    /**
     * {@inheritdoc}
     */
    public function loadMetadataForClass(\ReflectionClass $reflClass)
    {
        if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
            $reflMethod = $reflClass->getMethod($this->methodName);

            if ($reflMethod->isAbstract()) {
                throw MappingException::withMessage(
                    'The class %s should not be and abstract class',
                    $reflClass->name,
                    $this->methodName
                );
            }

            if (!$reflMethod->isStatic()) {
                throw MappingException::withMessage(
                    'The method %s::%s should be static',
                    $reflClass->name,
                    $this->methodName
                );
            }

            $metadata = new ClassMetadata($reflClass->getName());
            $metadata->defaultGroup = $this->defaultGroup;

            $reflMethod->invoke(null, $metadata);

            return $metadata;
        }
    }
}

{'fraction_non_alphanumeric': 0.11569350987627523, 'fraction_numerical': 0.0, 'mean_word_length': 2.0039113428943938, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 48, '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': '5009636', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1191, 'n_words': 278}