getDocComment example

if (!array_is_list($arguments)) {
            $arguments = array_combine(array_map(fn ($k) => preg_replace('/^.*\\$/', '', $k)array_keys($arguments))$arguments);
        }

        if (null !== $factory) {
            $service = $factory(...$arguments);

            if (!$definition->isDeprecated() && \is_array($factory) && \is_string($factory[0])) {
                $r = new \ReflectionClass($factory[0]);

                if (0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
                    trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" factory class. It should either be deprecated or its factory upgraded.', $id$r->name);
                }
            }
        } else {
            $r = new \ReflectionClass($class);

            if (\is_object($tryProxy)) {
                if ($r->getConstructor()) {
                    $tryProxy->__construct(...$arguments);
                }

                
/** * @return array<string, class-string<SymfonyBaseEvent>> */
    private function getEventClasses(): array
    {
        $reflectionClass = $this->getReflectionClass();
        $docParser = $this->getDocParser();

        $eventClasses = [];
        foreach ($reflectionClass->getReflectionConstants() as $constant) {
            $docComment = $constant->getDocComment();
            if (!\is_string($docComment)) {
                continue;
            }

            foreach ($docParser->parse($docComment) as $annotation) {
                if ($annotation instanceof Event) {
                    $deprecationVersion = $annotation->getDeprecationVersion();

                    if ($deprecationVersion && Feature::isActive($deprecationVersion)) {
                        continue;
                    }

                    

    public function addNamespace($namespace)
    {
        $this->parser->addNamespace($namespace);
    }

    /** * {@inheritDoc} */
    public function getClassAnnotations(ReflectionClass $class)
    {
        return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
    }

    /** * {@inheritDoc} */
    public function getMethodAnnotations(ReflectionMethod $method)
    {
        return $this->parser->parse(
            $method->getDocComment(),
            'method ' . $method->getDeclaringClass()->name . '::' . $method->getName() . '()'
        );
    }
return ClassMethod::class;
    }

    /** * @param Node\Stmt\ClassMethod $node * * @return string[] */
    public function processNode(Node $node, Scope $scope): array
    {
        // Check if the method has a dataProvider annotation         $docComment = $node->getDocComment();
        if ($docComment === null) {
            return [];
        }

        $dataProviderPattern = '/@dataProvider\s+([^\s]+)/';
        if (!preg_match($dataProviderPattern$docComment->getText()$matches)) {
            return [];
        }

        // Get the dataProvider method name         $dataProviderName = $matches[1];

        
if (!array_is_list($arguments)) {
            $arguments = array_combine(array_map(fn ($k) => preg_replace('/^.*\\$/', '', $k)array_keys($arguments))$arguments);
        }

        if (null !== $factory) {
            $service = $factory(...$arguments);

            if (!$definition->isDeprecated() && \is_array($factory) && \is_string($factory[0])) {
                $r = new \ReflectionClass($factory[0]);

                if (0 < strpos($r->getDocComment(), "\n * @deprecated ")) {
                    trigger_deprecation('', '', 'The "%s" service relies on the deprecated "%s" factory class. It should either be deprecated or its factory upgraded.', $id$r->name);
                }
            }
        } else {
            $r = new \ReflectionClass($class);

            if (\is_object($tryProxy)) {
                if ($r->getConstructor()) {
                    $tryProxy->__construct(...$arguments);
                }

                
    public function getName()
    {
        return $this->staticReflectionParser->getClassName();
    }

    /** * {@inheritDoc} */
    #[\ReturnTypeWillChange]     public function getDocComment()
    {
        return $this->staticReflectionParser->getDocComment();
    }

    /** * {@inheritDoc} */
    #[\ReturnTypeWillChange]     public function getNamespaceName()
    {
        return $this->staticReflectionParser->getNamespaceName();
    }

    
// Prevent expensive class loader lookups for each reflected test class by     // registering the complete classmap of test classes to the class loader.     // This also ensures that test classes are loaded from the discovered     // pathnames; a namespace/classname mismatch will throw an exception.     $this->classLoader->addClassMap($classmap);

    foreach ($classmap as $classname => $pathname) {
      $finder = MockFileFinder::create($pathname);
      $parser = new StaticReflectionParser($classname$finder, TRUE);
      try {
        $info = static::getTestInfo($classname$parser->getDocComment());
      }
      catch (MissingGroupException $e) {
        // If the class name ends in Test and is not a migrate table dump.         if (preg_match('/Test$/', $classname) && !str_contains($classname, 'migrate_drupal\Tests\Table')) {
          throw $e;
        }
        // If the class is @group annotation just skip it. Most likely it is an         // abstract class, trait or test fixture.         continue;
      }
      foreach ($info['groups'] as $group) {
        

    public function addNamespace($namespace)
    {
        $this->parser->addNamespace($namespace);
    }

    /** * {@inheritDoc} */
    public function getClassAnnotations(\ReflectionClass $class)
    {
        return $this->parser->parse($class->getDocComment(), 'class '.$class->getName());
    }

    /** * {@inheritDoc} */
    public function getMethodAnnotations(\ReflectionMethod $method)
    {
        return $this->parser->parse($method->getDocComment(), 'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()');
    }

    /** * {@inheritDoc} */
if (!$reflectionClass = $this->container->getReflectionClass($value->getClass(), false)) {
            return $value;
        }

        $properties = $value->getProperties();
        foreach ($reflectionClass->getProperties() as $reflectionProperty) {
            if (!($type = $reflectionProperty->getType()) instanceof \ReflectionNamedType) {
                continue;
            }
            $doc = false;
            if (!$reflectionProperty->getAttributes(Required::class)
                && ((false === $doc = $reflectionProperty->getDocComment()) || false === stripos($doc, '@required') || !preg_match('#(?:^/\*\*|\n\s*+\*)\s*+@required(?:\s|\*/$)#i', $doc))
            ) {
                continue;
            }
            if ($doc) {
                trigger_deprecation('symfony/dependency-injection', '6.3', 'Using the "@required" annotation on property "%s::$%s" is deprecated, use the "Symfony\Contracts\Service\Attribute\Required" attribute instead.', $reflectionProperty->class, $reflectionProperty->name);
            }
            if (\array_key_exists($name = $reflectionProperty->getName()$properties)) {
                continue;
            }

            $type = $type->getName();
            
->exclude('*/Test/*', '*/vendor/*', '*/DevOps/StaticAnalyze*')
            ->findClassNames();

        foreach ($shopwareClasses as $class) {
            if (!class_exists($class)) {
                // skip not autoloadable test classes                 continue;
            }

            $reflection = new \ReflectionClass($class);

            if (!$reflection->getDocComment()) {
                continue;
            }

            $doc = $this->docFactory->create($reflection);

            if (!$doc->hasTag('script-service')) {
                continue;
            }

            $scriptServices[] = $class;
        }

        
$returnType[$i] = null !== $format ? sprintf($format$alias) : $alias;
        }

        if ('docblock' === $this->patchTypes['force'] || ('object' === $normalizedType && '7.1' === $this->patchTypes['php'])) {
            $returnType = implode($glue$returnType).($nullable ? '|null' : '');

            if (str_contains($code[$startLine], '#[')) {
                --$startLine;
            }

            if ($method->getDocComment()) {
                $code[$startLine] = " * @return $returnType\n".$code[$startLine];
            } else {
                $code[$startLine] .= <<<EOTXT /** * @return $returnType */ EOTXT;
            }

            $fileOffset += substr_count($code[$startLine], "\n") - 1;
        }
self::$metadataParser->setIgnoreNotImportedAnnotations(true);
            self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames);
            self::$metadataParser->setImports(array(
                'enum'          => 'Doctrine\Common\Annotations\Annotation\Enum',
                'target'        => 'Doctrine\Common\Annotations\Annotation\Target',
                'attribute'     => 'Doctrine\Common\Annotations\Annotation\Attribute',
                'attributes'    => 'Doctrine\Common\Annotations\Annotation\Attributes'
            ));
        }

        $class      = new \ReflectionClass($name);
        $docComment = $class->getDocComment();

        // Sets default values for annotation metadata         $metadata = array(
            'default_property' => null,
            'has_constructor'  => (null !== $constructor = $class->getConstructor()) && $constructor->getNumberOfParameters() > 0,
            'properties'       => array(),
            'property_types'   => array(),
            'attribute_types'  => array(),
            'targets_literal'  => null,
            'targets'          => Target::TARGET_ALL,
            'is_annotation'    => str_contains($docComment, '@Annotation'),
        );
$optionsMapping[] = $key.'='.$value;
        }

        return ' (when '.implode(', ', $optionsMapping).')';
    }

    private static function getClassDescription(string $class): string
    {
        try {
            $r = new \ReflectionClass($class);

            if ($docComment = $r->getDocComment()) {
                $docComment = preg_split('#\n\s*\*\s*[\n@]#', substr($docComment, 3, -2), 2)[0];

                return trim(preg_replace('#\s*\n\s*\*\s*#', ' ', $docComment));
            }
        } catch (\ReflectionException) {
        }

        return '';
    }

    public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
    {
public function testAnnotationTarget()
    {

        $parser = new DocParser;
        $parser->setImports(array(
            '__NAMESPACE__' => 'Drupal\Tests\Component\Annotation\Doctrine\Fixtures',
        ));
        $class  = new \ReflectionClass('Drupal\Tests\Component\Annotation\Doctrine\Fixtures\ClassWithValidAnnotationTarget');


        $context    = 'class ' . $class->getName();
        $docComment = $class->getDocComment();

        $parser->setTarget(Target::TARGET_CLASS);
        $this->assertNotNull($parser->parse($docComment,$context));


        $property   = $class->getProperty('foo');
        $docComment = $property->getDocComment();
        $context    = 'property ' . $class->getName() . "::\$" . $property->getName();

        $parser->setTarget(Target::TARGET_PROPERTY);
        $this->assertNotNull($parser->parse($docComment,$context));



        


    private function snakeCaseToCamelCase(string $input): string
    {
        return str_replace('_', '', ucwords($input, '_'));
    }

    private function isExperimental(EntityDefinition $definition): bool
    {
        $reflection = new \ReflectionClass($definition);

        return str_contains($reflection->getDocComment() ?: '', '@' . self::EXPERIMENTAL_ANNOTATION_NAME);
    }
}
Home | Imprint | This part of the site doesn't use cookies.