PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB` */ class ValidConstructorPass extends CodeCleanerPass { private $namespace; public function beforeTraverse(array $nodes) { $this->namespace = []; } /** * Validate that the constructor is not static and does not have a return type. * * @throws FatalErrorException the constructor function is static * @throws FatalErrorException the constructor function has a return type * * @param Node $node */ public function enterNode(Node $node) { if ($node instanceof Namespace_) { $this->namespace = isset($node->name) ? $node->name->parts : []; } elseif ($node instanceof Class_) { $constructor = null; foreach ($node->stmts as $stmt) { if ($stmt instanceof ClassMethod) { // If we find a new-style constructor, no need to look for the old-style if ('__construct' === \strtolower($stmt->name)) { $this->validateConstructor($stmt, $node); return; } // We found a possible old-style constructor (unless there is also a __construct method) if (empty($this->namespace) && \strtolower($node->name) === \strtolower($stmt->name)) { $constructor = $stmt; } } } if ($constructor) { $this->validateConstructor($constructor, $node); } } } /** * @throws FatalErrorException the constructor function is static * @throws FatalErrorException the constructor function has a return type * * @param Node $constructor * @param Node $classNode */ private function validateConstructor(Node $constructor, Node $classNode) { if ($constructor->isStatic()) { // For PHP Parser 4.x $className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name; $msg = \sprintf( 'Constructor %s::%s() cannot be static', \implode('\\', \array_merge($this->namespace, (array) $className)), $constructor->name ); throw new FatalErrorException($msg, 0, \E_ERROR, null, $classNode->getLine()); } if (\method_exists($constructor, 'getReturnType') && $constructor->getReturnType()) { // For PHP Parser 4.x $className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name; $msg = \sprintf( 'Constructor %s::%s() cannot declare a return type', \implode('\\', \array_merge($this->namespace, (array) $className)), $constructor->name ); throw new FatalErrorException($msg, 0, \E_ERROR, null, $classNode->getLine()); } } }