@@ -26,121 +26,121 @@ |
||
26 | 26 | */ |
27 | 27 | class Doubler |
28 | 28 | { |
29 | - private $mirror; |
|
30 | - private $creator; |
|
31 | - private $namer; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var ClassPatchInterface[] |
|
35 | - */ |
|
36 | - private $patches = array(); |
|
37 | - |
|
38 | - /** |
|
39 | - * @var \Doctrine\Instantiator\Instantiator |
|
40 | - */ |
|
41 | - private $instantiator; |
|
42 | - |
|
43 | - /** |
|
44 | - * Initializes doubler. |
|
45 | - * |
|
46 | - * @param ClassMirror $mirror |
|
47 | - * @param ClassCreator $creator |
|
48 | - * @param NameGenerator $namer |
|
49 | - */ |
|
50 | - public function __construct(ClassMirror $mirror = null, ClassCreator $creator = null, |
|
51 | - NameGenerator $namer = null) |
|
52 | - { |
|
53 | - $this->mirror = $mirror ?: new ClassMirror; |
|
54 | - $this->creator = $creator ?: new ClassCreator; |
|
55 | - $this->namer = $namer ?: new NameGenerator; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Returns list of registered class patches. |
|
60 | - * |
|
61 | - * @return ClassPatchInterface[] |
|
62 | - */ |
|
63 | - public function getClassPatches() |
|
64 | - { |
|
65 | - return $this->patches; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Registers new class patch. |
|
70 | - * |
|
71 | - * @param ClassPatchInterface $patch |
|
72 | - */ |
|
73 | - public function registerClassPatch(ClassPatchInterface $patch) |
|
74 | - { |
|
75 | - $this->patches[] = $patch; |
|
76 | - |
|
77 | - @usort($this->patches, function (ClassPatchInterface $patch1, ClassPatchInterface $patch2) { |
|
78 | - return $patch2->getPriority() - $patch1->getPriority(); |
|
79 | - }); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Creates double from specific class or/and list of interfaces. |
|
84 | - * |
|
85 | - * @param ReflectionClass $class |
|
86 | - * @param ReflectionClass[] $interfaces Array of ReflectionClass instances |
|
87 | - * @param array $args Constructor arguments |
|
88 | - * |
|
89 | - * @return DoubleInterface |
|
90 | - * |
|
91 | - * @throws \Prophecy\Exception\InvalidArgumentException |
|
92 | - */ |
|
93 | - public function double(ReflectionClass $class = null, array $interfaces, array $args = null) |
|
94 | - { |
|
95 | - foreach ($interfaces as $interface) { |
|
96 | - if (!$interface instanceof ReflectionClass) { |
|
97 | - throw new InvalidArgumentException(sprintf( |
|
98 | - "[ReflectionClass \$interface1 [, ReflectionClass \$interface2]] array expected as\n". |
|
99 | - "a second argument to `Doubler::double(...)`, but got %s.", |
|
100 | - is_object($interface) ? get_class($interface).' class' : gettype($interface) |
|
101 | - )); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - $classname = $this->createDoubleClass($class, $interfaces); |
|
106 | - $reflection = new ReflectionClass($classname); |
|
107 | - |
|
108 | - if (null !== $args) { |
|
109 | - return $reflection->newInstanceArgs($args); |
|
110 | - } |
|
111 | - if ((null === $constructor = $reflection->getConstructor()) |
|
112 | - || ($constructor->isPublic() && !$constructor->isFinal())) { |
|
113 | - return $reflection->newInstance(); |
|
114 | - } |
|
115 | - |
|
116 | - if (!$this->instantiator) { |
|
117 | - $this->instantiator = new Instantiator(); |
|
118 | - } |
|
119 | - |
|
120 | - return $this->instantiator->instantiate($classname); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Creates double class and returns its FQN. |
|
125 | - * |
|
126 | - * @param ReflectionClass $class |
|
127 | - * @param ReflectionClass[] $interfaces |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - protected function createDoubleClass(ReflectionClass $class = null, array $interfaces) |
|
132 | - { |
|
133 | - $name = $this->namer->name($class, $interfaces); |
|
134 | - $node = $this->mirror->reflect($class, $interfaces); |
|
135 | - |
|
136 | - foreach ($this->patches as $patch) { |
|
137 | - if ($patch->supports($node)) { |
|
138 | - $patch->apply($node); |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - $this->creator->create($name, $node); |
|
143 | - |
|
144 | - return $name; |
|
145 | - } |
|
29 | + private $mirror; |
|
30 | + private $creator; |
|
31 | + private $namer; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var ClassPatchInterface[] |
|
35 | + */ |
|
36 | + private $patches = array(); |
|
37 | + |
|
38 | + /** |
|
39 | + * @var \Doctrine\Instantiator\Instantiator |
|
40 | + */ |
|
41 | + private $instantiator; |
|
42 | + |
|
43 | + /** |
|
44 | + * Initializes doubler. |
|
45 | + * |
|
46 | + * @param ClassMirror $mirror |
|
47 | + * @param ClassCreator $creator |
|
48 | + * @param NameGenerator $namer |
|
49 | + */ |
|
50 | + public function __construct(ClassMirror $mirror = null, ClassCreator $creator = null, |
|
51 | + NameGenerator $namer = null) |
|
52 | + { |
|
53 | + $this->mirror = $mirror ?: new ClassMirror; |
|
54 | + $this->creator = $creator ?: new ClassCreator; |
|
55 | + $this->namer = $namer ?: new NameGenerator; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Returns list of registered class patches. |
|
60 | + * |
|
61 | + * @return ClassPatchInterface[] |
|
62 | + */ |
|
63 | + public function getClassPatches() |
|
64 | + { |
|
65 | + return $this->patches; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Registers new class patch. |
|
70 | + * |
|
71 | + * @param ClassPatchInterface $patch |
|
72 | + */ |
|
73 | + public function registerClassPatch(ClassPatchInterface $patch) |
|
74 | + { |
|
75 | + $this->patches[] = $patch; |
|
76 | + |
|
77 | + @usort($this->patches, function (ClassPatchInterface $patch1, ClassPatchInterface $patch2) { |
|
78 | + return $patch2->getPriority() - $patch1->getPriority(); |
|
79 | + }); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Creates double from specific class or/and list of interfaces. |
|
84 | + * |
|
85 | + * @param ReflectionClass $class |
|
86 | + * @param ReflectionClass[] $interfaces Array of ReflectionClass instances |
|
87 | + * @param array $args Constructor arguments |
|
88 | + * |
|
89 | + * @return DoubleInterface |
|
90 | + * |
|
91 | + * @throws \Prophecy\Exception\InvalidArgumentException |
|
92 | + */ |
|
93 | + public function double(ReflectionClass $class = null, array $interfaces, array $args = null) |
|
94 | + { |
|
95 | + foreach ($interfaces as $interface) { |
|
96 | + if (!$interface instanceof ReflectionClass) { |
|
97 | + throw new InvalidArgumentException(sprintf( |
|
98 | + "[ReflectionClass \$interface1 [, ReflectionClass \$interface2]] array expected as\n". |
|
99 | + "a second argument to `Doubler::double(...)`, but got %s.", |
|
100 | + is_object($interface) ? get_class($interface).' class' : gettype($interface) |
|
101 | + )); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + $classname = $this->createDoubleClass($class, $interfaces); |
|
106 | + $reflection = new ReflectionClass($classname); |
|
107 | + |
|
108 | + if (null !== $args) { |
|
109 | + return $reflection->newInstanceArgs($args); |
|
110 | + } |
|
111 | + if ((null === $constructor = $reflection->getConstructor()) |
|
112 | + || ($constructor->isPublic() && !$constructor->isFinal())) { |
|
113 | + return $reflection->newInstance(); |
|
114 | + } |
|
115 | + |
|
116 | + if (!$this->instantiator) { |
|
117 | + $this->instantiator = new Instantiator(); |
|
118 | + } |
|
119 | + |
|
120 | + return $this->instantiator->instantiate($classname); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Creates double class and returns its FQN. |
|
125 | + * |
|
126 | + * @param ReflectionClass $class |
|
127 | + * @param ReflectionClass[] $interfaces |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + protected function createDoubleClass(ReflectionClass $class = null, array $interfaces) |
|
132 | + { |
|
133 | + $name = $this->namer->name($class, $interfaces); |
|
134 | + $node = $this->mirror->reflect($class, $interfaces); |
|
135 | + |
|
136 | + foreach ($this->patches as $patch) { |
|
137 | + if ($patch->supports($node)) { |
|
138 | + $patch->apply($node); |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + $this->creator->create($name, $node); |
|
143 | + |
|
144 | + return $name; |
|
145 | + } |
|
146 | 146 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | public function __construct(ClassMirror $mirror = null, ClassCreator $creator = null, |
51 | 51 | NameGenerator $namer = null) |
52 | 52 | { |
53 | - $this->mirror = $mirror ?: new ClassMirror; |
|
53 | + $this->mirror = $mirror ?: new ClassMirror; |
|
54 | 54 | $this->creator = $creator ?: new ClassCreator; |
55 | - $this->namer = $namer ?: new NameGenerator; |
|
55 | + $this->namer = $namer ?: new NameGenerator; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | { |
75 | 75 | $this->patches[] = $patch; |
76 | 76 | |
77 | - @usort($this->patches, function (ClassPatchInterface $patch1, ClassPatchInterface $patch2) { |
|
77 | + @usort($this->patches, function(ClassPatchInterface $patch1, ClassPatchInterface $patch2) { |
|
78 | 78 | return $patch2->getPriority() - $patch1->getPriority(); |
79 | 79 | }); |
80 | 80 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | public function double(ReflectionClass $class = null, array $interfaces, array $args = null) |
94 | 94 | { |
95 | 95 | foreach ($interfaces as $interface) { |
96 | - if (!$interface instanceof ReflectionClass) { |
|
96 | + if ( ! $interface instanceof ReflectionClass) { |
|
97 | 97 | throw new InvalidArgumentException(sprintf( |
98 | 98 | "[ReflectionClass \$interface1 [, ReflectionClass \$interface2]] array expected as\n". |
99 | 99 | "a second argument to `Doubler::double(...)`, but got %s.", |
@@ -109,11 +109,11 @@ discard block |
||
109 | 109 | return $reflection->newInstanceArgs($args); |
110 | 110 | } |
111 | 111 | if ((null === $constructor = $reflection->getConstructor()) |
112 | - || ($constructor->isPublic() && !$constructor->isFinal())) { |
|
112 | + || ($constructor->isPublic() && ! $constructor->isFinal())) { |
|
113 | 113 | return $reflection->newInstance(); |
114 | 114 | } |
115 | 115 | |
116 | - if (!$this->instantiator) { |
|
116 | + if ( ! $this->instantiator) { |
|
117 | 117 | $this->instantiator = new Instantiator(); |
118 | 118 | } |
119 | 119 |
@@ -21,32 +21,32 @@ |
||
21 | 21 | */ |
22 | 22 | class NameGenerator |
23 | 23 | { |
24 | - private static $counter = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Generates name. |
|
28 | - * |
|
29 | - * @param ReflectionClass $class |
|
30 | - * @param ReflectionClass[] $interfaces |
|
31 | - * |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function name(ReflectionClass $class = null, array $interfaces) |
|
35 | - { |
|
36 | - $parts = array(); |
|
37 | - |
|
38 | - if (null !== $class) { |
|
39 | - $parts[] = $class->getName(); |
|
40 | - } else { |
|
41 | - foreach ($interfaces as $interface) { |
|
42 | - $parts[] = $interface->getShortName(); |
|
43 | - } |
|
44 | - } |
|
45 | - |
|
46 | - if (!count($parts)) { |
|
47 | - $parts[] = 'stdClass'; |
|
48 | - } |
|
49 | - |
|
50 | - return sprintf('Double\%s\P%d', implode('\\', $parts), self::$counter++); |
|
51 | - } |
|
24 | + private static $counter = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Generates name. |
|
28 | + * |
|
29 | + * @param ReflectionClass $class |
|
30 | + * @param ReflectionClass[] $interfaces |
|
31 | + * |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function name(ReflectionClass $class = null, array $interfaces) |
|
35 | + { |
|
36 | + $parts = array(); |
|
37 | + |
|
38 | + if (null !== $class) { |
|
39 | + $parts[] = $class->getName(); |
|
40 | + } else { |
|
41 | + foreach ($interfaces as $interface) { |
|
42 | + $parts[] = $interface->getShortName(); |
|
43 | + } |
|
44 | + } |
|
45 | + |
|
46 | + if (!count($parts)) { |
|
47 | + $parts[] = 'stdClass'; |
|
48 | + } |
|
49 | + |
|
50 | + return sprintf('Double\%s\P%d', implode('\\', $parts), self::$counter++); |
|
51 | + } |
|
52 | 52 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
46 | - if (!count($parts)) { |
|
46 | + if ( ! count($parts)) { |
|
47 | 47 | $parts[] = 'stdClass'; |
48 | 48 | } |
49 | 49 |
@@ -21,37 +21,37 @@ |
||
21 | 21 | */ |
22 | 22 | class ReflectionClassNewInstancePatch implements ClassPatchInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * Supports ReflectionClass |
|
26 | - * |
|
27 | - * @param ClassNode $node |
|
28 | - * |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public function supports(ClassNode $node) |
|
32 | - { |
|
33 | - return 'ReflectionClass' === $node->getParentClass(); |
|
34 | - } |
|
24 | + /** |
|
25 | + * Supports ReflectionClass |
|
26 | + * |
|
27 | + * @param ClassNode $node |
|
28 | + * |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public function supports(ClassNode $node) |
|
32 | + { |
|
33 | + return 'ReflectionClass' === $node->getParentClass(); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Updates newInstance's first argument to make it optional |
|
38 | - * |
|
39 | - * @param ClassNode $node |
|
40 | - */ |
|
41 | - public function apply(ClassNode $node) |
|
42 | - { |
|
43 | - foreach ($node->getMethod('newInstance')->getArguments() as $argument) { |
|
44 | - $argument->setDefault(null); |
|
45 | - } |
|
46 | - } |
|
36 | + /** |
|
37 | + * Updates newInstance's first argument to make it optional |
|
38 | + * |
|
39 | + * @param ClassNode $node |
|
40 | + */ |
|
41 | + public function apply(ClassNode $node) |
|
42 | + { |
|
43 | + foreach ($node->getMethod('newInstance')->getArguments() as $argument) { |
|
44 | + $argument->setDefault(null); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Returns patch priority, which determines when patch will be applied. |
|
50 | - * |
|
51 | - * @return int Priority number (higher = earlier) |
|
52 | - */ |
|
53 | - public function getPriority() |
|
54 | - { |
|
55 | - return 50; |
|
56 | - } |
|
48 | + /** |
|
49 | + * Returns patch priority, which determines when patch will be applied. |
|
50 | + * |
|
51 | + * @return int Priority number (higher = earlier) |
|
52 | + */ |
|
53 | + public function getPriority() |
|
54 | + { |
|
55 | + return 50; |
|
56 | + } |
|
57 | 57 | } |
@@ -22,55 +22,55 @@ |
||
22 | 22 | */ |
23 | 23 | class DisableConstructorPatch implements ClassPatchInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * Checks if class has `__construct` method. |
|
27 | - * |
|
28 | - * @param ClassNode $node |
|
29 | - * |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function supports(ClassNode $node) |
|
33 | - { |
|
34 | - return true; |
|
35 | - } |
|
25 | + /** |
|
26 | + * Checks if class has `__construct` method. |
|
27 | + * |
|
28 | + * @param ClassNode $node |
|
29 | + * |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function supports(ClassNode $node) |
|
33 | + { |
|
34 | + return true; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Makes all class constructor arguments optional. |
|
39 | - * |
|
40 | - * @param ClassNode $node |
|
41 | - */ |
|
42 | - public function apply(ClassNode $node) |
|
43 | - { |
|
44 | - if (!$node->isExtendable('__construct')) { |
|
45 | - return; |
|
46 | - } |
|
37 | + /** |
|
38 | + * Makes all class constructor arguments optional. |
|
39 | + * |
|
40 | + * @param ClassNode $node |
|
41 | + */ |
|
42 | + public function apply(ClassNode $node) |
|
43 | + { |
|
44 | + if (!$node->isExtendable('__construct')) { |
|
45 | + return; |
|
46 | + } |
|
47 | 47 | |
48 | - if (!$node->hasMethod('__construct')) { |
|
49 | - $node->addMethod(new MethodNode('__construct', '')); |
|
48 | + if (!$node->hasMethod('__construct')) { |
|
49 | + $node->addMethod(new MethodNode('__construct', '')); |
|
50 | 50 | |
51 | - return; |
|
52 | - } |
|
51 | + return; |
|
52 | + } |
|
53 | 53 | |
54 | - $constructor = $node->getMethod('__construct'); |
|
55 | - foreach ($constructor->getArguments() as $argument) { |
|
56 | - $argument->setDefault(null); |
|
57 | - } |
|
54 | + $constructor = $node->getMethod('__construct'); |
|
55 | + foreach ($constructor->getArguments() as $argument) { |
|
56 | + $argument->setDefault(null); |
|
57 | + } |
|
58 | 58 | |
59 | - $constructor->setCode(<<<PHP |
|
59 | + $constructor->setCode(<<<PHP |
|
60 | 60 | if (0 < func_num_args()) { |
61 | 61 | call_user_func_array(array('parent', '__construct'), func_get_args()); |
62 | 62 | } |
63 | 63 | PHP |
64 | - ); |
|
65 | - } |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns patch priority, which determines when patch will be applied. |
|
69 | - * |
|
70 | - * @return int Priority number (higher - earlier) |
|
71 | - */ |
|
72 | - public function getPriority() |
|
73 | - { |
|
74 | - return 100; |
|
75 | - } |
|
67 | + /** |
|
68 | + * Returns patch priority, which determines when patch will be applied. |
|
69 | + * |
|
70 | + * @return int Priority number (higher - earlier) |
|
71 | + */ |
|
72 | + public function getPriority() |
|
73 | + { |
|
74 | + return 100; |
|
75 | + } |
|
76 | 76 | } |
@@ -41,11 +41,11 @@ |
||
41 | 41 | */ |
42 | 42 | public function apply(ClassNode $node) |
43 | 43 | { |
44 | - if (!$node->isExtendable('__construct')) { |
|
44 | + if ( ! $node->isExtendable('__construct')) { |
|
45 | 45 | return; |
46 | 46 | } |
47 | 47 | |
48 | - if (!$node->hasMethod('__construct')) { |
|
48 | + if ( ! $node->hasMethod('__construct')) { |
|
49 | 49 | $node->addMethod(new MethodNode('__construct', '')); |
50 | 50 | |
51 | 51 | return; |
@@ -20,49 +20,49 @@ |
||
20 | 20 | */ |
21 | 21 | class KeywordPatch implements ClassPatchInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * Support any class |
|
25 | - * |
|
26 | - * @param ClassNode $node |
|
27 | - * |
|
28 | - * @return boolean |
|
29 | - */ |
|
30 | - public function supports(ClassNode $node) |
|
31 | - { |
|
32 | - return true; |
|
33 | - } |
|
23 | + /** |
|
24 | + * Support any class |
|
25 | + * |
|
26 | + * @param ClassNode $node |
|
27 | + * |
|
28 | + * @return boolean |
|
29 | + */ |
|
30 | + public function supports(ClassNode $node) |
|
31 | + { |
|
32 | + return true; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Remove methods that clash with php keywords |
|
37 | - * |
|
38 | - * @param ClassNode $node |
|
39 | - */ |
|
40 | - public function apply(ClassNode $node) |
|
41 | - { |
|
42 | - $methodNames = array_keys($node->getMethods()); |
|
43 | - $methodsToRemove = array_intersect($methodNames, $this->getKeywords()); |
|
44 | - foreach ($methodsToRemove as $methodName) { |
|
45 | - $node->removeMethod($methodName); |
|
46 | - } |
|
47 | - } |
|
35 | + /** |
|
36 | + * Remove methods that clash with php keywords |
|
37 | + * |
|
38 | + * @param ClassNode $node |
|
39 | + */ |
|
40 | + public function apply(ClassNode $node) |
|
41 | + { |
|
42 | + $methodNames = array_keys($node->getMethods()); |
|
43 | + $methodsToRemove = array_intersect($methodNames, $this->getKeywords()); |
|
44 | + foreach ($methodsToRemove as $methodName) { |
|
45 | + $node->removeMethod($methodName); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Returns patch priority, which determines when patch will be applied. |
|
51 | - * |
|
52 | - * @return int Priority number (higher - earlier) |
|
53 | - */ |
|
54 | - public function getPriority() |
|
55 | - { |
|
56 | - return 49; |
|
57 | - } |
|
49 | + /** |
|
50 | + * Returns patch priority, which determines when patch will be applied. |
|
51 | + * |
|
52 | + * @return int Priority number (higher - earlier) |
|
53 | + */ |
|
54 | + public function getPriority() |
|
55 | + { |
|
56 | + return 49; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Returns array of php keywords. |
|
61 | - * |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - private function getKeywords() |
|
65 | - { |
|
66 | - return ['__halt_compiler']; |
|
67 | - } |
|
59 | + /** |
|
60 | + * Returns array of php keywords. |
|
61 | + * |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + private function getKeywords() |
|
65 | + { |
|
66 | + return ['__halt_compiler']; |
|
67 | + } |
|
68 | 68 | } |
@@ -22,27 +22,27 @@ |
||
22 | 22 | */ |
23 | 23 | interface ClassPatchInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * Checks if patch supports specific class node. |
|
27 | - * |
|
28 | - * @param ClassNode $node |
|
29 | - * |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function supports(ClassNode $node); |
|
25 | + /** |
|
26 | + * Checks if patch supports specific class node. |
|
27 | + * |
|
28 | + * @param ClassNode $node |
|
29 | + * |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function supports(ClassNode $node); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Applies patch to the specific class node. |
|
36 | - * |
|
37 | - * @param ClassNode $node |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function apply(ClassNode $node); |
|
34 | + /** |
|
35 | + * Applies patch to the specific class node. |
|
36 | + * |
|
37 | + * @param ClassNode $node |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function apply(ClassNode $node); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Returns patch priority, which determines when patch will be applied. |
|
44 | - * |
|
45 | - * @return int Priority number (higher - earlier) |
|
46 | - */ |
|
47 | - public function getPriority(); |
|
42 | + /** |
|
43 | + * Returns patch priority, which determines when patch will be applied. |
|
44 | + * |
|
45 | + * @return int Priority number (higher - earlier) |
|
46 | + */ |
|
47 | + public function getPriority(); |
|
48 | 48 | } |
@@ -23,76 +23,76 @@ |
||
23 | 23 | */ |
24 | 24 | class TraversablePatch implements ClassPatchInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * Supports nodetree, that implement Traversable, but not Iterator or IteratorAggregate. |
|
28 | - * |
|
29 | - * @param ClassNode $node |
|
30 | - * |
|
31 | - * @return bool |
|
32 | - */ |
|
33 | - public function supports(ClassNode $node) |
|
34 | - { |
|
35 | - if (in_array('Iterator', $node->getInterfaces())) { |
|
36 | - return false; |
|
37 | - } |
|
38 | - if (in_array('IteratorAggregate', $node->getInterfaces())) { |
|
39 | - return false; |
|
40 | - } |
|
26 | + /** |
|
27 | + * Supports nodetree, that implement Traversable, but not Iterator or IteratorAggregate. |
|
28 | + * |
|
29 | + * @param ClassNode $node |
|
30 | + * |
|
31 | + * @return bool |
|
32 | + */ |
|
33 | + public function supports(ClassNode $node) |
|
34 | + { |
|
35 | + if (in_array('Iterator', $node->getInterfaces())) { |
|
36 | + return false; |
|
37 | + } |
|
38 | + if (in_array('IteratorAggregate', $node->getInterfaces())) { |
|
39 | + return false; |
|
40 | + } |
|
41 | 41 | |
42 | - foreach ($node->getInterfaces() as $interface) { |
|
43 | - if ('Traversable' !== $interface && !is_subclass_of($interface, 'Traversable')) { |
|
44 | - continue; |
|
45 | - } |
|
46 | - if ('Iterator' === $interface || is_subclass_of($interface, 'Iterator')) { |
|
47 | - continue; |
|
48 | - } |
|
49 | - if ('IteratorAggregate' === $interface || is_subclass_of($interface, 'IteratorAggregate')) { |
|
50 | - continue; |
|
51 | - } |
|
42 | + foreach ($node->getInterfaces() as $interface) { |
|
43 | + if ('Traversable' !== $interface && !is_subclass_of($interface, 'Traversable')) { |
|
44 | + continue; |
|
45 | + } |
|
46 | + if ('Iterator' === $interface || is_subclass_of($interface, 'Iterator')) { |
|
47 | + continue; |
|
48 | + } |
|
49 | + if ('IteratorAggregate' === $interface || is_subclass_of($interface, 'IteratorAggregate')) { |
|
50 | + continue; |
|
51 | + } |
|
52 | 52 | |
53 | - return true; |
|
54 | - } |
|
53 | + return true; |
|
54 | + } |
|
55 | 55 | |
56 | - return false; |
|
57 | - } |
|
56 | + return false; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Forces class to implement Iterator interface. |
|
61 | - * |
|
62 | - * @param ClassNode $node |
|
63 | - */ |
|
64 | - public function apply(ClassNode $node) |
|
65 | - { |
|
66 | - $node->addInterface('Iterator'); |
|
59 | + /** |
|
60 | + * Forces class to implement Iterator interface. |
|
61 | + * |
|
62 | + * @param ClassNode $node |
|
63 | + */ |
|
64 | + public function apply(ClassNode $node) |
|
65 | + { |
|
66 | + $node->addInterface('Iterator'); |
|
67 | 67 | |
68 | - $currentMethod = new MethodNode('current'); |
|
69 | - (\PHP_VERSION_ID >= 80100) && $currentMethod->setReturnTypeNode(new ReturnTypeNode('mixed')); |
|
70 | - $node->addMethod($currentMethod); |
|
68 | + $currentMethod = new MethodNode('current'); |
|
69 | + (\PHP_VERSION_ID >= 80100) && $currentMethod->setReturnTypeNode(new ReturnTypeNode('mixed')); |
|
70 | + $node->addMethod($currentMethod); |
|
71 | 71 | |
72 | - $keyMethod = new MethodNode('key'); |
|
73 | - (\PHP_VERSION_ID >= 80100) && $keyMethod->setReturnTypeNode(new ReturnTypeNode('mixed')); |
|
74 | - $node->addMethod($keyMethod); |
|
72 | + $keyMethod = new MethodNode('key'); |
|
73 | + (\PHP_VERSION_ID >= 80100) && $keyMethod->setReturnTypeNode(new ReturnTypeNode('mixed')); |
|
74 | + $node->addMethod($keyMethod); |
|
75 | 75 | |
76 | - $nextMethod = new MethodNode('next'); |
|
77 | - (\PHP_VERSION_ID >= 80100) && $nextMethod->setReturnTypeNode(new ReturnTypeNode('void')); |
|
78 | - $node->addMethod($nextMethod); |
|
76 | + $nextMethod = new MethodNode('next'); |
|
77 | + (\PHP_VERSION_ID >= 80100) && $nextMethod->setReturnTypeNode(new ReturnTypeNode('void')); |
|
78 | + $node->addMethod($nextMethod); |
|
79 | 79 | |
80 | - $rewindMethod = new MethodNode('rewind'); |
|
81 | - (\PHP_VERSION_ID >= 80100) && $rewindMethod->setReturnTypeNode(new ReturnTypeNode('void')); |
|
82 | - $node->addMethod($rewindMethod); |
|
80 | + $rewindMethod = new MethodNode('rewind'); |
|
81 | + (\PHP_VERSION_ID >= 80100) && $rewindMethod->setReturnTypeNode(new ReturnTypeNode('void')); |
|
82 | + $node->addMethod($rewindMethod); |
|
83 | 83 | |
84 | - $validMethod = new MethodNode('valid'); |
|
85 | - (\PHP_VERSION_ID >= 80100) && $validMethod->setReturnTypeNode(new ReturnTypeNode('bool')); |
|
86 | - $node->addMethod($validMethod); |
|
87 | - } |
|
84 | + $validMethod = new MethodNode('valid'); |
|
85 | + (\PHP_VERSION_ID >= 80100) && $validMethod->setReturnTypeNode(new ReturnTypeNode('bool')); |
|
86 | + $node->addMethod($validMethod); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Returns patch priority, which determines when patch will be applied. |
|
91 | - * |
|
92 | - * @return int Priority number (higher - earlier) |
|
93 | - */ |
|
94 | - public function getPriority() |
|
95 | - { |
|
96 | - return 100; |
|
97 | - } |
|
89 | + /** |
|
90 | + * Returns patch priority, which determines when patch will be applied. |
|
91 | + * |
|
92 | + * @return int Priority number (higher - earlier) |
|
93 | + */ |
|
94 | + public function getPriority() |
|
95 | + { |
|
96 | + return 100; |
|
97 | + } |
|
98 | 98 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | foreach ($node->getInterfaces() as $interface) { |
43 | - if ('Traversable' !== $interface && !is_subclass_of($interface, 'Traversable')) { |
|
43 | + if ('Traversable' !== $interface && ! is_subclass_of($interface, 'Traversable')) { |
|
44 | 44 | continue; |
45 | 45 | } |
46 | 46 | if ('Iterator' === $interface || is_subclass_of($interface, 'Iterator')) { |
@@ -7,89 +7,89 @@ |
||
7 | 7 | |
8 | 8 | class ThrowablePatch implements ClassPatchInterface |
9 | 9 | { |
10 | - /** |
|
11 | - * Checks if patch supports specific class node. |
|
12 | - * |
|
13 | - * @param ClassNode $node |
|
14 | - * @return bool |
|
15 | - */ |
|
16 | - public function supports(ClassNode $node) |
|
17 | - { |
|
18 | - return $this->implementsAThrowableInterface($node) && $this->doesNotExtendAThrowableClass($node); |
|
19 | - } |
|
10 | + /** |
|
11 | + * Checks if patch supports specific class node. |
|
12 | + * |
|
13 | + * @param ClassNode $node |
|
14 | + * @return bool |
|
15 | + */ |
|
16 | + public function supports(ClassNode $node) |
|
17 | + { |
|
18 | + return $this->implementsAThrowableInterface($node) && $this->doesNotExtendAThrowableClass($node); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @param ClassNode $node |
|
23 | - * @return bool |
|
24 | - */ |
|
25 | - private function implementsAThrowableInterface(ClassNode $node) |
|
26 | - { |
|
27 | - foreach ($node->getInterfaces() as $type) { |
|
28 | - if (is_a($type, 'Throwable', true)) { |
|
29 | - return true; |
|
30 | - } |
|
31 | - } |
|
21 | + /** |
|
22 | + * @param ClassNode $node |
|
23 | + * @return bool |
|
24 | + */ |
|
25 | + private function implementsAThrowableInterface(ClassNode $node) |
|
26 | + { |
|
27 | + foreach ($node->getInterfaces() as $type) { |
|
28 | + if (is_a($type, 'Throwable', true)) { |
|
29 | + return true; |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - return false; |
|
34 | - } |
|
33 | + return false; |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param ClassNode $node |
|
38 | - * @return bool |
|
39 | - */ |
|
40 | - private function doesNotExtendAThrowableClass(ClassNode $node) |
|
41 | - { |
|
42 | - return !is_a($node->getParentClass(), 'Throwable', true); |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param ClassNode $node |
|
38 | + * @return bool |
|
39 | + */ |
|
40 | + private function doesNotExtendAThrowableClass(ClassNode $node) |
|
41 | + { |
|
42 | + return !is_a($node->getParentClass(), 'Throwable', true); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Applies patch to the specific class node. |
|
47 | - * |
|
48 | - * @param ClassNode $node |
|
49 | - * |
|
50 | - * @return void |
|
51 | - */ |
|
52 | - public function apply(ClassNode $node) |
|
53 | - { |
|
54 | - $this->checkItCanBeDoubled($node); |
|
55 | - $this->setParentClassToException($node); |
|
56 | - } |
|
45 | + /** |
|
46 | + * Applies patch to the specific class node. |
|
47 | + * |
|
48 | + * @param ClassNode $node |
|
49 | + * |
|
50 | + * @return void |
|
51 | + */ |
|
52 | + public function apply(ClassNode $node) |
|
53 | + { |
|
54 | + $this->checkItCanBeDoubled($node); |
|
55 | + $this->setParentClassToException($node); |
|
56 | + } |
|
57 | 57 | |
58 | - private function checkItCanBeDoubled(ClassNode $node) |
|
59 | - { |
|
60 | - $className = $node->getParentClass(); |
|
61 | - if ($className !== 'stdClass') { |
|
62 | - throw new ClassCreatorException( |
|
63 | - sprintf( |
|
64 | - 'Cannot double concrete class %s as well as implement Traversable', |
|
65 | - $className |
|
66 | - ), |
|
67 | - $node |
|
68 | - ); |
|
69 | - } |
|
70 | - } |
|
58 | + private function checkItCanBeDoubled(ClassNode $node) |
|
59 | + { |
|
60 | + $className = $node->getParentClass(); |
|
61 | + if ($className !== 'stdClass') { |
|
62 | + throw new ClassCreatorException( |
|
63 | + sprintf( |
|
64 | + 'Cannot double concrete class %s as well as implement Traversable', |
|
65 | + $className |
|
66 | + ), |
|
67 | + $node |
|
68 | + ); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - private function setParentClassToException(ClassNode $node) |
|
73 | - { |
|
74 | - $node->setParentClass('Exception'); |
|
72 | + private function setParentClassToException(ClassNode $node) |
|
73 | + { |
|
74 | + $node->setParentClass('Exception'); |
|
75 | 75 | |
76 | - $node->removeMethod('getMessage'); |
|
77 | - $node->removeMethod('getCode'); |
|
78 | - $node->removeMethod('getFile'); |
|
79 | - $node->removeMethod('getLine'); |
|
80 | - $node->removeMethod('getTrace'); |
|
81 | - $node->removeMethod('getPrevious'); |
|
82 | - $node->removeMethod('getNext'); |
|
83 | - $node->removeMethod('getTraceAsString'); |
|
84 | - } |
|
76 | + $node->removeMethod('getMessage'); |
|
77 | + $node->removeMethod('getCode'); |
|
78 | + $node->removeMethod('getFile'); |
|
79 | + $node->removeMethod('getLine'); |
|
80 | + $node->removeMethod('getTrace'); |
|
81 | + $node->removeMethod('getPrevious'); |
|
82 | + $node->removeMethod('getNext'); |
|
83 | + $node->removeMethod('getTraceAsString'); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Returns patch priority, which determines when patch will be applied. |
|
88 | - * |
|
89 | - * @return int Priority number (higher - earlier) |
|
90 | - */ |
|
91 | - public function getPriority() |
|
92 | - { |
|
93 | - return 100; |
|
94 | - } |
|
86 | + /** |
|
87 | + * Returns patch priority, which determines when patch will be applied. |
|
88 | + * |
|
89 | + * @return int Priority number (higher - earlier) |
|
90 | + */ |
|
91 | + public function getPriority() |
|
92 | + { |
|
93 | + return 100; |
|
94 | + } |
|
95 | 95 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | */ |
40 | 40 | private function doesNotExtendAThrowableClass(ClassNode $node) |
41 | 41 | { |
42 | - return !is_a($node->getParentClass(), 'Throwable', true); |
|
42 | + return ! is_a($node->getParentClass(), 'Throwable', true); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -25,89 +25,89 @@ |
||
25 | 25 | */ |
26 | 26 | class ProphecySubjectPatch implements ClassPatchInterface |
27 | 27 | { |
28 | - /** |
|
29 | - * Always returns true. |
|
30 | - * |
|
31 | - * @param ClassNode $node |
|
32 | - * |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - public function supports(ClassNode $node) |
|
36 | - { |
|
37 | - return true; |
|
38 | - } |
|
28 | + /** |
|
29 | + * Always returns true. |
|
30 | + * |
|
31 | + * @param ClassNode $node |
|
32 | + * |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + public function supports(ClassNode $node) |
|
36 | + { |
|
37 | + return true; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Apply Prophecy functionality to class node. |
|
42 | - * |
|
43 | - * @param ClassNode $node |
|
44 | - */ |
|
45 | - public function apply(ClassNode $node) |
|
46 | - { |
|
47 | - $node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface'); |
|
48 | - $node->addProperty('objectProphecyClosure', 'private'); |
|
40 | + /** |
|
41 | + * Apply Prophecy functionality to class node. |
|
42 | + * |
|
43 | + * @param ClassNode $node |
|
44 | + */ |
|
45 | + public function apply(ClassNode $node) |
|
46 | + { |
|
47 | + $node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface'); |
|
48 | + $node->addProperty('objectProphecyClosure', 'private'); |
|
49 | 49 | |
50 | - foreach ($node->getMethods() as $name => $method) { |
|
51 | - if ('__construct' === strtolower($name)) { |
|
52 | - continue; |
|
53 | - } |
|
50 | + foreach ($node->getMethods() as $name => $method) { |
|
51 | + if ('__construct' === strtolower($name)) { |
|
52 | + continue; |
|
53 | + } |
|
54 | 54 | |
55 | - if (!$method->getReturnTypeNode()->hasReturnStatement()) { |
|
56 | - $method->setCode( |
|
57 | - '$this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());' |
|
58 | - ); |
|
59 | - } else { |
|
60 | - $method->setCode( |
|
61 | - 'return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());' |
|
62 | - ); |
|
63 | - } |
|
64 | - } |
|
55 | + if (!$method->getReturnTypeNode()->hasReturnStatement()) { |
|
56 | + $method->setCode( |
|
57 | + '$this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());' |
|
58 | + ); |
|
59 | + } else { |
|
60 | + $method->setCode( |
|
61 | + 'return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());' |
|
62 | + ); |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - $prophecySetter = new MethodNode('setProphecy'); |
|
67 | - $prophecyArgument = new ArgumentNode('prophecy'); |
|
68 | - $prophecyArgument->setTypeNode(new ArgumentTypeNode('Prophecy\Prophecy\ProphecyInterface')); |
|
69 | - $prophecySetter->addArgument($prophecyArgument); |
|
70 | - $prophecySetter->setCode(<<<PHP |
|
66 | + $prophecySetter = new MethodNode('setProphecy'); |
|
67 | + $prophecyArgument = new ArgumentNode('prophecy'); |
|
68 | + $prophecyArgument->setTypeNode(new ArgumentTypeNode('Prophecy\Prophecy\ProphecyInterface')); |
|
69 | + $prophecySetter->addArgument($prophecyArgument); |
|
70 | + $prophecySetter->setCode(<<<PHP |
|
71 | 71 | if (null === \$this->objectProphecyClosure) { |
72 | 72 | \$this->objectProphecyClosure = static function () use (\$prophecy) { |
73 | 73 | return \$prophecy; |
74 | 74 | }; |
75 | 75 | } |
76 | 76 | PHP |
77 | - ); |
|
77 | + ); |
|
78 | 78 | |
79 | - $prophecyGetter = new MethodNode('getProphecy'); |
|
80 | - $prophecyGetter->setCode('return \call_user_func($this->objectProphecyClosure);'); |
|
79 | + $prophecyGetter = new MethodNode('getProphecy'); |
|
80 | + $prophecyGetter->setCode('return \call_user_func($this->objectProphecyClosure);'); |
|
81 | 81 | |
82 | - if ($node->hasMethod('__call')) { |
|
83 | - $__call = $node->getMethod('__call'); |
|
84 | - } else { |
|
85 | - $__call = new MethodNode('__call'); |
|
86 | - $__call->addArgument(new ArgumentNode('name')); |
|
87 | - $__call->addArgument(new ArgumentNode('arguments')); |
|
82 | + if ($node->hasMethod('__call')) { |
|
83 | + $__call = $node->getMethod('__call'); |
|
84 | + } else { |
|
85 | + $__call = new MethodNode('__call'); |
|
86 | + $__call->addArgument(new ArgumentNode('name')); |
|
87 | + $__call->addArgument(new ArgumentNode('arguments')); |
|
88 | 88 | |
89 | - $node->addMethod($__call, true); |
|
90 | - } |
|
89 | + $node->addMethod($__call, true); |
|
90 | + } |
|
91 | 91 | |
92 | - $__call->setCode(<<<PHP |
|
92 | + $__call->setCode(<<<PHP |
|
93 | 93 | throw new \Prophecy\Exception\Doubler\MethodNotFoundException( |
94 | 94 | sprintf('Method `%s::%s()` not found.', get_class(\$this), func_get_arg(0)), |
95 | 95 | get_class(\$this), func_get_arg(0) |
96 | 96 | ); |
97 | 97 | PHP |
98 | - ); |
|
98 | + ); |
|
99 | 99 | |
100 | - $node->addMethod($prophecySetter, true); |
|
101 | - $node->addMethod($prophecyGetter, true); |
|
102 | - } |
|
100 | + $node->addMethod($prophecySetter, true); |
|
101 | + $node->addMethod($prophecyGetter, true); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Returns patch priority, which determines when patch will be applied. |
|
106 | - * |
|
107 | - * @return int Priority number (higher - earlier) |
|
108 | - */ |
|
109 | - public function getPriority() |
|
110 | - { |
|
111 | - return 0; |
|
112 | - } |
|
104 | + /** |
|
105 | + * Returns patch priority, which determines when patch will be applied. |
|
106 | + * |
|
107 | + * @return int Priority number (higher - earlier) |
|
108 | + */ |
|
109 | + public function getPriority() |
|
110 | + { |
|
111 | + return 0; |
|
112 | + } |
|
113 | 113 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | continue; |
53 | 53 | } |
54 | 54 | |
55 | - if (!$method->getReturnTypeNode()->hasReturnStatement()) { |
|
55 | + if ( ! $method->getReturnTypeNode()->hasReturnStatement()) { |
|
56 | 56 | $method->setCode( |
57 | 57 | '$this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());' |
58 | 58 | ); |