From 2220f35b1b048fd0e79e2893ab853d5b472e1507 Mon Sep 17 00:00:00 2001 From: Markus Bauer Date: Wed, 24 Jul 2024 21:55:01 +0200 Subject: [PATCH] Remove constructs that deprecate with PHP 8.4 (#75) * Remove constructs that deprecate with PHP 8.4 * Fix SecurityComponent typing --------- Co-authored-by: Markus Bauer --- lib/Cake/Console/Command/Task/FixtureTask.php | 2 +- lib/Cake/Console/Command/Task/ModelTask.php | 4 ++-- .../Controller/Component/Auth/BaseAuthorize.php | 2 +- .../Component/Auth/ControllerAuthorize.php | 2 +- lib/Cake/Controller/Component/AuthComponent.php | 2 +- .../Controller/Component/SecurityComponent.php | 4 ++-- lib/Cake/Error/exceptions.php | 2 +- lib/Cake/Model/Datasource/DboSource.php | 14 +++++++------- lib/Cake/Model/Model.php | 2 +- lib/Cake/Test/Case/Console/ShellTest.php | 2 +- lib/Cake/View/JsonView.php | 2 +- lib/Cake/View/View.php | 2 +- lib/Cake/View/XmlView.php | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/Cake/Console/Command/Task/FixtureTask.php b/lib/Cake/Console/Command/Task/FixtureTask.php index 7b2ee52e7..70a55ed6e 100644 --- a/lib/Cake/Console/Command/Task/FixtureTask.php +++ b/lib/Cake/Console/Command/Task/FixtureTask.php @@ -248,7 +248,7 @@ class FixtureTask extends BakeTask { $this->_Schema = new CakeSchema(); $data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection)); if (!isset($data['tables'][$useTable])) { - $this->err("Warning: Could not find the '${useTable}' table for ${model}."); + $this->err("Warning: Could not find the '{$useTable}' table for {$model}."); return null; } diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index f70cf656d..3473e3f41 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -170,7 +170,7 @@ class ModelTask extends BakeTask { while (!$valid) { $len = strlen(count($options) + 1); foreach ($options as $i => $option) { - $this->out(sprintf("%${len}d. %s", $i + 1, $option)); + $this->out(sprintf("%{$len}d. %s", $i + 1, $option)); } if (empty($prompt)) { $prompt = __d('cake_console', 'Make a selection from the choices above'); @@ -901,7 +901,7 @@ class ModelTask extends BakeTask { $this->out(__d('cake_console', 'Possible Models based on your current database:')); $len = strlen($count + 1); for ($i = 0; $i < $count; $i++) { - $this->out(sprintf("%${len}d. %s", $i + 1, $this->_modelNames[$i])); + $this->out(sprintf("%{$len}d. %s", $i + 1, $this->_modelNames[$i])); } } return $this->_tables; diff --git a/lib/Cake/Controller/Component/Auth/BaseAuthorize.php b/lib/Cake/Controller/Component/Auth/BaseAuthorize.php index 1e6a0d688..feefb88c2 100644 --- a/lib/Cake/Controller/Component/Auth/BaseAuthorize.php +++ b/lib/Cake/Controller/Component/Auth/BaseAuthorize.php @@ -89,7 +89,7 @@ abstract class BaseAuthorize { * @return mixed * @throws CakeException */ - public function controller(Controller $controller = null) { + public function controller(?Controller $controller = null) { if ($controller) { if (!$controller instanceof Controller) { throw new CakeException(__d('cake_dev', '$controller needs to be an instance of Controller')); diff --git a/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php b/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php index c55ef3d3e..62b306506 100644 --- a/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php +++ b/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php @@ -43,7 +43,7 @@ class ControllerAuthorize extends BaseAuthorize { * @return mixed * @throws CakeException */ - public function controller(Controller $controller = null) { + public function controller(?Controller $controller = null) { if ($controller) { if (!method_exists($controller, 'isAuthorized')) { throw new CakeException(__d('cake_dev', '$controller does not implement an %s method.', 'isAuthorized()')); diff --git a/lib/Cake/Controller/Component/AuthComponent.php b/lib/Cake/Controller/Component/AuthComponent.php index a652e950a..f21ac5cac 100644 --- a/lib/Cake/Controller/Component/AuthComponent.php +++ b/lib/Cake/Controller/Component/AuthComponent.php @@ -453,7 +453,7 @@ class AuthComponent extends Component { * @param CakeRequest|null $request The request to authenticate for. If empty, the current request will be used. * @return bool True if $user is authorized, otherwise false */ - public function isAuthorized($user = null, CakeRequest $request = null) { + public function isAuthorized($user = null, ?CakeRequest $request = null) { if (empty($user) && !$this->user()) { return false; } diff --git a/lib/Cake/Controller/Component/SecurityComponent.php b/lib/Cake/Controller/Component/SecurityComponent.php index 9b3134e47..e9d779e76 100644 --- a/lib/Cake/Controller/Component/SecurityComponent.php +++ b/lib/Cake/Controller/Component/SecurityComponent.php @@ -344,7 +344,7 @@ class SecurityComponent extends Component { * @link https://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#handling-blackhole-callbacks * @throws BadRequestException */ - public function blackHole(Controller $controller, $error = '', SecurityException $exception = null) { + public function blackHole(Controller $controller, $error = '', ?SecurityException $exception = null) { if (!$this->blackHoleCallback) { $this->_throwException($exception); } @@ -822,7 +822,7 @@ class SecurityComponent extends Component { * @param string $method Method to execute * @param array $params Parameters to send to method * @return mixed Controller callback method's response - * @throws BadRequestException When a the blackholeCallback is not callable. + * @throws BadRequestException When the blackholeCallback is not callable. */ protected function _callback(Controller $controller, $method, $params = array()) { if (!is_callable(array($controller, $method))) { diff --git a/lib/Cake/Error/exceptions.php b/lib/Cake/Error/exceptions.php index 6608f6221..373d01a1b 100644 --- a/lib/Cake/Error/exceptions.php +++ b/lib/Cake/Error/exceptions.php @@ -297,7 +297,7 @@ class PrivateActionException extends CakeException { protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.'; //@codingStandardsIgnoreStart - public function __construct($message, $code = 404, Exception $previous = null) { + public function __construct($message, $code = 404, ?Exception $previous = null) { parent::__construct($message, $code, $previous); } //@codingStandardsIgnoreEnd diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 0322668ee..da3ffb911 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -527,7 +527,7 @@ class DboSource extends DataSource { * @param PDOStatement $query the query to extract the error from if any * @return string Error message with error number */ - public function lastError(PDOStatement $query = null) { + public function lastError(?PDOStatement $query = null) { if ($query) { $error = $query->errorInfo(); } else { @@ -2761,7 +2761,7 @@ class DboSource extends DataSource { * @param Model $Model A reference to the Model instance making the query * @return string SQL fragment */ - public function conditions($conditions, $quoteValues = true, $where = true, Model $Model = null) { + public function conditions($conditions, $quoteValues = true, $where = true, ?Model $Model = null) { $clause = $out = ''; if ($where) { @@ -2804,7 +2804,7 @@ class DboSource extends DataSource { * @param Model $Model A reference to the Model instance making the query * @return string SQL fragment */ - public function conditionKeysToString($conditions, $quoteValues = true, Model $Model = null) { + public function conditionKeysToString($conditions, $quoteValues = true, ?Model $Model = null) { $out = array(); $data = $columnType = null; @@ -2909,7 +2909,7 @@ class DboSource extends DataSource { * @param Model $Model Model object initiating the query * @return string */ - protected function _parseKey($key, $value, Model $Model = null) { + protected function _parseKey($key, $value, ?Model $Model = null) { $operatorMatch = '/^(((' . implode(')|(', $this->_sqlOps); $operatorMatch .= ')\\x20?)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is'; $bound = (strpos($key, '?') !== false || (is_array($value) && strpos($key, ':') !== false)); @@ -3083,7 +3083,7 @@ class DboSource extends DataSource { * @param Model $Model Model reference (used to look for virtual field) * @return string ORDER BY clause */ - public function order($keys, $direction = 'ASC', Model $Model = null) { + public function order($keys, $direction = 'ASC', ?Model $Model = null) { if (!is_array($keys)) { $keys = array($keys); } @@ -3166,7 +3166,7 @@ class DboSource extends DataSource { * @param Model $Model The model to get group by fields for. * @return string Group By clause or null. */ - public function group($fields, Model $Model = null) { + public function group($fields, ?Model $Model = null) { if (empty($fields)) { return null; } @@ -3196,7 +3196,7 @@ class DboSource extends DataSource { * @param Model $Model A reference to the Model instance making the query * @return string|null HAVING clause or null */ - public function having($fields, $quoteValues = true, Model $Model = null) { + public function having($fields, $quoteValues = true, ?Model $Model = null) { if (!$fields) { return null; } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index b597cf2d0..3ac6f6d6f 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -3913,7 +3913,7 @@ class Model extends CakeObject implements CakeEventListener { * If null a new ModelValidator instance will be made using current model object * @return ModelValidator */ - public function validator(ModelValidator $instance = null) { + public function validator(?ModelValidator $instance = null) { if ($instance) { $this->_validator = $instance; } elseif (!$this->_validator) { diff --git a/lib/Cake/Test/Case/Console/ShellTest.php b/lib/Cake/Test/Case/Console/ShellTest.php index 2617320e6..1886eac57 100644 --- a/lib/Cake/Test/Case/Console/ShellTest.php +++ b/lib/Cake/Test/Case/Console/ShellTest.php @@ -607,7 +607,7 @@ class ShellTest extends CakeTestCase { $this->Shell->interactive = false; - $contents = "Shell->createFile($file, $contents); $this->assertTrue($result); $this->assertTrue(file_exists($file)); diff --git a/lib/Cake/View/JsonView.php b/lib/Cake/View/JsonView.php index 2284233a5..d5412c46f 100644 --- a/lib/Cake/View/JsonView.php +++ b/lib/Cake/View/JsonView.php @@ -65,7 +65,7 @@ class JsonView extends View { * * @param Controller $controller Controller instance. */ - public function __construct(Controller $controller = null) { + public function __construct(?Controller $controller = null) { parent::__construct($controller); if (isset($controller->response) && $controller->response instanceof CakeResponse) { $controller->response->type('json'); diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 085928d2e..2b7410f66 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -330,7 +330,7 @@ class View extends CakeObject { * * @param Controller $controller A controller object to pull View::_passedVars from. */ - public function __construct(Controller $controller = null) { + public function __construct(?Controller $controller = null) { if (is_object($controller)) { $count = count($this->_passedVars); for ($j = 0; $j < $count; $j++) { diff --git a/lib/Cake/View/XmlView.php b/lib/Cake/View/XmlView.php index a8f4fcb16..eb6267b13 100644 --- a/lib/Cake/View/XmlView.php +++ b/lib/Cake/View/XmlView.php @@ -65,7 +65,7 @@ class XmlView extends View { * * @param Controller $controller Controller instance. */ - public function __construct(Controller $controller = null) { + public function __construct(?Controller $controller = null) { parent::__construct($controller); if (isset($controller->response) && $controller->response instanceof CakeResponse) {