Fixed implementations of ArrayAccess to reduce deprecation notices in PHP 8.1 #1

This commit is contained in:
Kamil Wylegala 2021-12-20 23:09:51 +01:00
parent e9ef6fb7e3
commit 61e4ef05c8
5 changed files with 28 additions and 28 deletions

View file

@ -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",

View file

@ -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]);
}

View file

@ -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]);
}

View file

@ -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]);
}

View file

@ -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();
}