@@ -250,6 +250,9 @@ |
||
| 250 | 250 | return $this->createAndCallController($class, $method, $params); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | + /** |
|
| 254 | + * @param string $hook |
|
| 255 | + */ |
|
| 253 | 256 | protected function callHook($hook) |
| 254 | 257 | { |
| 255 | 258 | if ($this->enableHooks) |
@@ -129,8 +129,7 @@ discard block |
||
| 129 | 129 | return $this->callControllerMethod( |
| 130 | 130 | $http_method, $argv, $params |
| 131 | 131 | ); |
| 132 | - } |
|
| 133 | - else |
|
| 132 | + } else |
|
| 134 | 133 | { |
| 135 | 134 | return $this->requestUri($http_method, $argv, $params); |
| 136 | 135 | } |
@@ -141,8 +140,7 @@ discard block |
||
| 141 | 140 | if ($e->getCode() === 0) |
| 142 | 141 | { |
| 143 | 142 | set_status_header(200); |
| 144 | - } |
|
| 145 | - else |
|
| 143 | + } else |
|
| 146 | 144 | { |
| 147 | 145 | set_status_header($e->getCode()); |
| 148 | 146 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | public function enableHooks() |
| 96 | 96 | { |
| 97 | 97 | $this->enableHooks = true; |
| 98 | - $this->hooks =& load_class('Hooks', 'core'); |
|
| 98 | + $this->hooks = & load_class('Hooks', 'core'); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | { |
| 142 | 142 | set_status_header($e->getCode()); |
| 143 | 143 | } |
| 144 | - $CI =& get_instance(); |
|
| 144 | + $CI = & get_instance(); |
|
| 145 | 145 | $CI->output->_status['redirect'] = $e->getMessage(); |
| 146 | 146 | } |
| 147 | 147 | // show_404() |
@@ -197,17 +197,17 @@ discard block |
||
| 197 | 197 | $this->setRawInputStream($request_params); |
| 198 | 198 | |
| 199 | 199 | // 404 checking |
| 200 | - if (! class_exists($class) || ! method_exists($class, $method)) |
|
| 200 | + if ( ! class_exists($class) || ! method_exists($class, $method)) |
|
| 201 | 201 | { |
| 202 | 202 | // If 404, CodeIgniter instance is not created yet. So create it here |
| 203 | 203 | // Because we need CI->output->_status to store info |
| 204 | - $CI =& get_instance(); |
|
| 204 | + $CI = & get_instance(); |
|
| 205 | 205 | if ($CI === null) |
| 206 | 206 | { |
| 207 | 207 | new CI_Controller(); |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - show_404($class.'::'.$method . '() is not found'); |
|
| 210 | + show_404($class.'::'.$method.'() is not found'); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | $params = $argv; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | { |
| 267 | 267 | if (is_string($string)) |
| 268 | 268 | { |
| 269 | - $INPUT =& load_class('Input', 'core'); |
|
| 269 | + $INPUT = & load_class('Input', 'core'); |
|
| 270 | 270 | CIPHPUnitTestReflection::setPrivateProperty( |
| 271 | 271 | $INPUT, |
| 272 | 272 | '_raw_input_stream', |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | |
| 291 | 291 | // Create controller |
| 292 | 292 | $controller = new $class; |
| 293 | - $CI =& get_instance(); |
|
| 293 | + $CI = & get_instance(); |
|
| 294 | 294 | |
| 295 | 295 | // Set CodeIgniter instance to TestCase |
| 296 | 296 | $this->testCase->setCI($CI); |
@@ -330,8 +330,8 @@ discard block |
||
| 330 | 330 | */ |
| 331 | 331 | public function getStatus() |
| 332 | 332 | { |
| 333 | - $CI =& get_instance(); |
|
| 334 | - if (! isset($CI->output->_status)) |
|
| 333 | + $CI = & get_instance(); |
|
| 334 | + if ( ! isset($CI->output->_status)) |
|
| 335 | 335 | { |
| 336 | 336 | throw new LogicException('Status code is not set. You must call $this->request() first'); |
| 337 | 337 | } |
@@ -63,6 +63,9 @@ discard block |
||
| 63 | 63 | return self::$cache_dir; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | + /** |
|
| 67 | + * @param string $path |
|
| 68 | + */ |
|
| 66 | 69 | public static function getSrcCacheFilePath($path) |
| 67 | 70 | { |
| 68 | 71 | $len = strlen(self::$project_root); |
@@ -158,6 +161,9 @@ discard block |
||
| 158 | 161 | ); |
| 159 | 162 | } |
| 160 | 163 | |
| 164 | + /** |
|
| 165 | + * @param string $filename |
|
| 166 | + */ |
|
| 161 | 167 | protected static function writeTmpConfFile($filename, array $list) |
| 162 | 168 | { |
| 163 | 169 | $contents = implode("\n", $list); |
@@ -194,6 +200,9 @@ discard block |
||
| 194 | 200 | ); |
| 195 | 201 | } |
| 196 | 202 | |
| 203 | + /** |
|
| 204 | + * @param string $filename |
|
| 205 | + */ |
|
| 197 | 206 | protected static function getTmpConfFile($filename) |
| 198 | 207 | { |
| 199 | 208 | if (is_readable(self::$$filename)) |
@@ -45,17 +45,17 @@ discard block |
||
| 45 | 45 | throw new LogicException("No such directory: $dir"); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - self::$src_cache_dir = self::$cache_dir . '/src'; |
|
| 48 | + self::$src_cache_dir = self::$cache_dir.'/src'; |
|
| 49 | 49 | self::$tmp_function_whitelist_file = |
| 50 | - self::$cache_dir . '/conf/func_whiltelist.php'; |
|
| 50 | + self::$cache_dir.'/conf/func_whiltelist.php'; |
|
| 51 | 51 | self::$tmp_function_blacklist_file = |
| 52 | - self::$cache_dir . '/conf/func_blacklist.php'; |
|
| 52 | + self::$cache_dir.'/conf/func_blacklist.php'; |
|
| 53 | 53 | self::$tmp_patcher_list_file = |
| 54 | - self::$cache_dir . '/conf/patcher_list.php'; |
|
| 54 | + self::$cache_dir.'/conf/patcher_list.php'; |
|
| 55 | 55 | self::$tmp_include_paths_file = |
| 56 | - self::$cache_dir . '/conf/include_paths.php'; |
|
| 56 | + self::$cache_dir.'/conf/include_paths.php'; |
|
| 57 | 57 | self::$tmp_exclude_paths_file = |
| 58 | - self::$cache_dir . '/conf/exclude_paths.php'; |
|
| 58 | + self::$cache_dir.'/conf/exclude_paths.php'; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | public static function getCacheDir() |
@@ -73,16 +73,16 @@ discard block |
||
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return self::$src_cache_dir . '/' . $relative_path; |
|
| 76 | + return self::$src_cache_dir.'/'.$relative_path; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | protected static function createDir($dir) |
| 80 | 80 | { |
| 81 | - if (! is_dir($dir)) |
|
| 81 | + if ( ! is_dir($dir)) |
|
| 82 | 82 | { |
| 83 | - if (! @mkdir($dir, 0777, true)) |
|
| 83 | + if ( ! @mkdir($dir, 0777, true)) |
|
| 84 | 84 | { |
| 85 | - throw new RuntimeException('Failed to create folder: ' . $dir); |
|
| 85 | + throw new RuntimeException('Failed to create folder: '.$dir); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | public static function appendTmpFunctionBlacklist($function) |
| 155 | 155 | { |
| 156 | 156 | file_put_contents( |
| 157 | - self::getTmpFunctionBlacklistFile(), $function . "\n", FILE_APPEND |
|
| 157 | + self::getTmpFunctionBlacklistFile(), $function."\n", FILE_APPEND |
|
| 158 | 158 | ); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -234,20 +234,20 @@ discard block |
||
| 234 | 234 | { |
| 235 | 235 | $cache = self::getSrcCacheFilePath($orig_file); |
| 236 | 236 | @unlink($cache); |
| 237 | - MonkeyPatchManager::log('remove_src_cache: ' . $cache); |
|
| 237 | + MonkeyPatchManager::log('remove_src_cache: '.$cache); |
|
| 238 | 238 | return $cache; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | public static function clearSrcCache() |
| 242 | 242 | { |
| 243 | 243 | self::recursiveUnlink(self::$src_cache_dir); |
| 244 | - MonkeyPatchManager::log('clear_src_cache: cleared ' . self::$src_cache_dir); |
|
| 244 | + MonkeyPatchManager::log('clear_src_cache: cleared '.self::$src_cache_dir); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | public static function clearCache() |
| 248 | 248 | { |
| 249 | 249 | self::recursiveUnlink(self::$cache_dir); |
| 250 | - MonkeyPatchManager::log('clear_cache: cleared ' . self::$cache_dir); |
|
| 250 | + MonkeyPatchManager::log('clear_cache: cleared '.self::$cache_dir); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | protected static function recursiveUnlink($dir) |
| 259 | 259 | { |
| 260 | - if (! is_dir($dir)) |
|
| 260 | + if ( ! is_dir($dir)) |
|
| 261 | 261 | { |
| 262 | 262 | return; |
| 263 | 263 | } |
@@ -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 |
@@ -251,10 +251,10 @@ |
||
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
| 254 | - * Recursive Unlink |
|
| 255 | - * |
|
| 256 | - * @param string $dir |
|
| 257 | - */ |
|
| 254 | + * Recursive Unlink |
|
| 255 | + * |
|
| 256 | + * @param string $dir |
|
| 257 | + */ |
|
| 258 | 258 | protected static function recursiveUnlink($dir) |
| 259 | 259 | { |
| 260 | 260 | if (! is_dir($dir)) |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @param string $function function name |
| 23 | 23 | * @param mixed $return_value return value |
| 24 | - * @param string $class_name class::method to apply this patch |
|
| 24 | + * @param string $class_method class::method to apply this patch |
|
| 25 | 25 | */ |
| 26 | 26 | public static function patchFunction($function, $return_value, $class_method = null) |
| 27 | 27 | { |
@@ -55,6 +55,9 @@ discard block |
||
| 55 | 55 | PatchManager::clear(); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | + /** |
|
| 59 | + * @param string $class_method |
|
| 60 | + */ |
|
| 58 | 61 | protected static function getClassname($class_method) |
| 59 | 62 | { |
| 60 | 63 | if (strpos($class_method, '::') === false) |
@@ -38,8 +38,7 @@ |
||
| 38 | 38 | { |
| 39 | 39 | $patched = true; |
| 40 | 40 | $new_source = static::generateNewSource($source); |
| 41 | - } |
|
| 42 | - else |
|
| 41 | + } else |
|
| 43 | 42 | { |
| 44 | 43 | $new_source = $source; |
| 45 | 44 | } |
@@ -37,12 +37,12 @@ |
||
| 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); |
@@ -32,6 +32,9 @@ discard block |
||
| 32 | 32 | 'MethodPatcher', |
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | + /** |
|
| 36 | + * @param string $message |
|
| 37 | + */ |
|
| 35 | 38 | public static function log($message) |
| 36 | 39 | { |
| 37 | 40 | if (! self::$debug) |
@@ -276,6 +279,9 @@ discard block |
||
| 276 | 279 | self::$load_patchers = true; |
| 277 | 280 | } |
| 278 | 281 | |
| 282 | + /** |
|
| 283 | + * @param string $source |
|
| 284 | + */ |
|
| 279 | 285 | protected static function execPatchers($source) |
| 280 | 286 | { |
| 281 | 287 | $patched = false; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public static function log($message) |
| 36 | 36 | { |
| 37 | - if (! self::$debug) |
|
| 37 | + if ( ! self::$debug) |
|
| 38 | 38 | { |
| 39 | 39 | return; |
| 40 | 40 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | if (self::$debug) |
| 66 | 66 | { |
| 67 | - self::$log_file = __DIR__ . '/debug.log'; |
|
| 67 | + self::$log_file = __DIR__.'/debug.log'; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (isset($config['root_dir'])) |
@@ -74,16 +74,16 @@ discard block |
||
| 74 | 74 | else |
| 75 | 75 | { |
| 76 | 76 | // APPPATH is constant in CodeIgniter |
| 77 | - Cache::setProjectRootDir(APPPATH . '../'); |
|
| 77 | + Cache::setProjectRootDir(APPPATH.'../'); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if (! isset($config['cache_dir'])) |
|
| 80 | + if ( ! isset($config['cache_dir'])) |
|
| 81 | 81 | { |
| 82 | 82 | throw new LogicException('You have to set "cache_dir"'); |
| 83 | 83 | } |
| 84 | 84 | self::setCacheDir($config['cache_dir']); |
| 85 | 85 | |
| 86 | - if (! isset($config['include_paths'])) |
|
| 86 | + if ( ! isset($config['include_paths'])) |
|
| 87 | 87 | { |
| 88 | 88 | throw new LogicException('You have to set "include_paths"'); |
| 89 | 89 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | // Updated? |
| 132 | 132 | if ($cached !== $current) |
| 133 | 133 | { |
| 134 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 134 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 135 | 135 | Cache::clearSrcCache(); |
| 136 | 136 | Cache::writeTmpIncludePaths($current); |
| 137 | 137 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | // Updated? |
| 143 | 143 | if ($cached !== $current) |
| 144 | 144 | { |
| 145 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 145 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 146 | 146 | Cache::clearSrcCache(); |
| 147 | 147 | Cache::writeTmpExcludePaths($current); |
| 148 | 148 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | // Updated? |
| 156 | 156 | if ($cached !== self::$patcher_list) |
| 157 | 157 | { |
| 158 | - MonkeyPatchManager::log('clear_src_cache: from ' . __METHOD__); |
|
| 158 | + MonkeyPatchManager::log('clear_src_cache: from '.__METHOD__); |
|
| 159 | 159 | Cache::clearSrcCache(); |
| 160 | 160 | Cache::writeTmpPatcherList(self::$patcher_list); |
| 161 | 161 | } |
@@ -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::writeTmpFunctionWhitelist($current); |
| 175 | 175 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | public static function patch($path) |
| 233 | 233 | { |
| 234 | - if (! is_readable($path)) |
|
| 234 | + if ( ! is_readable($path)) |
|
| 235 | 235 | { |
| 236 | 236 | throw new LogicException("Can't read '$path'"); |
| 237 | 237 | } |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | // Check cache file |
| 240 | 240 | if ($cache_file = Cache::getValidSrcCachePath($path)) |
| 241 | 241 | { |
| 242 | - self::log('cache_hit: ' . $path); |
|
| 242 | + self::log('cache_hit: '.$path); |
|
| 243 | 243 | return fopen($cache_file, 'r'); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - self::log('cache_miss: ' . $path); |
|
| 246 | + self::log('cache_miss: '.$path); |
|
| 247 | 247 | $source = file_get_contents($path); |
| 248 | 248 | |
| 249 | 249 | list($new_source, $patched) = self::execPatchers($source); |
| 250 | 250 | |
| 251 | 251 | // Write to cache file |
| 252 | - self::log('write_cache: ' . $path); |
|
| 252 | + self::log('write_cache: '.$path); |
|
| 253 | 253 | Cache::writeSrcCacheFile($path, $new_source); |
| 254 | 254 | |
| 255 | 255 | $resource = fopen('php://memory', 'rb+'); |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | return; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - require __DIR__ . '/Patcher/AbstractPatcher.php'; |
|
| 269 | - require __DIR__ . '/Patcher/Backtrace.php'; |
|
| 268 | + require __DIR__.'/Patcher/AbstractPatcher.php'; |
|
| 269 | + require __DIR__.'/Patcher/Backtrace.php'; |
|
| 270 | 270 | |
| 271 | 271 | foreach (self::$patcher_list as $classname) |
| 272 | 272 | { |
| 273 | - require __DIR__ . '/Patcher/' . $classname . '.php'; |
|
| 273 | + require __DIR__.'/Patcher/'.$classname.'.php'; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | self::$load_patchers = true; |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | $patched = false; |
| 282 | 282 | foreach (self::$patcher_list as $classname) |
| 283 | 283 | { |
| 284 | - $classname = 'Kenjis\MonkeyPatch\Patcher\\' . $classname; |
|
| 284 | + $classname = 'Kenjis\MonkeyPatch\Patcher\\'.$classname; |
|
| 285 | 285 | $patcher = new $classname; |
| 286 | 286 | list($source, $patched_this) = $patcher->patch($source); |
| 287 | 287 | $patched = $patched || $patched_this; |
@@ -38,8 +38,7 @@ |
||
| 38 | 38 | { |
| 39 | 39 | $patched = true; |
| 40 | 40 | $new_source = static::generateNewSource($source); |
| 41 | - } |
|
| 42 | - else |
|
| 41 | + } else |
|
| 43 | 42 | { |
| 44 | 43 | $new_source = $source; |
| 45 | 44 | } |
@@ -11,7 +11,6 @@ |
||
| 11 | 11 | namespace Kenjis\MonkeyPatch; |
| 12 | 12 | |
| 13 | 13 | use LogicException; |
| 14 | -use RuntimeException; |
|
| 15 | 14 | use PhpParser\ParserFactory; |
| 16 | 15 | use Kenjis\MonkeyPatch\Patcher\FunctionPatcher; |
| 17 | 16 | |
@@ -21,15 +21,11 @@ |
||
| 21 | 21 | |
| 22 | 22 | namespace Kenjis\MonkeyPatch\Patcher\FunctionPatcher; |
| 23 | 23 | |
| 24 | -use ReflectionFunction; |
|
| 25 | -use ReflectionException; |
|
| 26 | - |
|
| 27 | 24 | use PhpParser\Node; |
| 28 | 25 | use PhpParser\Node\Expr\FuncCall; |
| 29 | 26 | use PhpParser\Node\Name; |
| 30 | 27 | use PhpParser\Node\Name\FullyQualified; |
| 31 | 28 | use PhpParser\NodeVisitorAbstract; |
| 32 | - |
|
| 33 | 29 | use Kenjis\MonkeyPatch\Patcher\FunctionPatcher; |
| 34 | 30 | |
| 35 | 31 | class NodeVisitor extends NodeVisitorAbstract |
@@ -36,17 +36,17 @@ discard block |
||
| 36 | 36 | { |
| 37 | 37 | public function leaveNode(Node $node) |
| 38 | 38 | { |
| 39 | - if (! ($node instanceof FuncCall)) |
|
| 39 | + if ( ! ($node instanceof FuncCall)) |
|
| 40 | 40 | { |
| 41 | 41 | return; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if (! ($node->name instanceof Name)) |
|
| 44 | + if ( ! ($node->name instanceof Name)) |
|
| 45 | 45 | { |
| 46 | 46 | return; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if (! $node->name->isUnqualified()) |
|
| 49 | + if ( ! $node->name->isUnqualified()) |
|
| 50 | 50 | { |
| 51 | 51 | return; |
| 52 | 52 | } |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | ) { |
| 58 | 58 | $replacement = new FullyQualified(array()); |
| 59 | 59 | $replacement->set( |
| 60 | - '\__FuncProxy__::' . (string) $node->name |
|
| 60 | + '\__FuncProxy__::'.(string) $node->name |
|
| 61 | 61 | ); |
| 62 | 62 | |
| 63 | 63 | $pos = $node->getAttribute('startTokenPos'); |
| 64 | 64 | FunctionPatcher::$replacement[$pos] = |
| 65 | - '\__FuncProxy__::' . (string) $node->name; |
|
| 65 | + '\__FuncProxy__::'.(string) $node->name; |
|
| 66 | 66 | |
| 67 | 67 | $node->name = $replacement; |
| 68 | 68 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @param string $function function name |
| 39 | 39 | * @param mixed $return_value return value or callable |
| 40 | - * @param string $class_name class::method to apply this patch |
|
| 40 | + * @param string $class_method class::method to apply this patch |
|
| 41 | 41 | * |
| 42 | 42 | * @throws LogicException |
| 43 | 43 | */ |
@@ -86,6 +86,9 @@ discard block |
||
| 86 | 86 | InvocationVerifier::verify(self::$expected_invocations, self::$invocations); |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | + /** |
|
| 90 | + * @param string $function |
|
| 91 | + */ |
|
| 89 | 92 | protected static function logInvocation($function, $arguments) |
| 90 | 93 | { |
| 91 | 94 | if (MonkeyPatchManager::$debug) |
@@ -111,6 +114,9 @@ discard block |
||
| 111 | 114 | } |
| 112 | 115 | } |
| 113 | 116 | |
| 117 | + /** |
|
| 118 | + * @param string $function |
|
| 119 | + */ |
|
| 114 | 120 | protected static function checkCalledMethod($function) |
| 115 | 121 | { |
| 116 | 122 | $trace = debug_backtrace(); |
@@ -184,6 +190,9 @@ discard block |
||
| 184 | 190 | return call_user_func_array($function, $arguments); |
| 185 | 191 | } |
| 186 | 192 | |
| 193 | + /** |
|
| 194 | + * @param string $function |
|
| 195 | + */ |
|
| 187 | 196 | protected static function checkPassedByReference($function) |
| 188 | 197 | { |
| 189 | 198 | $ref_func = new ReflectionFunction($function); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | self::outputMessage($msg); |
| 52 | 52 | throw new LogicException($msg); |
| 53 | 53 | } |
| 54 | - if (! FunctionPatcher::isWhitelisted($function)) |
|
| 54 | + if ( ! FunctionPatcher::isWhitelisted($function)) |
|
| 55 | 55 | { |
| 56 | 56 | $msg = "<red>Can't patch on '$function'. It is not in whitelist. If you want to patch it, please add it to 'functions_to_patch' in 'tests/Bootstrap.php'. But note that there are some limitations. See <https://github.com/kenjis/ci-phpunit-test/blob/master/docs/HowToWriteTests.md#patching-functions> for details.</red>"; |
| 57 | 57 | self::outputMessage($msg); |
@@ -97,16 +97,16 @@ discard block |
||
| 97 | 97 | $line = $info['line']; |
| 98 | 98 | $method = isset($info['class_method']) ? $info['class_method'] : $info['function']; |
| 99 | 99 | |
| 100 | - $log_args = function () use ($arguments) { |
|
| 100 | + $log_args = function() use ($arguments) { |
|
| 101 | 101 | $output = ''; |
| 102 | 102 | foreach ($arguments as $arg) { |
| 103 | - $output .= var_export($arg, true) . ', '; |
|
| 103 | + $output .= var_export($arg, true).', '; |
|
| 104 | 104 | } |
| 105 | 105 | $output = rtrim($output, ', '); |
| 106 | 106 | return $output; |
| 107 | 107 | }; |
| 108 | 108 | MonkeyPatchManager::log( |
| 109 | - 'invoke_func: ' . $function . '(' . $log_args() . ') on line ' . $line . ' in ' . $file . ' by ' . $method . '()' |
|
| 109 | + 'invoke_func: '.$function.'('.$log_args().') on line '.$line.' in '.$file.' by '.$method.'()' |
|
| 110 | 110 | ); |
| 111 | 111 | } |
| 112 | 112 | } |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | if (isset(self::$patches_to_apply[$function])) |
| 150 | 150 | { |
| 151 | - if (! self::checkCalledMethod($function)) |
|
| 151 | + if ( ! self::checkCalledMethod($function)) |
|
| 152 | 152 | { |
| 153 | 153 | MonkeyPatchManager::log( |
| 154 | - 'invoke_func: ' . $function . '() not patched (out of scope)' |
|
| 154 | + 'invoke_func: '.$function.'() not patched (out of scope)' |
|
| 155 | 155 | ); |
| 156 | 156 | self::checkPassedByReference($function); |
| 157 | 157 | return call_user_func_array($function, $arguments); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | if (array_key_exists($function, self::$patches)) |
| 162 | 162 | { |
| 163 | - MonkeyPatchManager::log('invoke_func: ' . $function . '() patched'); |
|
| 163 | + MonkeyPatchManager::log('invoke_func: '.$function.'() patched'); |
|
| 164 | 164 | |
| 165 | 165 | if (is_callable(self::$patches[$function])) |
| 166 | 166 | { |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | MonkeyPatchManager::log( |
| 181 | - 'invoke_func: ' . $function . '() not patched (no patch)' |
|
| 181 | + 'invoke_func: '.$function.'() not patched (no patch)' |
|
| 182 | 182 | ); |
| 183 | 183 | self::checkPassedByReference($function); |
| 184 | 184 | return call_user_func_array($function, $arguments); |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | $msg = str_replace( |
| 232 | 232 | ['<red>', '</red>'], [$red_begin, $red_end], $msg |
| 233 | 233 | ); |
| 234 | - echo $msg . "\n"; |
|
| 234 | + echo $msg."\n"; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -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 |
@@ -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 |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | { |
| 21 | 21 | public function leaveNode(Node $node) |
| 22 | 22 | { |
| 23 | - if (! ($node instanceof ClassMethod)) |
|
| 23 | + if ( ! ($node instanceof ClassMethod)) |
|
| 24 | 24 | { |
| 25 | 25 | return; |
| 26 | 26 | } |
@@ -136,6 +136,11 @@ discard block |
||
| 136 | 136 | return $_is_loaded; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | +/** |
|
| 140 | + * @param boolean $return |
|
| 141 | + * |
|
| 142 | + * @return boolean |
|
| 143 | + */ |
|
| 139 | 144 | function is_cli($return = null) |
| 140 | 145 | { |
| 141 | 146 | static $_return = TRUE; |
@@ -148,6 +153,9 @@ discard block |
||
| 148 | 153 | return $_return; |
| 149 | 154 | } |
| 150 | 155 | |
| 156 | +/** |
|
| 157 | + * @param string $message |
|
| 158 | + */ |
|
| 151 | 159 | function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered') |
| 152 | 160 | { |
| 153 | 161 | $status_code = abs($status_code); |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | // Save status code in Output object |
| 265 | 265 | // added by ci-phpunit-test |
| 266 | - $CI =& get_instance(); |
|
| 266 | + $CI = & get_instance(); |
|
| 267 | 267 | $output = $CI->output; |
| 268 | 268 | $output->_status = [ |
| 269 | 269 | 'code' => $code, |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | if (empty($_config)) |
| 377 | 377 | { |
| 378 | 378 | // references cannot be directly assigned to static variables, so we use an array |
| 379 | - $_config[0] =& get_config(); |
|
| 379 | + $_config[0] = & get_config(); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | return isset($_config[0][$item]) ? $_config[0][$item] : NULL; |
@@ -158,14 +158,16 @@ discard block |
||
| 158 | 158 | if ($status_code < 100) |
| 159 | 159 | { |
| 160 | 160 | $exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN |
| 161 | - if ($exit_status > 125) // 125 is EXIT__AUTO_MAX |
|
| 161 | + if ($exit_status > 125) { |
|
| 162 | + // 125 is EXIT__AUTO_MAX |
|
| 162 | 163 | { |
| 163 | - $exit_status = 1; // EXIT_ERROR |
|
| 164 | + $exit_status = 1; |
|
| 165 | + } |
|
| 166 | + // EXIT_ERROR |
|
| 164 | 167 | } |
| 165 | 168 | |
| 166 | 169 | $status_code = 500; |
| 167 | - } |
|
| 168 | - else |
|
| 170 | + } else |
|
| 169 | 171 | { |
| 170 | 172 | $exit_status = 1; // EXIT_ERROR |
| 171 | 173 | } |
@@ -254,8 +256,7 @@ discard block |
||
| 254 | 256 | if (isset($stati[$code])) |
| 255 | 257 | { |
| 256 | 258 | $text = $stati[$code]; |
| 257 | - } |
|
| 258 | - else |
|
| 259 | + } else |
|
| 259 | 260 | { |
| 260 | 261 | show_error('No status text available. Please check your status code number or supply your own message text.', 500); |
| 261 | 262 | } |
@@ -281,8 +282,7 @@ discard block |
||
| 281 | 282 | if (strpos(PHP_SAPI, 'cgi') === 0) |
| 282 | 283 | { |
| 283 | 284 | header('Status: '.$code.' '.$text, TRUE); |
| 284 | - } |
|
| 285 | - else |
|
| 285 | + } else |
|
| 286 | 286 | { |
| 287 | 287 | $server_protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; |
| 288 | 288 | header($server_protocol.' '.$code.' '.$text, TRUE, $code); |
@@ -325,8 +325,7 @@ discard block |
||
| 325 | 325 | if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php')) |
| 326 | 326 | { |
| 327 | 327 | require($file_path); |
| 328 | - } |
|
| 329 | - elseif ( ! $found) |
|
| 328 | + } elseif ( ! $found) |
|
| 330 | 329 | { |
| 331 | 330 | set_status_header(503); |
| 332 | 331 | echo 'The configuration file does not exist.'; |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * NOTE: If you change these, also change the error_reporting() code below |
| 55 | 55 | */ |
| 56 | 56 | // This is needed for @runInSeparateProcess |
| 57 | -if (! defined('ENVIRONMENT')) |
|
| 57 | +if ( ! defined('ENVIRONMENT')) |
|
| 58 | 58 | { |
| 59 | 59 | define('ENVIRONMENT', 'testing'); |
| 60 | 60 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | * Added for CI PHPUnit Test |
| 328 | 328 | * ------------------------------------------------------------------- |
| 329 | 329 | */ |
| 330 | -require __DIR__ . '/_ci_phpunit_test/CIPHPUnitTest.php'; |
|
| 330 | +require __DIR__.'/_ci_phpunit_test/CIPHPUnitTest.php'; |
|
| 331 | 331 | CIPHPUnitTest::init(); |
| 332 | 332 | /* |
| 333 | 333 | * Or you can set directories for autoloading |
@@ -69,28 +69,28 @@ |
||
| 69 | 69 | */ |
| 70 | 70 | switch (ENVIRONMENT) |
| 71 | 71 | { |
| 72 | - case 'testing': |
|
| 73 | - case 'development': |
|
| 74 | - error_reporting(-1); |
|
| 75 | - ini_set('display_errors', 1); |
|
| 76 | - break; |
|
| 72 | + case 'testing': |
|
| 73 | + case 'development': |
|
| 74 | + error_reporting(-1); |
|
| 75 | + ini_set('display_errors', 1); |
|
| 76 | + break; |
|
| 77 | 77 | |
| 78 | - case 'production': |
|
| 79 | - ini_set('display_errors', 0); |
|
| 80 | - if (version_compare(PHP_VERSION, '5.3', '>=')) |
|
| 81 | - { |
|
| 82 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 83 | - } |
|
| 84 | - else |
|
| 85 | - { |
|
| 86 | - error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 87 | - } |
|
| 88 | - break; |
|
| 78 | + case 'production': |
|
| 79 | + ini_set('display_errors', 0); |
|
| 80 | + if (version_compare(PHP_VERSION, '5.3', '>=')) |
|
| 81 | + { |
|
| 82 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + { |
|
| 86 | + error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
|
| 87 | + } |
|
| 88 | + break; |
|
| 89 | 89 | |
| 90 | - default: |
|
| 91 | - header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 92 | - echo 'The application environment is not set correctly.'; |
|
| 93 | - exit(1); // EXIT_ERROR |
|
| 90 | + default: |
|
| 91 | + header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
|
| 92 | + echo 'The application environment is not set correctly.'; |
|
| 93 | + exit(1); // EXIT_ERROR |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /* |
@@ -80,8 +80,7 @@ discard block |
||
| 80 | 80 | if (version_compare(PHP_VERSION, '5.3', '>=')) |
| 81 | 81 | { |
| 82 | 82 | error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED); |
| 83 | - } |
|
| 84 | - else |
|
| 83 | + } else |
|
| 85 | 84 | { |
| 86 | 85 | error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE); |
| 87 | 86 | } |
@@ -204,8 +203,7 @@ discard block |
||
| 204 | 203 | if (($_temp = realpath($system_path)) !== FALSE) |
| 205 | 204 | { |
| 206 | 205 | $system_path = $_temp.DIRECTORY_SEPARATOR; |
| 207 | - } |
|
| 208 | - else |
|
| 206 | + } else |
|
| 209 | 207 | { |
| 210 | 208 | // Ensure there's a trailing slash |
| 211 | 209 | $system_path = strtr( |
@@ -247,8 +245,7 @@ discard block |
||
| 247 | 245 | if (($_temp = realpath($application_folder)) !== FALSE) |
| 248 | 246 | { |
| 249 | 247 | $application_folder = $_temp; |
| 250 | - } |
|
| 251 | - else |
|
| 248 | + } else |
|
| 252 | 249 | { |
| 253 | 250 | $application_folder = strtr( |
| 254 | 251 | rtrim($application_folder, '/\\'), |
@@ -256,16 +253,14 @@ discard block |
||
| 256 | 253 | DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR |
| 257 | 254 | ); |
| 258 | 255 | } |
| 259 | - } |
|
| 260 | - elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR)) |
|
| 256 | + } elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR)) |
|
| 261 | 257 | { |
| 262 | 258 | $application_folder = BASEPATH.strtr( |
| 263 | 259 | trim($application_folder, '/\\'), |
| 264 | 260 | '/\\', |
| 265 | 261 | DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR |
| 266 | 262 | ); |
| 267 | - } |
|
| 268 | - else |
|
| 263 | + } else |
|
| 269 | 264 | { |
| 270 | 265 | header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
| 271 | 266 | echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF; |
@@ -278,14 +273,12 @@ discard block |
||
| 278 | 273 | if ( ! isset($view_folder[0]) && is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR)) |
| 279 | 274 | { |
| 280 | 275 | $view_folder = APPPATH.'views'; |
| 281 | - } |
|
| 282 | - elseif (is_dir($view_folder)) |
|
| 276 | + } elseif (is_dir($view_folder)) |
|
| 283 | 277 | { |
| 284 | 278 | if (($_temp = realpath($view_folder)) !== FALSE) |
| 285 | 279 | { |
| 286 | 280 | $view_folder = $_temp; |
| 287 | - } |
|
| 288 | - else |
|
| 281 | + } else |
|
| 289 | 282 | { |
| 290 | 283 | $view_folder = strtr( |
| 291 | 284 | rtrim($view_folder, '/\\'), |
@@ -293,16 +286,14 @@ discard block |
||
| 293 | 286 | DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR |
| 294 | 287 | ); |
| 295 | 288 | } |
| 296 | - } |
|
| 297 | - elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR)) |
|
| 289 | + } elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR)) |
|
| 298 | 290 | { |
| 299 | 291 | $view_folder = APPPATH.strtr( |
| 300 | 292 | trim($view_folder, '/\\'), |
| 301 | 293 | '/\\', |
| 302 | 294 | DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR |
| 303 | 295 | ); |
| 304 | - } |
|
| 305 | - else |
|
| 296 | + } else |
|
| 306 | 297 | { |
| 307 | 298 | header('HTTP/1.1 503 Service Unavailable.', TRUE, 503); |
| 308 | 299 | echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF; |