<commit_before><?php

declare(strict_types=1);

namespace Spiechu\SymfonyCommonsBundle\Annotation\Controller;

use Doctrine\Common\Annotations\Reader;

trait ControllerAnnotationExtractorTrait
{
    abstract protected function getAnnotationReader(): Reader;

    protected function getClassAnnotationFromController(callable $controller = null, string $annotationClass): ?object
    {
        $objectToReflect = $this->getObjectToReflect($controller);

        if (is_object($objectToReflect)) {
            return $this->getAnnotationReader()->getClassAnnotation(
                new \ReflectionObject($objectToReflect),
                $annotationClass
            );
        }
    }

    protected function getMethodAnnotationFromController(callable $controller = null, string $annotationClass): ?object
    {
        if (is_array($controller)
            && isset($controller[1])
            && is_object($objectToReflect = $this->getObjectToReflect($controller))
        ) {
            return $this->getAnnotationReader()->getMethodAnnotation(
                new \ReflectionMethod($objectToReflect, $controller[1]),
                $annotationClass
            );
        }
    }

    protected function getObjectToReflect(callable $controller = null): ?object
    {
        if (is_object($controller)) {<commit_msg>remove return object typehint<commit_after><?php

declare(strict_types=1);

namespace Spiechu\SymfonyCommonsBundle\Annotation\Controller;

use Doctrine\Common\Annotations\Reader;

trait ControllerAnnotationExtractorTrait
{
    abstract protected function getAnnotationReader(): Reader;

    /**
     * @param callable|null $controller
     * @param string $annotationClass
     *
     * @return null|object
     */
    protected function getClassAnnotationFromController(callable $controller = null, string $annotationClass)
    {
        $objectToReflect = $this->getObjectToReflect($controller);

        if (is_object($objectToReflect)) {
            return $this->getAnnotationReader()->getClassAnnotation(
                new \ReflectionObject($objectToReflect),
                $annotationClass
            );
        }
    }

    /**
     * @param callable|null $controller
     * @param string $annotationClass
     *
     * @return object|null
     */
    protected function getMethodAnnotationFromController(callable $controller = null, string $annotationClass)
    {
        if (is_array($controller)
            && isset($controller[1])
            && is_object($objectToReflect = $this->getObjectToReflect($controller))
        ) {
            return $this->getAnnotationReader()->getMethodAnnotation(
                new \ReflectionMethod($objectToReflect, $controller[1]),
                $annotationClass
            );
        }
    }

    /**
     * @param callable|null $controller
     *
     * @return object|null
     */
    protected function getObjectToReflect(callable $controller = null)
    {
        if (is_object($controller)) {
{'fraction_non_alphanumeric': 0.10238335011748909, 'fraction_numerical': 0.002014098690835851, 'mean_word_length': 2.81562099871959, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '5325030', 'n_tokens_mistral': 765, 'n_tokens_neox': 750, 'n_words': 135}