diff --git a/src/Command/BakeMigrationDiffCommand.php b/src/Command/BakeMigrationDiffCommand.php index 3742566..6354951 100644 --- a/src/Command/BakeMigrationDiffCommand.php +++ b/src/Command/BakeMigrationDiffCommand.php @@ -453,7 +453,7 @@ protected function checkSync() $lastVersion = $this->migratedItems[0]['version']; $lastFile = end($this->migrationsFiles); - return (bool)strpos($lastFile, (string)$lastVersion); + return (bool)strpos((string) $lastFile, (string)$lastVersion); } return false; @@ -555,7 +555,7 @@ protected function getCurrentSchema() } $collection = $connection->getSchemaCollection(); foreach ($this->tables as $table) { - if (preg_match('/^.*phinxlog$/', $table) === 1) { + if (preg_match('/^.*phinxlog$/', (string) $table) === 1) { continue; } @@ -580,7 +580,7 @@ public function template(): string */ public function getOptionParser(): ConsoleOptionParser { - $parser = parent::getOptionParser(); + $parser = null; $parser->addArgument('name', [ 'help' => 'Name of the migration to bake. Can use Plugin.name to bake migration files into plugins.', diff --git a/src/Controller/Component/RefererComponent.php b/src/Controller/Component/RefererComponent.php index 4bc6c02..b7d0b36 100644 --- a/src/Controller/Component/RefererComponent.php +++ b/src/Controller/Component/RefererComponent.php @@ -152,7 +152,7 @@ public function normalizeUrl($url = null): ?string * @param int $status http status code, default is null * @return \Cake\Http\Response|null */ - public function redirect($url, int $status = 302): ?Response + public function redirect(mixed $url, int $status = 302): ?Response { $referer = $this->getReferer(); @@ -160,7 +160,7 @@ public function redirect($url, int $status = 302): ?Response $referer = null; } - if (strlen($referer) == 0 || $referer == '/') { + if (strlen((string) $referer) == 0 || $referer == '/') { return $this->getController()->redirect($url, $status); } else { return $this->getController()->redirect($referer, $status); diff --git a/src/Controller/Controller.php b/src/Controller/Controller.php index 8aa1f2c..32febc7 100644 --- a/src/Controller/Controller.php +++ b/src/Controller/Controller.php @@ -117,7 +117,7 @@ public function paginate($object = null, array $settings = []) try { return $this->Paginator->paginate($table, $settings); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $request = $this->getRequest(); $queryString = $request->getQueryParams(); if (isset($queryString['page'])) { diff --git a/src/Database/Type/JsonArrayType.php b/src/Database/Type/JsonArrayType.php index 07b1db3..b08667d 100644 --- a/src/Database/Type/JsonArrayType.php +++ b/src/Database/Type/JsonArrayType.php @@ -44,7 +44,7 @@ public function manyToPHP(array $values, array $fields, DriverInterface $driver) continue; } - $values[$field] = json_decode($values[$field], false); + $values[$field] = json_decode((string) $values[$field], false); } return $values; diff --git a/src/Filesystem/FileApi.php b/src/Filesystem/FileApi.php index e31d7e8..aad95e2 100644 --- a/src/Filesystem/FileApi.php +++ b/src/Filesystem/FileApi.php @@ -192,7 +192,7 @@ public static function put($tmpFilePath, array $metaData = []) $file->meta = $metaData['meta']; } /** @var array $pathInfo */ - $pathInfo = pathinfo($metaData['original_filename']); + $pathInfo = pathinfo((string) $metaData['original_filename']); $file->filename = Text::uuid() . isset($pathInfo['extension']) ? '.' . $pathInfo['extension'] : null; $folder = new Folder(Configure::read('FileApi.basePath') . $file->category . DS . $file->tag, true, 0755); @@ -243,7 +243,7 @@ public static function resize(string $id, array $options = []) // Get additional image data try { $imageInfo = getimagesize($file->path); - } catch (Exception $e) { + } catch (Exception) { $imageInfo = []; } diff --git a/src/Message/StatusMessage.php b/src/Message/StatusMessage.php index a55c15c..f76fef0 100644 --- a/src/Message/StatusMessage.php +++ b/src/Message/StatusMessage.php @@ -159,6 +159,6 @@ public static function toString(string $key) $message = static::$_messages[$key]['responseText'] ?? ''; $type = static::$_messages[$key]['type'] ?? 'notice'; - return trim($message . ' ' . strtoupper($type) . ': ' . $code); + return trim($message . ' ' . strtoupper((string) $type) . ': ' . $code); } } diff --git a/src/Model/Entity/File.php b/src/Model/Entity/File.php index c112e5b..fe92268 100644 --- a/src/Model/Entity/File.php +++ b/src/Model/Entity/File.php @@ -63,6 +63,6 @@ protected function _getBase64() $contents = ''; } - return 'data:' . $file->mime() . ';base64,' . base64_encode($contents); + return 'data:' . $file->mime() . ';base64,' . base64_encode((string) $contents); } } diff --git a/src/Plugin.php b/src/Plugin.php index 6660b6d..167ca79 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -125,7 +125,7 @@ protected function findInPath(string $namespace, string $path): array try { $reflection = new ReflectionClass($class); - } catch (ReflectionException $e) { + } catch (ReflectionException) { continue; } if (!$reflection->isInstantiable() || !$reflection->isSubclassOf(BakeCommand::class)) { @@ -134,7 +134,7 @@ protected function findInPath(string $namespace, string $path): array // Trim off 'Command' from the name. [$ns, $className] = namespaceSplit($class); - $name = Inflector::underscore(substr($className, 0, -7)); + $name = Inflector::underscore(substr((string) $className, 0, -7)); $shortName = $class::defaultName(); @@ -142,7 +142,7 @@ protected function findInPath(string $namespace, string $path): array $candidates[$shortName] = $class; } else { // Commands ending with `_all` should be ` all` instead. - if (substr($name, -4) === '_all') { + if (str_ends_with($name, '_all')) { $name = substr($name, 0, -4) . ' all'; } $candidates["bake {$name}"] = $class; diff --git a/src/Routing/Middleware/SessionTimeoutMiddleware.php b/src/Routing/Middleware/SessionTimeoutMiddleware.php index 13d1ac7..4e21e6b 100644 --- a/src/Routing/Middleware/SessionTimeoutMiddleware.php +++ b/src/Routing/Middleware/SessionTimeoutMiddleware.php @@ -52,7 +52,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface } /** @var \Cake\Http\ServerRequest $request */ - if ((!$request->is('ajax') || ($request->getQuery('session_timeout') && strtolower($request->getQuery('session_timeout')) === 'extend')) && $request->getParam('plugin') !== 'DebugKit') { + if ((!$request->is('ajax') || ($request->getQuery('session_timeout') && strtolower((string) $request->getQuery('session_timeout')) === 'extend')) && $request->getParam('plugin') !== 'DebugKit') { $session->write('SessionTimeoutFilter.lastAccess', time()); } diff --git a/src/Utility/Format.php b/src/Utility/Format.php index 1736288..c9042b7 100644 --- a/src/Utility/Format.php +++ b/src/Utility/Format.php @@ -59,7 +59,7 @@ public static function phone(string $phone, array $formats = [], string $extForm ]; $phone = self::parsePhone($phone, true); - $format = !empty($formats[strlen($phone['string'])]) ? $formats[strlen($phone['string'])] : ''; + $format = !empty($formats[strlen((string) $phone['string'])]) ? $formats[strlen((string) $phone['string'])] : ''; $formattedPhone = self::formatString($phone['string'], $format); if (!empty($phone['parts']['ext'])) { @@ -160,7 +160,7 @@ public static function maskString(string $string = '', string $format = '', stri $spos++; } else { $result .= substr($format, $fpos, 1); - if (strpos($ignore, substr($format, $fpos, 1)) === false) { + if (!str_contains($ignore, substr($format, $fpos, 1))) { ++$spos; } } diff --git a/src/Utility/Muddle.php b/src/Utility/Muddle.php index e49b802..b4cf76b 100644 --- a/src/Utility/Muddle.php +++ b/src/Utility/Muddle.php @@ -17,7 +17,7 @@ class Muddle * @param string $separator The separator character * @return bool True/False did the value get inserted */ - public static function insert(array &$array, $path, $value, string $separator = '.'): bool + public static function insert(array &$array, $path, mixed $value, string $separator = '.'): bool { if (!is_array($path)) { $path = explode($separator, $path); diff --git a/src/View/Helper/FormHelper.php b/src/View/Helper/FormHelper.php index 78a62d7..ae90099 100644 --- a/src/View/Helper/FormHelper.php +++ b/src/View/Helper/FormHelper.php @@ -73,7 +73,7 @@ public function postLink(string $title, $url = null, array $options = []): strin $requestMethod = 'POST'; if (!empty($options['method'])) { - $requestMethod = strtoupper($options['method']); + $requestMethod = strtoupper((string) $options['method']); unset($options['method']); } diff --git a/src/View/Helper/TableHelper.php b/src/View/Helper/TableHelper.php index 9ea242d..da9cd1d 100644 --- a/src/View/Helper/TableHelper.php +++ b/src/View/Helper/TableHelper.php @@ -68,7 +68,7 @@ public function header(string $key, $title = null, array $options = []): string $keyArr = explode('.', $key); // As Model names are now required for all fields, remove the base model from the title $title = array_pop($keyArr); - if (strpos($title, '.') !== false) { + if (str_contains($title, '.')) { $title = str_replace('.', ' ', $title); } diff --git a/templates/element/paginate.php b/templates/element/paginate.php index d937da7..a7466b7 100644 --- a/templates/element/paginate.php +++ b/templates/element/paginate.php @@ -24,7 +24,7 @@ 'data-url' => Cake\Routing\Router::url(['?' => $this->getRequest()->getQuery()]), 'data-update' => $this->fetch('ajax_update_element'), 'options' => !empty($paginatorOptions['limit']['options']) && is_array($paginatorOptions['limit']['options']) ? $paginatorOptions['limit']['options'] : [20 => 20, 40 => 40, 60 => 60, 80 => 80, 100 => 100], - 'default' => $this->getRequest()->getQuery('limit') ? $this->getRequest()->getQuery('limit') : $paginatorOptions['limit']['default'] ?? 20, + 'default' => $this->getRequest()->getQuery('limit') ?: $paginatorOptions['limit']['default'] ?? 20, 'templates' => [ 'select' => '', 'inputContainer' => 'Show: {{content}}', diff --git a/templates/layout/error.php b/templates/layout/error.php index ac1089e..4a027cd 100644 --- a/templates/layout/error.php +++ b/templates/layout/error.php @@ -184,7 +184,7 @@ function each(els, cb) { = h($this->fetch('title')) ?>