Guest User

Untitled

a guest
Jul 20th, 2021
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @implements Rule<ClassPropertiesNode>
  5.  */
  6. class ClassPropertiesNullabilityRule implements Rule
  7. {
  8.  
  9.     private Standard $printer;
  10.  
  11.     public function __construct(\PhpParser\PrettyPrinter\Standard $printer)
  12.     {
  13.         $this->printer = $printer;
  14.     }
  15.  
  16.     public function getNodeType(): string
  17.     {
  18.         return ClassPropertiesNode::class;
  19.     }
  20.  
  21.     /**
  22.      * @param ClassPropertiesNode $node
  23.      * @return RuleError[]
  24.      */
  25.     public function processNode(Node $node, Scope $scope): array
  26.     {
  27.         foreach ($node->getPropertyUsages() as $propertyUsage) {
  28.             if (!$propertyUsage instanceof PropertyWrite) {
  29.                 continue;
  30.             }
  31.  
  32.             $parentNode = $propertyUsage->getFetch()->getAttribute('parent');
  33.             echo $this->printer->prettyPrint([$parentNode]);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment