From 61e4ef05c8cafa22d069f25c767e4f0fdc7aed12 Mon Sep 17 00:00:00 2001 From: Kamil Wylegala Date: Mon, 20 Dec 2021 23:09:51 +0100 Subject: [PATCH] Fixed implementations of ArrayAccess to reduce deprecation notices in PHP 8.1 #1 --- composer.json | 2 +- lib/Cake/Model/ModelValidator.php | 12 ++++++------ lib/Cake/Model/Validator/CakeValidationSet.php | 12 ++++++------ lib/Cake/Network/CakeRequest.php | 14 +++++++------- lib/Cake/Network/Http/HttpSocketResponse.php | 16 ++++++++-------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index aff3b8590..23617dbf8 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "source": "https://github.com/cakephp/cakephp" }, "require": { - "php": "^7.0 || ^8.0" + "php": "^8.0" }, "suggest": { "ext-openssl": "You need to install ext-openssl or ext-mcrypt to use AES-256 encryption", diff --git a/lib/Cake/Model/ModelValidator.php b/lib/Cake/Model/ModelValidator.php index 406c0816c..7c34d94e4 100644 --- a/lib/Cake/Model/ModelValidator.php +++ b/lib/Cake/Model/ModelValidator.php @@ -461,10 +461,10 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { /** * Returns whether a rule set is defined for a field or not * - * @param string $field name of the field to check + * @param mixed $field name of the field to check * @return bool */ - public function offsetExists($field) { + public function offsetExists(mixed $field) : bool { $this->_parseRules(); return isset($this->_fields[$field]); } @@ -472,10 +472,10 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { /** * Returns the rule set for a field * - * @param string $field name of the field to check + * @param mixed $field name of the field to check * @return CakeValidationSet */ - public function offsetGet($field) { + public function offsetGet(mixed $field) : mixed { $this->_parseRules(); return $this->_fields[$field]; } @@ -487,7 +487,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { * @param array|CakeValidationSet $rules set of rules to apply to field * @return void */ - public function offsetSet($field, $rules) { + public function offsetSet(mixed $field, mixed $rules) : void { $this->_parseRules(); if (!$rules instanceof CakeValidationSet) { $rules = new CakeValidationSet($field, $rules); @@ -503,7 +503,7 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { * @param string $field name of the field to unset * @return void */ - public function offsetUnset($field) { + public function offsetUnset(mixed $field) : void { $this->_parseRules(); unset($this->_fields[$field]); } diff --git a/lib/Cake/Model/Validator/CakeValidationSet.php b/lib/Cake/Model/Validator/CakeValidationSet.php index eab540861..e04453e05 100644 --- a/lib/Cake/Model/Validator/CakeValidationSet.php +++ b/lib/Cake/Model/Validator/CakeValidationSet.php @@ -307,20 +307,20 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable { /** * Returns whether an index exists in the rule set * - * @param string $index name of the rule + * @param mixed $index name of the rule * @return bool */ - public function offsetExists($index) { + public function offsetExists(mixed $index) : bool { return isset($this->_rules[$index]); } /** * Returns a rule object by its index * - * @param string $index name of the rule + * @param mixed $index name of the rule * @return CakeValidationRule */ - public function offsetGet($index) { + public function offsetGet(mixed $index) : mixed { return $this->_rules[$index]; } @@ -335,7 +335,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable { * @return void * @see http://www.php.net/manual/en/arrayobject.offsetset.php */ - public function offsetSet($index, $rule) { + public function offsetSet(mixed $index, mixed $rule) : void { $this->setRule($index, $rule); } @@ -345,7 +345,7 @@ class CakeValidationSet implements ArrayAccess, IteratorAggregate, Countable { * @param string $index name of the rule * @return void */ - public function offsetUnset($index) { + public function offsetUnset(mixed $index) : void { unset($this->_rules[$index]); } diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index adc0b99b6..5d4bd7ee0 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -1113,10 +1113,10 @@ class CakeRequest implements ArrayAccess { /** * Array access read implementation * - * @param string $name Name of the key being accessed. + * @param mixed $name Name of the key being accessed. * @return mixed */ - public function offsetGet($name) { + public function offsetGet(mixed $name) : mixed { if (isset($this->params[$name])) { return $this->params[$name]; } @@ -1132,21 +1132,21 @@ class CakeRequest implements ArrayAccess { /** * Array access write implementation * - * @param string $name Name of the key being written + * @param mixed $name Name of the key being written * @param mixed $value The value being written. * @return void */ - public function offsetSet($name, $value) { + public function offsetSet(mixed $name, mixed $value) : void { $this->params[$name] = $value; } /** * Array access isset() implementation * - * @param string $name thing to check. + * @param mixed $name thing to check. * @return bool */ - public function offsetExists($name) { + public function offsetExists(mixed $name) : bool { if ($name === 'url' || $name === 'data') { return true; } @@ -1159,7 +1159,7 @@ class CakeRequest implements ArrayAccess { * @param string $name Name to unset. * @return void */ - public function offsetUnset($name) { + public function offsetUnset(mixed $name) : void { unset($this->params[$name]); } diff --git a/lib/Cake/Network/Http/HttpSocketResponse.php b/lib/Cake/Network/Http/HttpSocketResponse.php index 69c6da725..5b3f7dc53 100644 --- a/lib/Cake/Network/Http/HttpSocketResponse.php +++ b/lib/Cake/Network/Http/HttpSocketResponse.php @@ -386,20 +386,20 @@ class HttpSocketResponse implements ArrayAccess { /** * ArrayAccess - Offset Exists * - * @param string $offset Offset to check. + * @param mixed $offset Offset to check. * @return bool */ - public function offsetExists($offset) { + public function offsetExists(mixed $offset) : bool { return in_array($offset, array('raw', 'status', 'header', 'body', 'cookies')); } /** * ArrayAccess - Offset Get * - * @param string $offset Offset to get. + * @param mixed $offset Offset to get. * @return mixed */ - public function offsetGet($offset) { + public function offsetGet(mixed $offset) : mixed { switch ($offset) { case 'raw': $firstLineLength = strpos($this->raw, "\r\n") + 2; @@ -433,11 +433,11 @@ class HttpSocketResponse implements ArrayAccess { /** * ArrayAccess - Offset Set * - * @param string $offset Offset to set. + * @param mixed $offset Offset to set. * @param mixed $value Value. * @return void */ - public function offsetSet($offset, $value) { + public function offsetSet(mixed $offset, mixed $value) : void { } /** @@ -446,7 +446,7 @@ class HttpSocketResponse implements ArrayAccess { * @param string $offset Offset to unset. * @return void */ - public function offsetUnset($offset) { + public function offsetUnset(mixed $offset) : void { } /** @@ -454,7 +454,7 @@ class HttpSocketResponse implements ArrayAccess { * * @return string */ - public function __toString() { + public function __tostring() { return $this->body(); }