@@ -13,7 +13,6 @@ |
||
13 | 13 | use PhpParser\Node; |
14 | 14 | use PhpParser\Node\Stmt\ClassMethod; |
15 | 15 | use PhpParser\NodeVisitorAbstract; |
16 | - |
|
17 | 16 | use Kenjis\MonkeyPatch\Patcher\MethodPatcher; |
18 | 17 | |
19 | 18 | class NodeVisitor extends NodeVisitorAbstract |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Part of ci-phpunit-test |
|
4 | - * |
|
5 | - * @author Kenji Suzuki <https://github.com/kenjis> |
|
6 | - * @license MIT License |
|
7 | - * @copyright 2016 Kenji Suzuki |
|
8 | - * @link https://github.com/kenjis/ci-phpunit-test |
|
9 | - */ |
|
3 | + * Part of ci-phpunit-test |
|
4 | + * |
|
5 | + * @author Kenji Suzuki <https://github.com/kenjis> |
|
6 | + * @license MIT License |
|
7 | + * @copyright 2016 Kenji Suzuki |
|
8 | + * @link https://github.com/kenjis/ci-phpunit-test |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | namespace Kenjis\MonkeyPatch\Patcher\ConstantPatcher; |
12 | 12 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | public function enterNode(Node $node) |
26 | 26 | { |
27 | - $callback = [$this, 'before' . ucfirst($node->getType())]; |
|
27 | + $callback = [$this, 'before'.ucfirst($node->getType())]; |
|
28 | 28 | if (is_callable($callback)) { |
29 | 29 | call_user_func_array($callback, [$node]); |
30 | 30 | } |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | |
33 | 33 | public function leaveNode(Node $node) |
34 | 34 | { |
35 | - if (! ($node instanceof ConstFetch)) |
|
35 | + if ( ! ($node instanceof ConstFetch)) |
|
36 | 36 | { |
37 | - $callback = [$this, 'rewrite' . ucfirst($node->getType())]; |
|
37 | + $callback = [$this, 'rewrite'.ucfirst($node->getType())]; |
|
38 | 38 | if (is_callable($callback)) { |
39 | 39 | call_user_func_array($callback, [$node]); |
40 | 40 | } |
@@ -47,24 +47,24 @@ discard block |
||
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - if (! ($node->name instanceof Name)) |
|
50 | + if ( ! ($node->name instanceof Name)) |
|
51 | 51 | { |
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | - if (! $node->name->isUnqualified()) |
|
55 | + if ( ! $node->name->isUnqualified()) |
|
56 | 56 | { |
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $replacement = new FullyQualified(array()); |
61 | 61 | $replacement->set( |
62 | - '\__ConstProxy__::get(\'' . (string) $node->name . '\')' |
|
62 | + '\__ConstProxy__::get(\''.(string) $node->name.'\')' |
|
63 | 63 | ); |
64 | 64 | |
65 | 65 | $pos = $node->getAttribute('startTokenPos'); |
66 | 66 | ConstantPatcher::$replacement[$pos] = |
67 | - '\__ConstProxy__::get(\'' . (string) $node->name .'\')'; |
|
67 | + '\__ConstProxy__::get(\''.(string) $node->name.'\')'; |
|
68 | 68 | |
69 | 69 | $node->name = $replacement; |
70 | 70 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @param string $constant constant name |
36 | 36 | * @param mixed $value value |
37 | - * @param string $class_name class::method to apply this patch |
|
37 | + * @param string $class_method class::method to apply this patch |
|
38 | 38 | * |
39 | 39 | * @throws LogicException |
40 | 40 | */ |
@@ -53,6 +53,9 @@ discard block |
||
53 | 53 | self::$patches_to_apply = []; |
54 | 54 | } |
55 | 55 | |
56 | + /** |
|
57 | + * @param string $constant |
|
58 | + */ |
|
56 | 59 | protected static function logInvocation($constant) |
57 | 60 | { |
58 | 61 | if (MonkeyPatchManager::$debug) |
@@ -70,6 +73,9 @@ discard block |
||
70 | 73 | } |
71 | 74 | } |
72 | 75 | |
76 | + /** |
|
77 | + * @param string $constant |
|
78 | + */ |
|
73 | 79 | protected static function checkCalledMethod($constant) |
74 | 80 | { |
75 | 81 | $trace = debug_backtrace(); |
@@ -13,14 +13,9 @@ |
||
13 | 13 | class_alias('Kenjis\MonkeyPatch\Patcher\ConstantPatcher\Proxy', '__ConstProxy__'); |
14 | 14 | |
15 | 15 | use LogicException; |
16 | -use ReflectionConstant; |
|
17 | -use ReflectionException; |
|
18 | - |
|
19 | 16 | use Kenjis\MonkeyPatch\Patcher\ConstantPatcher; |
20 | 17 | use Kenjis\MonkeyPatch\Patcher\Backtrace; |
21 | 18 | use Kenjis\MonkeyPatch\MonkeyPatchManager; |
22 | -use Kenjis\MonkeyPatch\Cache; |
|
23 | -use Kenjis\MonkeyPatch\InvocationVerifier; |
|
24 | 19 | |
25 | 20 | class Proxy |
26 | 21 | { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $method = isset($info['class_method']) ? $info['class_method'] : $info['function']; |
66 | 66 | |
67 | 67 | MonkeyPatchManager::log( |
68 | - 'invoke_const: ' . $constant . ') on line ' . $line . ' in ' . $file . ' by ' . $method . '()' |
|
68 | + 'invoke_const: '.$constant.') on line '.$line.' in '.$file.' by '.$method.'()' |
|
69 | 69 | ); |
70 | 70 | } |
71 | 71 | } |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | |
112 | 112 | if (isset(self::$patches_to_apply[$constant])) |
113 | 113 | { |
114 | - if (! self::checkCalledMethod($constant)) |
|
114 | + if ( ! self::checkCalledMethod($constant)) |
|
115 | 115 | { |
116 | 116 | MonkeyPatchManager::log( |
117 | - 'invoke_const: ' . $constant . ' not patched (out of scope)' |
|
117 | + 'invoke_const: '.$constant.' not patched (out of scope)' |
|
118 | 118 | ); |
119 | 119 | return constant($constant); |
120 | 120 | } |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | |
123 | 123 | if (array_key_exists($constant, self::$patches)) |
124 | 124 | { |
125 | - MonkeyPatchManager::log('invoke_const: ' . $constant . ' patched'); |
|
125 | + MonkeyPatchManager::log('invoke_const: '.$constant.' patched'); |
|
126 | 126 | return self::$patches[$constant]; |
127 | 127 | } |
128 | 128 | |
129 | 129 | MonkeyPatchManager::log( |
130 | - 'invoke_const: ' . $constant . ' not patched (no patch)' |
|
130 | + 'invoke_const: '.$constant.' not patched (no patch)' |
|
131 | 131 | ); |
132 | 132 | return constant($constant); |
133 | 133 | } |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Part of ci-phpunit-test |
|
4 | - * |
|
5 | - * @author Kenji Suzuki <https://github.com/kenjis> |
|
6 | - * @license MIT License |
|
7 | - * @copyright 2015 Kenji Suzuki |
|
8 | - * @link https://github.com/kenjis/ci-phpunit-test |
|
9 | - */ |
|
3 | + * Part of ci-phpunit-test |
|
4 | + * |
|
5 | + * @author Kenji Suzuki <https://github.com/kenjis> |
|
6 | + * @license MIT License |
|
7 | + * @copyright 2015 Kenji Suzuki |
|
8 | + * @link https://github.com/kenjis/ci-phpunit-test |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | namespace Kenjis\MonkeyPatch; |
12 | 12 | |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
40 | - * Patch on constant |
|
41 | - * |
|
42 | - * @param type $constant |
|
43 | - * @param type $value |
|
44 | - * @param type $class_method |
|
45 | - */ |
|
40 | + * Patch on constant |
|
41 | + * |
|
42 | + * @param type $constant |
|
43 | + * @param type $value |
|
44 | + * @param type $class_method |
|
45 | + */ |
|
46 | 46 | public static function patchConstant($constant, $value, $class_method = null) |
47 | 47 | { |
48 | 48 | ConstProxy::patch($constant, $value, $class_method); |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Part of ci-phpunit-test |
|
4 | - * |
|
5 | - * @author Kenji Suzuki <https://github.com/kenjis> |
|
6 | - * @license MIT License |
|
7 | - * @copyright 2016 Kenji Suzuki |
|
8 | - * @link https://github.com/kenjis/ci-phpunit-test |
|
9 | - */ |
|
3 | + * Part of ci-phpunit-test |
|
4 | + * |
|
5 | + * @author Kenji Suzuki <https://github.com/kenjis> |
|
6 | + * @license MIT License |
|
7 | + * @copyright 2016 Kenji Suzuki |
|
8 | + * @link https://github.com/kenjis/ci-phpunit-test |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | namespace Kenjis\MonkeyPatch\Patcher; |
12 | 12 |
@@ -10,8 +10,8 @@ |
||
10 | 10 | |
11 | 11 | namespace Kenjis\MonkeyPatch\Patcher; |
12 | 12 | |
13 | -require __DIR__ . '/ConstantPatcher/NodeVisitor.php'; |
|
14 | -require __DIR__ . '/ConstantPatcher/Proxy.php'; |
|
13 | +require __DIR__.'/ConstantPatcher/NodeVisitor.php'; |
|
14 | +require __DIR__.'/ConstantPatcher/Proxy.php'; |
|
15 | 15 | |
16 | 16 | use LogicException; |
17 | 17 |
@@ -173,13 +173,11 @@ |
||
173 | 173 | if (is_string($token)) |
174 | 174 | { |
175 | 175 | $new_source .= $token; |
176 | - } |
|
177 | - elseif ($i == $replacement['key']) |
|
176 | + } elseif ($i == $replacement['key']) |
|
178 | 177 | { |
179 | 178 | $new_source .= $replacement['value']; |
180 | 179 | $replacement = each(self::$replacement); |
181 | - } |
|
182 | - else |
|
180 | + } else |
|
183 | 181 | { |
184 | 182 | $new_source .= $token[1]; |
185 | 183 | } |