Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RequestAwareBlockMethod.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
11 use PHPMD\AbstractNode;
12 use PHPMD\AbstractRule;
13 use PHPMD\Node\ClassNode;
14 use PHPMD\Node\MethodNode;
15 use PDepend\Source\AST\ASTMethod;
16 use PHPMD\Rule\MethodAware;
17 
21 class RequestAwareBlockMethod extends AbstractRule implements MethodAware
22 {
28  public function apply(AbstractNode $method)
29  {
30  $definedIn = $method->getParentType();
31  try {
32  $isBlock = ($definedIn instanceof ClassNode)
33  && is_subclass_of(
34  $definedIn->getFullQualifiedName(),
35  \Magento\Framework\View\Element\AbstractBlock::class
36  );
37  } catch (\Throwable $exception) {
38  //Failed to load classes.
39  return;
40  }
41 
42  if ($isBlock) {
43  $nodes = $method->findChildrenOfType('PropertyPostfix') + $method->findChildrenOfType('MethodPostfix');
44  foreach ($nodes as $node) {
45  $name = mb_strtolower($node->getFirstChildOfType('Identifier')->getImage());
46  if ($name === '_request' || $name === 'getrequest') {
47  $this->addViolation($method, [$method->getFullQualifiedName()]);
48  break;
49  }
50  }
51  }
52  }
53 }
is_subclass_of($obj, $className)
$method
Definition: info.phtml:13
if(!isset($_GET['name'])) $name
Definition: log.php:14