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 <markus.bauer@cispa.saarland>
This commit is contained in:
Markus Bauer 2024-07-24 21:55:01 +02:00 committed by GitHub
parent 42e9fa1aad
commit 2220f35b1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 21 additions and 21 deletions

View file

@ -248,7 +248,7 @@ class FixtureTask extends BakeTask {
$this->_Schema = new CakeSchema(); $this->_Schema = new CakeSchema();
$data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection)); $data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection));
if (!isset($data['tables'][$useTable])) { if (!isset($data['tables'][$useTable])) {
$this->err("<warning>Warning:</warning> Could not find the '${useTable}' table for ${model}."); $this->err("<warning>Warning:</warning> Could not find the '{$useTable}' table for {$model}.");
return null; return null;
} }

View file

@ -170,7 +170,7 @@ class ModelTask extends BakeTask {
while (!$valid) { while (!$valid) {
$len = strlen(count($options) + 1); $len = strlen(count($options) + 1);
foreach ($options as $i => $option) { 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)) { if (empty($prompt)) {
$prompt = __d('cake_console', 'Make a selection from the choices above'); $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:')); $this->out(__d('cake_console', 'Possible Models based on your current database:'));
$len = strlen($count + 1); $len = strlen($count + 1);
for ($i = 0; $i < $count; $i++) { 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; return $this->_tables;

View file

@ -89,7 +89,7 @@ abstract class BaseAuthorize {
* @return mixed * @return mixed
* @throws CakeException * @throws CakeException
*/ */
public function controller(Controller $controller = null) { public function controller(?Controller $controller = null) {
if ($controller) { if ($controller) {
if (!$controller instanceof Controller) { if (!$controller instanceof Controller) {
throw new CakeException(__d('cake_dev', '$controller needs to be an instance of Controller')); throw new CakeException(__d('cake_dev', '$controller needs to be an instance of Controller'));

View file

@ -43,7 +43,7 @@ class ControllerAuthorize extends BaseAuthorize {
* @return mixed * @return mixed
* @throws CakeException * @throws CakeException
*/ */
public function controller(Controller $controller = null) { public function controller(?Controller $controller = null) {
if ($controller) { if ($controller) {
if (!method_exists($controller, 'isAuthorized')) { if (!method_exists($controller, 'isAuthorized')) {
throw new CakeException(__d('cake_dev', '$controller does not implement an %s method.', 'isAuthorized()')); throw new CakeException(__d('cake_dev', '$controller does not implement an %s method.', 'isAuthorized()'));

View file

@ -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. * @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 * @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()) { if (empty($user) && !$this->user()) {
return false; return false;
} }

View file

@ -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 * @link https://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#handling-blackhole-callbacks
* @throws BadRequestException * @throws BadRequestException
*/ */
public function blackHole(Controller $controller, $error = '', SecurityException $exception = null) { public function blackHole(Controller $controller, $error = '', ?SecurityException $exception = null) {
if (!$this->blackHoleCallback) { if (!$this->blackHoleCallback) {
$this->_throwException($exception); $this->_throwException($exception);
} }
@ -822,7 +822,7 @@ class SecurityComponent extends Component {
* @param string $method Method to execute * @param string $method Method to execute
* @param array $params Parameters to send to method * @param array $params Parameters to send to method
* @return mixed Controller callback method's response * @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()) { protected function _callback(Controller $controller, $method, $params = array()) {
if (!is_callable(array($controller, $method))) { if (!is_callable(array($controller, $method))) {

View file

@ -297,7 +297,7 @@ class PrivateActionException extends CakeException {
protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.'; protected $_messageTemplate = 'Private Action %s::%s() is not directly accessible.';
//@codingStandardsIgnoreStart //@codingStandardsIgnoreStart
public function __construct($message, $code = 404, Exception $previous = null) { public function __construct($message, $code = 404, ?Exception $previous = null) {
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }
//@codingStandardsIgnoreEnd //@codingStandardsIgnoreEnd

View file

@ -527,7 +527,7 @@ class DboSource extends DataSource {
* @param PDOStatement $query the query to extract the error from if any * @param PDOStatement $query the query to extract the error from if any
* @return string Error message with error number * @return string Error message with error number
*/ */
public function lastError(PDOStatement $query = null) { public function lastError(?PDOStatement $query = null) {
if ($query) { if ($query) {
$error = $query->errorInfo(); $error = $query->errorInfo();
} else { } else {
@ -2761,7 +2761,7 @@ class DboSource extends DataSource {
* @param Model $Model A reference to the Model instance making the query * @param Model $Model A reference to the Model instance making the query
* @return string SQL fragment * @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 = ''; $clause = $out = '';
if ($where) { if ($where) {
@ -2804,7 +2804,7 @@ class DboSource extends DataSource {
* @param Model $Model A reference to the Model instance making the query * @param Model $Model A reference to the Model instance making the query
* @return string SQL fragment * @return string SQL fragment
*/ */
public function conditionKeysToString($conditions, $quoteValues = true, Model $Model = null) { public function conditionKeysToString($conditions, $quoteValues = true, ?Model $Model = null) {
$out = array(); $out = array();
$data = $columnType = null; $data = $columnType = null;
@ -2909,7 +2909,7 @@ class DboSource extends DataSource {
* @param Model $Model Model object initiating the query * @param Model $Model Model object initiating the query
* @return string * @return string
*/ */
protected function _parseKey($key, $value, Model $Model = null) { protected function _parseKey($key, $value, ?Model $Model = null) {
$operatorMatch = '/^(((' . implode(')|(', $this->_sqlOps); $operatorMatch = '/^(((' . implode(')|(', $this->_sqlOps);
$operatorMatch .= ')\\x20?)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is'; $operatorMatch .= ')\\x20?)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)/is';
$bound = (strpos($key, '?') !== false || (is_array($value) && strpos($key, ':') !== false)); $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) * @param Model $Model Model reference (used to look for virtual field)
* @return string ORDER BY clause * @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)) { if (!is_array($keys)) {
$keys = array($keys); $keys = array($keys);
} }
@ -3166,7 +3166,7 @@ class DboSource extends DataSource {
* @param Model $Model The model to get group by fields for. * @param Model $Model The model to get group by fields for.
* @return string Group By clause or null. * @return string Group By clause or null.
*/ */
public function group($fields, Model $Model = null) { public function group($fields, ?Model $Model = null) {
if (empty($fields)) { if (empty($fields)) {
return null; return null;
} }
@ -3196,7 +3196,7 @@ class DboSource extends DataSource {
* @param Model $Model A reference to the Model instance making the query * @param Model $Model A reference to the Model instance making the query
* @return string|null HAVING clause or null * @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) { if (!$fields) {
return null; return null;
} }

View file

@ -3913,7 +3913,7 @@ class Model extends CakeObject implements CakeEventListener {
* If null a new ModelValidator instance will be made using current model object * If null a new ModelValidator instance will be made using current model object
* @return ModelValidator * @return ModelValidator
*/ */
public function validator(ModelValidator $instance = null) { public function validator(?ModelValidator $instance = null) {
if ($instance) { if ($instance) {
$this->_validator = $instance; $this->_validator = $instance;
} elseif (!$this->_validator) { } elseif (!$this->_validator) {

View file

@ -607,7 +607,7 @@ class ShellTest extends CakeTestCase {
$this->Shell->interactive = false; $this->Shell->interactive = false;
$contents = "<?php{$eol}echo 'test';${eol}\$te = 'st';{$eol}"; $contents = "<?php{$eol}echo 'test';{$eol}\$te = 'st';{$eol}";
$result = $this->Shell->createFile($file, $contents); $result = $this->Shell->createFile($file, $contents);
$this->assertTrue($result); $this->assertTrue($result);
$this->assertTrue(file_exists($file)); $this->assertTrue(file_exists($file));

View file

@ -65,7 +65,7 @@ class JsonView extends View {
* *
* @param Controller $controller Controller instance. * @param Controller $controller Controller instance.
*/ */
public function __construct(Controller $controller = null) { public function __construct(?Controller $controller = null) {
parent::__construct($controller); parent::__construct($controller);
if (isset($controller->response) && $controller->response instanceof CakeResponse) { if (isset($controller->response) && $controller->response instanceof CakeResponse) {
$controller->response->type('json'); $controller->response->type('json');

View file

@ -330,7 +330,7 @@ class View extends CakeObject {
* *
* @param Controller $controller A controller object to pull View::_passedVars from. * @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)) { if (is_object($controller)) {
$count = count($this->_passedVars); $count = count($this->_passedVars);
for ($j = 0; $j < $count; $j++) { for ($j = 0; $j < $count; $j++) {

View file

@ -65,7 +65,7 @@ class XmlView extends View {
* *
* @param Controller $controller Controller instance. * @param Controller $controller Controller instance.
*/ */
public function __construct(Controller $controller = null) { public function __construct(?Controller $controller = null) {
parent::__construct($controller); parent::__construct($controller);
if (isset($controller->response) && $controller->response instanceof CakeResponse) { if (isset($controller->response) && $controller->response instanceof CakeResponse) {