diff --git a/src/Core/App.php b/src/Core/App.php index a39581d9e02..180ad9bf210 100644 --- a/src/Core/App.php +++ b/src/Core/App.php @@ -59,13 +59,8 @@ public static function className($class, $type = '', $suffix = '') } list($plugin, $name) = pluginSplit($class); - if ($plugin) { - $base = $plugin; - } else { - $base = Configure::read('App.namespace'); - } + $base = $plugin ?: Configure::read('App.namespace'); $base = str_replace('/', '\\', rtrim($base, '\\')); - $fullname = '\\' . str_replace('/', '\\', $type . '\\' . $name) . $suffix; if (static::_classExistsInBase($fullname, $base)) { diff --git a/src/Core/Configure.php b/src/Core/Configure.php index 0a58cfc8187..dd7993c19fd 100644 --- a/src/Core/Configure.php +++ b/src/Core/Configure.php @@ -166,11 +166,10 @@ public static function delete($var) */ public static function consume($var) { - $simple = strpos($var, '.') === false; - if ($simple && !isset(static::$_values[$var])) { - return null; - } - if ($simple) { + if (strpos($var, '.') === false) { + if (!isset(static::$_values[$var])) { + return null; + } $value = static::$_values[$var]; unset(static::$_values[$var]); return $value; diff --git a/src/Core/InstanceConfigTrait.php b/src/Core/InstanceConfigTrait.php index bbd34f6de46..8c3bd4b82d1 100644 --- a/src/Core/InstanceConfigTrait.php +++ b/src/Core/InstanceConfigTrait.php @@ -144,7 +144,6 @@ protected function _configRead($key) } $return = $return[$k]; - } return $return; @@ -168,11 +167,7 @@ protected function _configWrite($key, $value, $merge = false) } if ($merge) { - if (is_array($key)) { - $update = $key; - } else { - $update = [$key => $value]; - } + $update = is_array($key) ? $key : [$key => $value]; if ($merge === 'shallow') { $this->_config = array_merge($this->_config, Hash::expand($update)); } else { diff --git a/src/Core/Plugin.php b/src/Core/Plugin.php index 9a7897605a5..1916470bcca 100644 --- a/src/Core/Plugin.php +++ b/src/Core/Plugin.php @@ -136,8 +136,8 @@ public static function load($plugin, array $config = []) if (empty($config['path'])) { $paths = App::path('Plugin'); + $pluginPath = str_replace('/', DS, $plugin); foreach ($paths as $path) { - $pluginPath = str_replace('/', DS, $plugin); if (is_dir($path . $pluginPath)) { $config['path'] = $path . $pluginPath . DS; break; diff --git a/src/Core/StaticConfigTrait.php b/src/Core/StaticConfigTrait.php index 443f9484b4d..3306b6f379d 100644 --- a/src/Core/StaticConfigTrait.php +++ b/src/Core/StaticConfigTrait.php @@ -72,15 +72,18 @@ trait StaticConfigTrait */ public static function config($key, $config = null) { - // Read config. - if ($config === null && is_string($key)) { - return isset(static::$_config[$key]) ? static::$_config[$key] : null; - } - if ($config === null && is_array($key)) { - foreach ($key as $name => $settings) { - static::config($name, $settings); + if ($config === null) { + // Read config. + if (is_string($key)) { + return isset(static::$_config[$key]) ? static::$_config[$key] : null; + } + + if (is_array($key)) { + foreach ($key as $name => $settings) { + static::config($name, $settings); + } + return; } - return; } if (isset(static::$_config[$key])) { diff --git a/src/Core/functions.php b/src/Core/functions.php index 313c3d0489f..30cecfba109 100644 --- a/src/Core/functions.php +++ b/src/Core/functions.php @@ -131,10 +131,12 @@ function namespaceSplit($class) */ function pr($var) { - if (Configure::read('debug')) { - $template = PHP_SAPI !== 'cli' ? '
%s
' : "\n%s\n\n"; - printf($template, trim(print_r($var, true))); + if (!Configure::read('debug')) { + return; } + + $template = PHP_SAPI !== 'cli' ? '
%s
' : "\n%s\n\n"; + printf($template, trim(print_r($var, true))); } } @@ -156,11 +158,9 @@ function pj($var) if (!Configure::read('debug')) { return; } - if (PHP_SAPI === 'cli') { - printf("\n%s\n\n", trim(json_encode($var, JSON_PRETTY_PRINT))); - } elseif (Configure::read('debug')) { - printf('
%s
', trim(json_encode($var, JSON_PRETTY_PRINT))); - } + + $template = PHP_SAPI !== 'cli' ? '
%s
' : "\n%s\n\n"; + printf($template, trim(json_encode($var, JSON_PRETTY_PRINT))); } }