hasPackageAnnotation example


    public function processNode(Node $node, Scope $scope): array
    {
        if ($this->isTestClass($node)) {
            return [];
        }

        $area = $this->getProductArea($node);

        if ($this->hasPackageAnnotation($node)) {
            return [];
        }

        return [sprintf('This class is missing the "#[Package(...)]" attribute (recommendation: %s)', $area ?? 'unknown')];
    }

    private function getProductArea(InClassNode $node): ?string
    {
        $namespace = $node->getClassReflection()->getName();

        foreach (self::PRODUCT_AREA_MAPPING as $area => $regexes) {
            
if ($this->isTestClass($node)) {
            return null;
        }

        $area = $this->getArea($node);

        if ($area === null) {
            return null;
        }

        if ($this->hasPackageAnnotation($node)) {
            return null;
        }

        $node->attrGroups[] = $this->phpAttributeGroupFactory->createFromClassWithItems(Package::class[$area]);

        return $node;
    }

    public function getRuleDefinition(): RuleDefinition
    {
        return new RuleDefinition(
            
Home | Imprint | This part of the site doesn't use cookies.