PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | deps/nette/utils/src/Utils/ObjectHelpers.php +19 -7 1.6.1 → 2.1 View file →
@@ -14,9 +14,12 @@
14 14 */
15 15 final class ObjectHelpers
16 16 {
17 17 use \Packetery\Nette\StaticClass;
18 - /** @throws MemberAccessException */
18 + /**
19 + * @return never
20 + * @throws MemberAccessException
21 + */
19 22 public static function strictGet(string $class, string $name) : void
20 23 {
21 24 $rc = new \ReflectionClass($class);
22 25 $hint = self::getSuggestion(\array_merge(\array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) {
@@ -23,9 +26,12 @@
23 26 return !$p->isStatic();
24 27 }), self::parseFullDoc($rc, '~^[ \\t*]*@property(?:-read)?[ \\t]+(?:\\S+[ \\t]+)??\\$(\\w+)~m')), $name);
25 28 throw new MemberAccessException("Cannot read an undeclared property {$class}::\${$name}" . ($hint ? ", did you mean \${$hint}?" : '.'));
26 29 }
27 - /** @throws MemberAccessException */
30 + /**
31 + * @return never
32 + * @throws MemberAccessException
33 + */
28 34 public static function strictSet(string $class, string $name) : void
29 35 {
30 36 $rc = new \ReflectionClass($class);
31 37 $hint = self::getSuggestion(\array_merge(\array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) {
@@ -32,9 +38,12 @@
32 38 return !$p->isStatic();
33 39 }), self::parseFullDoc($rc, '~^[ \\t*]*@property(?:-write)?[ \\t]+(?:\\S+[ \\t]+)??\\$(\\w+)~m')), $name);
34 40 throw new MemberAccessException("Cannot write to an undeclared property {$class}::\${$name}" . ($hint ? ", did you mean \${$hint}?" : '.'));
35 41 }
36 - /** @throws MemberAccessException */
42 + /**
43 + * @return never
44 + * @throws MemberAccessException
45 + */
37 46 public static function strictCall(string $class, string $method, array $additionalMethods = []) : void
38 47 {
39 48 $trace = \debug_backtrace(0, 3);
40 49 // suppose this method is called from __call()
@@ -48,13 +57,16 @@
48 57 $rm = new \ReflectionMethod($class, $method);
49 58 $visibility = $rm->isPrivate() ? 'private ' : ($rm->isProtected() ? 'protected ' : '');
50 59 throw new MemberAccessException("Call to {$visibility}method {$class}::{$method}() from " . ($context ? "scope {$context}." : 'global scope.'));
51 60 } else {
52 - $hint = self::getSuggestion(\array_merge(\get_class_methods($class), self::parseFullDoc(new \ReflectionClass($class), '~^[ \\t*]*@method[ \\t]+(?:\\S+[ \\t]+)??(\\w+)\\(~m'), $additionalMethods), $method);
61 + $hint = self::getSuggestion(\array_merge(\get_class_methods($class), self::parseFullDoc(new \ReflectionClass($class), '~^[ \\t*]*@method[ \\t]+(?:static[ \\t]+)?(?:\\S+[ \\t]+)??(\\w+)\\(~m'), $additionalMethods), $method);
53 62 throw new MemberAccessException("Call to undefined method {$class}::{$method}()" . ($hint ? ", did you mean {$hint}()?" : '.'));
54 63 }
55 64 }
56 - /** @throws MemberAccessException */
65 + /**
66 + * @return never
67 + * @throws MemberAccessException
68 + */
57 69 public static function strictStaticCall(string $class, string $method) : void
58 70 {
59 71 $trace = \debug_backtrace(0, 3);
60 72 // suppose this method is called from __callStatic()
@@ -87,9 +99,9 @@
87 99 if ($props !== null) {
88 100 return $props;
89 101 }
90 102 $rc = new \ReflectionClass($class);
91 - \preg_match_all('~^ [ \\t*]* @property(|-read|-write) [ \\t]+ [^\\s$]+ [ \\t]+ \\$ (\\w+) ()~mx', (string) $rc->getDocComment(), $matches, \PREG_SET_ORDER);
103 + \preg_match_all('~^ [ \\t*]* @property(|-read|-write|-deprecated) [ \\t]+ [^\\s$]+ [ \\t]+ \\$ (\\w+) ()~mx', (string) $rc->getDocComment(), $matches, \PREG_SET_ORDER);
92 104 $props = [];
93 105 foreach ($matches as [, $type, $name]) {
94 106 $uname = \ucfirst($name);
95 107 $write = $type !== '-read' && $rc->hasMethod($nm = 'set' . $uname) && ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
@@ -94,9 +106,9 @@
94 106 $uname = \ucfirst($name);
95 107 $write = $type !== '-read' && $rc->hasMethod($nm = 'set' . $uname) && ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
96 108 $read = $type !== '-write' && ($rc->hasMethod($nm = 'get' . $uname) || $rc->hasMethod($nm = 'is' . $uname)) && ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
97 109 if ($read || $write) {
98 - $props[$name] = $read << 0 | ($nm[0] === 'g') << 1 | $rm->returnsReference() << 2 | $write << 3;
110 + $props[$name] = $read << 0 | ($nm[0] === 'g') << 1 | $rm->returnsReference() << 2 | $write << 3 | ($type === '-deprecated') << 4;
99 111 }
100 112 }
101 113 foreach ($rc->getTraits() as $trait) {
102 114 $props += self::getMagicProperties($trait->name);