@@ -35,6 +35,9 @@ discard block |
||
| 35 | 35 | 'ConstantPatcher', |
| 36 | 36 | ]; |
| 37 | 37 | |
| 38 | + /** |
|
| 39 | + * @param string $message |
|
| 40 | + */ |
|
| 38 | 41 | public static function log($message) |
| 39 | 42 | { |
| 40 | 43 | if (! self::$debug) |
@@ -303,6 +306,9 @@ discard block |
||
| 303 | 306 | self::$load_patchers = true; |
| 304 | 307 | } |
| 305 | 308 | |
| 309 | + /** |
|
| 310 | + * @param string $source |
|
| 311 | + */ |
|
| 306 | 312 | protected static function execPatchers($source) |
| 307 | 313 | { |
| 308 | 314 | $patched = false; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public static function log($message) |
| 39 | 39 | { |
| 40 | - if (! self::$debug) |
|
| 40 | + if ( ! self::$debug) |
|
| 41 | 41 | { |
| 42 | 42 | return; |
| 43 | 43 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | if (self::$debug) |
| 74 | 74 | { |
| 75 | - self::$log_file = __DIR__ . '/debug.log'; |
|
| 75 | + self::$log_file = __DIR__.'/debug.log'; |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | else |
| 86 | 86 | { |
| 87 | 87 | // APPPATH is constant in CodeIgniter |
| 88 | - Cache::setProjectRootDir(APPPATH . '../'); |
|
| 88 | + Cache::setProjectRootDir(APPPATH.'../'); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if (! isset($config['cache_dir'])) |
|
| 91 | + if ( ! isset($config['cache_dir'])) |
|
| 92 | 92 | { |
| 93 | 93 | throw new LogicException('You have to set "cache_dir"'); |
| 94 | 94 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | protected static function setPaths(array $config) |
| 99 | 99 | { |
| 100 | - if (! isset($config['include_paths'])) |
|
| 100 | + if ( ! isset($config['include_paths'])) |
|
| 101 | 101 | { |
| 102 | 102 | throw new LogicException('You have to set "include_paths"'); |
| 103 | 103 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | // Updated? |
| 159 | 159 | if ($cached !== $current) |
| 160 | 160 | { |
| 161 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 161 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 162 | 162 | Cache::clearSrcCache(); |
| 163 | 163 | Cache::writeTmpIncludePaths($current); |
| 164 | 164 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | // Updated? |
| 170 | 170 | if ($cached !== $current) |
| 171 | 171 | { |
| 172 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 172 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 173 | 173 | Cache::clearSrcCache(); |
| 174 | 174 | Cache::writeTmpExcludePaths($current); |
| 175 | 175 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // Updated? |
| 183 | 183 | if ($cached !== self::$patcher_list) |
| 184 | 184 | { |
| 185 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 185 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 186 | 186 | Cache::clearSrcCache(); |
| 187 | 187 | Cache::writeTmpPatcherList(self::$patcher_list); |
| 188 | 188 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | // Updated? |
| 197 | 197 | if ($cached !== $current) |
| 198 | 198 | { |
| 199 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 199 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 200 | 200 | Cache::clearSrcCache(); |
| 201 | 201 | Cache::writeTmpFunctionWhitelist($current); |
| 202 | 202 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public static function patch($path) |
| 260 | 260 | { |
| 261 | - if (! is_readable($path)) |
|
| 261 | + if ( ! is_readable($path)) |
|
| 262 | 262 | { |
| 263 | 263 | throw new LogicException("Can't read '$path'"); |
| 264 | 264 | } |
@@ -266,17 +266,17 @@ discard block |
||
| 266 | 266 | // Check cache file |
| 267 | 267 | if ($cache_file = Cache::getValidSrcCachePath($path)) |
| 268 | 268 | { |
| 269 | - self::log('cache_hit: ' . $path); |
|
| 269 | + self::log('cache_hit: '.$path); |
|
| 270 | 270 | return fopen($cache_file, 'r'); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - self::log('cache_miss: ' . $path); |
|
| 273 | + self::log('cache_miss: '.$path); |
|
| 274 | 274 | $source = file_get_contents($path); |
| 275 | 275 | |
| 276 | 276 | list($new_source, $patched) = self::execPatchers($source); |
| 277 | 277 | |
| 278 | 278 | // Write to cache file |
| 279 | - self::log('write_cache: ' . $path); |
|
| 279 | + self::log('write_cache: '.$path); |
|
| 280 | 280 | Cache::writeSrcCacheFile($path, $new_source); |
| 281 | 281 | |
| 282 | 282 | $resource = fopen('php://memory', 'rb+'); |
@@ -292,12 +292,12 @@ discard block |
||
| 292 | 292 | return; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - require __DIR__ . '/Patcher/AbstractPatcher.php'; |
|
| 296 | - require __DIR__ . '/Patcher/Backtrace.php'; |
|
| 295 | + require __DIR__.'/Patcher/AbstractPatcher.php'; |
|
| 296 | + require __DIR__.'/Patcher/Backtrace.php'; |
|
| 297 | 297 | |
| 298 | 298 | foreach (self::$patcher_list as $classname) |
| 299 | 299 | { |
| 300 | - require __DIR__ . '/Patcher/' . $classname . '.php'; |
|
| 300 | + require __DIR__.'/Patcher/'.$classname.'.php'; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | self::$load_patchers = true; |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $patched = false; |
| 309 | 309 | foreach (self::$patcher_list as $classname) |
| 310 | 310 | { |
| 311 | - $classname = 'Kenjis\MonkeyPatch\Patcher\\' . $classname; |
|
| 311 | + $classname = 'Kenjis\MonkeyPatch\Patcher\\'.$classname; |
|
| 312 | 312 | $patcher = new $classname; |
| 313 | 313 | list($source, $patched_this) = $patcher->patch($source); |
| 314 | 314 | $patched = $patched || $patched_this; |
@@ -70,8 +70,7 @@ |
||
| 70 | 70 | if (isset($config['root_dir'])) |
| 71 | 71 | { |
| 72 | 72 | Cache::setProjectRootDir($config['root_dir']); |
| 73 | - } |
|
| 74 | - else |
|
| 73 | + } else |
|
| 75 | 74 | { |
| 76 | 75 | // APPPATH is constant in CodeIgniter |
| 77 | 76 | Cache::setProjectRootDir(APPPATH . '../'); |
@@ -15,7 +15,6 @@ |
||
| 15 | 15 | use PhpParser\Node\Name; |
| 16 | 16 | use PhpParser\Node\Name\FullyQualified; |
| 17 | 17 | use PhpParser\NodeVisitorAbstract; |
| 18 | - |
|
| 19 | 18 | use Kenjis\MonkeyPatch\Patcher\ConstantPatcher; |
| 20 | 19 | |
| 21 | 20 | class NodeVisitor extends NodeVisitorAbstract |
@@ -15,7 +15,6 @@ |
||
| 15 | 15 | use LogicException; |
| 16 | 16 | use ReflectionFunction; |
| 17 | 17 | use ReflectionException; |
| 18 | - |
|
| 19 | 18 | use Kenjis\MonkeyPatch\Patcher\FunctionPatcher; |
| 20 | 19 | use Kenjis\MonkeyPatch\Patcher\Backtrace; |
| 21 | 20 | use Kenjis\MonkeyPatch\MonkeyPatchManager; |
@@ -35,6 +35,9 @@ discard block |
||
| 35 | 35 | 'ConstantPatcher', |
| 36 | 36 | ]; |
| 37 | 37 | |
| 38 | + /** |
|
| 39 | + * @param string $message |
|
| 40 | + */ |
|
| 38 | 41 | public static function log($message) |
| 39 | 42 | { |
| 40 | 43 | if (! self::$debug) |
@@ -303,6 +306,9 @@ discard block |
||
| 303 | 306 | self::$load_patchers = true; |
| 304 | 307 | } |
| 305 | 308 | |
| 309 | + /** |
|
| 310 | + * @param string $source |
|
| 311 | + */ |
|
| 306 | 312 | protected static function execPatchers($source) |
| 307 | 313 | { |
| 308 | 314 | $patched = false; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public static function log($message) |
| 39 | 39 | { |
| 40 | - if (! self::$debug) |
|
| 40 | + if ( ! self::$debug) |
|
| 41 | 41 | { |
| 42 | 42 | return; |
| 43 | 43 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | if (self::$debug) |
| 74 | 74 | { |
| 75 | - self::$log_file = __DIR__ . '/debug.log'; |
|
| 75 | + self::$log_file = __DIR__.'/debug.log'; |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
@@ -85,10 +85,10 @@ discard block |
||
| 85 | 85 | else |
| 86 | 86 | { |
| 87 | 87 | // APPPATH is constant in CodeIgniter |
| 88 | - Cache::setProjectRootDir(APPPATH . '../'); |
|
| 88 | + Cache::setProjectRootDir(APPPATH.'../'); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if (! isset($config['cache_dir'])) |
|
| 91 | + if ( ! isset($config['cache_dir'])) |
|
| 92 | 92 | { |
| 93 | 93 | throw new LogicException('You have to set "cache_dir"'); |
| 94 | 94 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | protected static function setPaths(array $config) |
| 99 | 99 | { |
| 100 | - if (! isset($config['include_paths'])) |
|
| 100 | + if ( ! isset($config['include_paths'])) |
|
| 101 | 101 | { |
| 102 | 102 | throw new LogicException('You have to set "include_paths"'); |
| 103 | 103 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | // Updated? |
| 159 | 159 | if ($cached !== $current) |
| 160 | 160 | { |
| 161 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 161 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 162 | 162 | Cache::clearSrcCache(); |
| 163 | 163 | Cache::writeTmpIncludePaths($current); |
| 164 | 164 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | // Updated? |
| 170 | 170 | if ($cached !== $current) |
| 171 | 171 | { |
| 172 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 172 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 173 | 173 | Cache::clearSrcCache(); |
| 174 | 174 | Cache::writeTmpExcludePaths($current); |
| 175 | 175 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // Updated? |
| 183 | 183 | if ($cached !== self::$patcher_list) |
| 184 | 184 | { |
| 185 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 185 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 186 | 186 | Cache::clearSrcCache(); |
| 187 | 187 | Cache::writeTmpPatcherList(self::$patcher_list); |
| 188 | 188 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | // Updated? |
| 197 | 197 | if ($cached !== $current) |
| 198 | 198 | { |
| 199 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 199 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 200 | 200 | Cache::clearSrcCache(); |
| 201 | 201 | Cache::writeTmpFunctionWhitelist($current); |
| 202 | 202 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public static function patch($path) |
| 260 | 260 | { |
| 261 | - if (! is_readable($path)) |
|
| 261 | + if ( ! is_readable($path)) |
|
| 262 | 262 | { |
| 263 | 263 | throw new LogicException("Can't read '$path'"); |
| 264 | 264 | } |
@@ -266,17 +266,17 @@ discard block |
||
| 266 | 266 | // Check cache file |
| 267 | 267 | if ($cache_file = Cache::getValidSrcCachePath($path)) |
| 268 | 268 | { |
| 269 | - self::log('cache_hit: ' . $path); |
|
| 269 | + self::log('cache_hit: '.$path); |
|
| 270 | 270 | return fopen($cache_file, 'r'); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - self::log('cache_miss: ' . $path); |
|
| 273 | + self::log('cache_miss: '.$path); |
|
| 274 | 274 | $source = file_get_contents($path); |
| 275 | 275 | |
| 276 | 276 | list($new_source, $patched) = self::execPatchers($source); |
| 277 | 277 | |
| 278 | 278 | // Write to cache file |
| 279 | - self::log('write_cache: ' . $path); |
|
| 279 | + self::log('write_cache: '.$path); |
|
| 280 | 280 | Cache::writeSrcCacheFile($path, $new_source); |
| 281 | 281 | |
| 282 | 282 | $resource = fopen('php://memory', 'rb+'); |
@@ -292,12 +292,12 @@ discard block |
||
| 292 | 292 | return; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - require __DIR__ . '/Patcher/AbstractPatcher.php'; |
|
| 296 | - require __DIR__ . '/Patcher/Backtrace.php'; |
|
| 295 | + require __DIR__.'/Patcher/AbstractPatcher.php'; |
|
| 296 | + require __DIR__.'/Patcher/Backtrace.php'; |
|
| 297 | 297 | |
| 298 | 298 | foreach (self::$patcher_list as $classname) |
| 299 | 299 | { |
| 300 | - require __DIR__ . '/Patcher/' . $classname . '.php'; |
|
| 300 | + require __DIR__.'/Patcher/'.$classname.'.php'; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | self::$load_patchers = true; |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $patched = false; |
| 309 | 309 | foreach (self::$patcher_list as $classname) |
| 310 | 310 | { |
| 311 | - $classname = 'Kenjis\MonkeyPatch\Patcher\\' . $classname; |
|
| 311 | + $classname = 'Kenjis\MonkeyPatch\Patcher\\'.$classname; |
|
| 312 | 312 | $patcher = new $classname; |
| 313 | 313 | list($source, $patched_this) = $patcher->patch($source); |
| 314 | 314 | $patched = $patched || $patched_this; |
@@ -70,8 +70,7 @@ |
||
| 70 | 70 | if (isset($config['root_dir'])) |
| 71 | 71 | { |
| 72 | 72 | Cache::setProjectRootDir($config['root_dir']); |
| 73 | - } |
|
| 74 | - else |
|
| 73 | + } else |
|
| 75 | 74 | { |
| 76 | 75 | // APPPATH is constant in CodeIgniter |
| 77 | 76 | Cache::setProjectRootDir(APPPATH . '../'); |
@@ -20,6 +20,9 @@ |
||
| 20 | 20 | 'ConstantPatcher' => 0, |
| 21 | 21 | ]; |
| 22 | 22 | |
| 23 | + /** |
|
| 24 | + * @param string $patcher |
|
| 25 | + */ |
|
| 23 | 26 | public static function getInfo($patcher, $backtrace) |
| 24 | 27 | { |
| 25 | 28 | if (! isset(self::$map[$patcher])) |
@@ -14,7 +14,6 @@ |
||
| 14 | 14 | require __DIR__ . '/ConstantPatcher/Proxy.php'; |
| 15 | 15 | |
| 16 | 16 | use LogicException; |
| 17 | - |
|
| 18 | 17 | use Kenjis\MonkeyPatch\Patcher\ConstantPatcher\NodeVisitor; |
| 19 | 18 | |
| 20 | 19 | class ConstantPatcher extends AbstractPatcher |
@@ -15,7 +15,6 @@ |
||
| 15 | 15 | use PhpParser\Node\Name; |
| 16 | 16 | use PhpParser\Node\Name\FullyQualified; |
| 17 | 17 | use PhpParser\NodeVisitorAbstract; |
| 18 | - |
|
| 19 | 18 | use Kenjis\MonkeyPatch\Patcher\ConstantPatcher; |
| 20 | 19 | |
| 21 | 20 | class NodeVisitor extends NodeVisitorAbstract |
@@ -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,23 +47,23 @@ 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 | - if (! ConstantPatcher::isBlacklisted((string) $node->name)) |
|
| 60 | + if ( ! ConstantPatcher::isBlacklisted((string) $node->name)) |
|
| 61 | 61 | { |
| 62 | - $replacement = new FullyQualified('\__ConstProxy__::get(\'' . (string) $node->name . '\')'); |
|
| 62 | + $replacement = new FullyQualified('\__ConstProxy__::get(\''.(string) $node->name.'\')'); |
|
| 63 | 63 | |
| 64 | 64 | $pos = $node->getAttribute('startTokenPos'); |
| 65 | 65 | ConstantPatcher::$replacement[$pos] = |
| 66 | - '\__ConstProxy__::get(\'' . (string) $node->name .'\')'; |
|
| 66 | + '\__ConstProxy__::get(\''.(string) $node->name.'\')'; |
|
| 67 | 67 | |
| 68 | 68 | $node->name = $replacement; |
| 69 | 69 | } |
@@ -51,6 +51,9 @@ discard block |
||
| 51 | 51 | self::$patches_to_apply = []; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | + /** |
|
| 55 | + * @param string $constant |
|
| 56 | + */ |
|
| 54 | 57 | protected static function logInvocation($constant) |
| 55 | 58 | { |
| 56 | 59 | if (MonkeyPatchManager::$debug) |
@@ -68,6 +71,9 @@ discard block |
||
| 68 | 71 | } |
| 69 | 72 | } |
| 70 | 73 | |
| 74 | + /** |
|
| 75 | + * @param string $constant |
|
| 76 | + */ |
|
| 71 | 77 | protected static function checkCalledMethod($constant) |
| 72 | 78 | { |
| 73 | 79 | $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 | { |
@@ -84,6 +84,9 @@ discard block |
||
| 84 | 84 | $this->node_visitor = new NodeVisitor(); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | + /** |
|
| 88 | + * @param string $error_msg |
|
| 89 | + */ |
|
| 87 | 90 | protected static function checkLock($error_msg) |
| 88 | 91 | { |
| 89 | 92 | if (self::$lock_function_list) |
@@ -110,6 +113,9 @@ discard block |
||
| 110 | 113 | return self::$whitelist; |
| 111 | 114 | } |
| 112 | 115 | |
| 116 | + /** |
|
| 117 | + * @param string $function_name |
|
| 118 | + */ |
|
| 113 | 119 | public static function addBlacklist($function_name) |
| 114 | 120 | { |
| 115 | 121 | self::checkLock("You can't add to blacklist after initialization"); |
@@ -14,7 +14,6 @@ |
||
| 14 | 14 | require __DIR__ . '/FunctionPatcher/Proxy.php'; |
| 15 | 15 | |
| 16 | 16 | use LogicException; |
| 17 | - |
|
| 18 | 17 | use Kenjis\MonkeyPatch\Patcher\FunctionPatcher\NodeVisitor; |
| 19 | 18 | |
| 20 | 19 | class FunctionPatcher extends AbstractPatcher |