comparison vendor/psy/psysh/src/CodeCleaner/ValidConstructorPass.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 5fb285c0d0e3
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
55 } elseif ($node instanceof Class_) { 55 } elseif ($node instanceof Class_) {
56 $constructor = null; 56 $constructor = null;
57 foreach ($node->stmts as $stmt) { 57 foreach ($node->stmts as $stmt) {
58 if ($stmt instanceof ClassMethod) { 58 if ($stmt instanceof ClassMethod) {
59 // If we find a new-style constructor, no need to look for the old-style 59 // If we find a new-style constructor, no need to look for the old-style
60 if ('__construct' === strtolower($stmt->name)) { 60 if ('__construct' === \strtolower($stmt->name)) {
61 $this->validateConstructor($stmt, $node); 61 $this->validateConstructor($stmt, $node);
62 62
63 return; 63 return;
64 } 64 }
65 65
66 // We found a possible old-style constructor (unless there is also a __construct method) 66 // We found a possible old-style constructor (unless there is also a __construct method)
67 if (empty($this->namespace) && strtolower($node->name) === strtolower($stmt->name)) { 67 if (empty($this->namespace) && \strtolower($node->name) === \strtolower($stmt->name)) {
68 $constructor = $stmt; 68 $constructor = $stmt;
69 } 69 }
70 } 70 }
71 } 71 }
72 72
87 { 87 {
88 if ($constructor->isStatic()) { 88 if ($constructor->isStatic()) {
89 // For PHP Parser 4.x 89 // For PHP Parser 4.x
90 $className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name; 90 $className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name;
91 91
92 $msg = sprintf( 92 $msg = \sprintf(
93 'Constructor %s::%s() cannot be static', 93 'Constructor %s::%s() cannot be static',
94 implode('\\', array_merge($this->namespace, (array) $className)), 94 \implode('\\', \array_merge($this->namespace, (array) $className)),
95 $constructor->name 95 $constructor->name
96 ); 96 );
97 throw new FatalErrorException($msg, 0, E_ERROR, null, $classNode->getLine()); 97 throw new FatalErrorException($msg, 0, E_ERROR, null, $classNode->getLine());
98 } 98 }
99 99
100 if (method_exists($constructor, 'getReturnType') && $constructor->getReturnType()) { 100 if (\method_exists($constructor, 'getReturnType') && $constructor->getReturnType()) {
101 // For PHP Parser 4.x 101 // For PHP Parser 4.x
102 $className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name; 102 $className = $classNode->name instanceof Identifier ? $classNode->name->toString() : $classNode->name;
103 103
104 $msg = sprintf( 104 $msg = \sprintf(
105 'Constructor %s::%s() cannot declare a return type', 105 'Constructor %s::%s() cannot declare a return type',
106 implode('\\', array_merge($this->namespace, (array) $className)), 106 \implode('\\', \array_merge($this->namespace, (array) $className)),
107 $constructor->name 107 $constructor->name
108 ); 108 );
109 throw new FatalErrorException($msg, 0, E_ERROR, null, $classNode->getLine()); 109 throw new FatalErrorException($msg, 0, E_ERROR, null, $classNode->getLine());
110 } 110 }
111 } 111 }