[REF][PHP8.1] Add in type hints to fix deprecations and add in #[\ReturnTypeWillChang...
authorSeamus Lee <seamuslee001@gmail.com>
Fri, 1 Jul 2022 02:31:29 +0000 (12:31 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Fri, 1 Jul 2022 02:31:29 +0000 (12:31 +1000)
CRM/Utils/LazyArray.php
Civi/Api4/Generic/AbstractAction.php
Civi/Api4/Generic/Result.php
Civi/Api4/Service/Spec/RequestSpec.php
Civi/Token/TokenProcessor.php
Civi/Token/TokenRow.php
ext/eventcart/CRM/Event/Cart/BAO/EventInCart.php
tests/phpunit/CRM/Contact/BAO/QueryTestDataProvider.php
tests/phpunit/CRM/Contact/Form/Search/Custom/GroupTestDataProvider.php
tests/phpunit/CRM/Mailing/BAO/QueryTestDataProvider.php

index 4ea6ab165995fee43417bda46505da6f1cf313e1..72f8089711f862891dfbc5a069172e29c9044b3d 100644 (file)
@@ -56,15 +56,16 @@ class CRM_Utils_LazyArray implements ArrayAccess, IteratorAggregate, Countable {
     return $this;
   }
 
-  public function offsetExists($offset) {
+  public function offsetExists($offset): bool {
     return isset($this->load()->cache[$offset]);
   }
 
+  #[\ReturnTypeWillChange]
   public function &offsetGet($offset) {
     return $this->load()->cache[$offset];
   }
 
-  public function offsetSet($offset, $value) {
+  public function offsetSet($offset, $value): void {
     if ($offset === NULL) {
       $this->load()->cache[] = $value;
     }
@@ -73,10 +74,11 @@ class CRM_Utils_LazyArray implements ArrayAccess, IteratorAggregate, Countable {
     }
   }
 
-  public function offsetUnset($offset) {
+  public function offsetUnset($offset): void {
     unset($this->load()->cache[$offset]);
   }
 
+  #[\ReturnTypeWillChange]
   public function getIterator() {
     return new ArrayIterator($this->load()->cache);
   }
@@ -88,7 +90,7 @@ class CRM_Utils_LazyArray implements ArrayAccess, IteratorAggregate, Countable {
     return $this->load()->cache;
   }
 
-  public function count() {
+  public function count(): int {
     return count($this->load()->cache);
   }
 
index 0abc53a3fd52cf803f56652946b9b7d330319b6f..0aa5e8be4bc8ffbe70ebc4b68d27efced94e5085 100644 (file)
@@ -327,13 +327,14 @@ abstract class AbstractAction implements \ArrayAccess {
   /**
    * @inheritDoc
    */
-  public function offsetExists($offset) {
+  public function offsetExists($offset): bool {
     return in_array($offset, ['entity', 'action', 'params', 'version', 'check_permissions', 'id']) || isset($this->_arrayStorage[$offset]);
   }
 
   /**
    * @inheritDoc
    */
+  #[\ReturnTypeWillChange]
   public function &offsetGet($offset) {
     $val = NULL;
     if (in_array($offset, ['entity', 'action'])) {
@@ -359,7 +360,7 @@ abstract class AbstractAction implements \ArrayAccess {
   /**
    * @inheritDoc
    */
-  public function offsetSet($offset, $value) {
+  public function offsetSet($offset, $value): void {
     if (in_array($offset, ['entity', 'action', 'entityName', 'actionName', 'params', 'version', 'id'])) {
       throw new \API_Exception('Cannot modify api4 state via array access');
     }
@@ -374,7 +375,7 @@ abstract class AbstractAction implements \ArrayAccess {
   /**
    * @inheritDoc
    */
-  public function offsetUnset($offset) {
+  public function offsetUnset($offset): void {
     if (in_array($offset, ['entity', 'action', 'entityName', 'actionName', 'params', 'check_permissions', 'version', 'id'])) {
       throw new \API_Exception('Cannot modify api4 state via array access');
     }
index 3689bee31153b12bdfcf5b9644ca410c9532356a..c1896890bf32b20edc7f542588ef89bea52db5b4 100644 (file)
@@ -157,7 +157,7 @@ class Result extends \ArrayObject implements \JsonSerializable {
    *
    * @return int
    */
-  public function count() {
+  public function count(): int {
     return $this->rowCount ?? parent::count();
   }
 
@@ -211,6 +211,7 @@ class Result extends \ArrayObject implements \JsonSerializable {
   /**
    * @return array
    */
+  #[\ReturnTypeWillChange]
   public function jsonSerialize() {
     return $this->getArrayCopy();
   }
index 7899ebe46ef65e5a33bcc1e3b7ff61e95fd91ffb..c18381c1ebb1a4288e9e95e9c57b140df6fca722 100644 (file)
@@ -176,23 +176,26 @@ class RequestSpec implements \Iterator {
     return $this->action;
   }
 
+  #[\ReturnTypeWillChange]
   public function rewind() {
     return reset($this->fields);
   }
 
+  #[\ReturnTypeWillChange]
   public function current() {
     return current($this->fields);
   }
 
+  #[\ReturnTypeWillChange]
   public function key() {
     return key($this->fields);
   }
 
-  public function next() {
-    return next($this->fields);
+  public function next(): void {
+    next($this->fields);
   }
 
-  public function valid() {
+  public function valid(): bool {
     return key($this->fields) !== NULL;
   }
 
index 4929a9c14fcb38e059e09621b289471e7398557e..87290e4aec6b56aedc2fb6231d23e35c7c3187fd 100644 (file)
@@ -528,6 +528,7 @@ class TokenRowIterator extends \IteratorIterator {
     $this->tokenProcessor = $tokenProcessor;
   }
 
+  #[\ReturnTypeWillChange]
   public function current() {
     return new TokenRow($this->tokenProcessor, parent::key());
   }
index 67010083918f5b7b22c1aed21a6889149f1a7199..0ef5b067e36a0dcf3e0b950a9fe28f1eb3705b05 100644 (file)
@@ -355,7 +355,7 @@ class TokenRowContext implements \ArrayAccess, \IteratorAggregate, \Countable {
    *
    * @return bool
    */
-  public function offsetExists($offset) {
+  public function offsetExists($offset): bool {
     return isset($this->tokenProcessor->rowContexts[$this->tokenRow][$offset])
       || isset($this->tokenProcessor->context[$offset]);
   }
@@ -367,6 +367,7 @@ class TokenRowContext implements \ArrayAccess, \IteratorAggregate, \Countable {
    *
    * @return string
    */
+  #[\ReturnTypeWillChange]
   public function &offsetGet($offset) {
     if (isset($this->tokenProcessor->rowContexts[$this->tokenRow][$offset])) {
       return $this->tokenProcessor->rowContexts[$this->tokenRow][$offset];
@@ -384,7 +385,7 @@ class TokenRowContext implements \ArrayAccess, \IteratorAggregate, \Countable {
    * @param string $offset
    * @param mixed $value
    */
-  public function offsetSet($offset, $value) {
+  public function offsetSet($offset, $value): void {
     $this->tokenProcessor->rowContexts[$this->tokenRow][$offset] = $value;
   }
 
@@ -393,7 +394,7 @@ class TokenRowContext implements \ArrayAccess, \IteratorAggregate, \Countable {
    *
    * @param mixed $offset
    */
-  public function offsetUnset($offset) {
+  public function offsetUnset($offset): void {
     unset($this->tokenProcessor->rowContexts[$this->tokenRow][$offset]);
   }
 
@@ -402,6 +403,7 @@ class TokenRowContext implements \ArrayAccess, \IteratorAggregate, \Countable {
    *
    * @return \ArrayIterator
    */
+  #[\ReturnTypeWillChange]
   public function getIterator() {
     return new \ArrayIterator($this->createMergedArray());
   }
@@ -411,7 +413,7 @@ class TokenRowContext implements \ArrayAccess, \IteratorAggregate, \Countable {
    *
    * @return int
    */
-  public function count() {
+  public function count(): int {
     return count($this->createMergedArray());
   }
 
index 97cc92d256df8cc320a2378535b7afcf1b9dfad7..b06844e7c590283c26e1ee20d6a331a7ec92ca15 100644 (file)
@@ -222,7 +222,7 @@ class CRM_Event_Cart_BAO_EventInCart extends CRM_Event_Cart_DAO_EventInCart impl
    *
    * @return bool
    */
-  public function offsetExists($offset) {
+  public function offsetExists($offset): bool {
     return array_key_exists(array_merge($this->fields(), ['main_conference_event_id']), $offset);
   }
 
@@ -231,6 +231,7 @@ class CRM_Event_Cart_BAO_EventInCart extends CRM_Event_Cart_DAO_EventInCart impl
    *
    * @return int
    */
+  #[\ReturnTypeWillChange]
   public function offsetGet($offset) {
     if ($offset == 'event') {
       return $this->event->toArray();
@@ -249,13 +250,13 @@ class CRM_Event_Cart_BAO_EventInCart extends CRM_Event_Cart_DAO_EventInCart impl
    * @param mixed $offset
    * @param mixed $value
    */
-  public function offsetSet($offset, $value) {
+  public function offsetSet($offset, $value): void {
   }
 
   /**
    * @param mixed $offset
    */
-  public function offsetUnset($offset) {
+  public function offsetUnset($offset): void {
   }
 
   /**
index 6c40d94231a80ceab474af1666e43671a8934485..f8cfd1ae95a6b233ed4282dbd0f381a7f16573e5 100644 (file)
@@ -210,6 +210,7 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator {
     $this->i = 0;
   }
 
+  #[\ReturnTypeWillChange]
   public function rewind() {
     $this->i = 0;
   }
@@ -217,6 +218,7 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator {
   /**
    * @return array
    */
+  #[\ReturnTypeWillChange]
   public function current() {
     $count = count($this->dataset[$this->i]['id']);
     $ids = $this->dataset[$this->i]['id'];
@@ -234,18 +236,19 @@ class CRM_Contact_BAO_QueryTestDataProvider implements Iterator {
   /**
    * @return int
    */
+  #[\ReturnTypeWillChange]
   public function key() {
     return $this->i;
   }
 
-  public function next() {
+  public function next(): void {
     $this->i++;
   }
 
   /**
    * @return bool
    */
-  public function valid() {
+  public function valid(): bool {
     return isset($this->dataset[$this->i]);
   }
 
index 7df961d860d8bab860ce0c2aebc0fc346f9257b1..46c321f39e60b3a21ebc00daf9e940d764ee4a1d 100644 (file)
@@ -323,6 +323,7 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator {
     ],
   ];
 
+  #[\ReturnTypeWillChange]
   public function rewind() {
     $this->i = 0;
   }
@@ -330,6 +331,7 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator {
   /**
    * @return array
    */
+  #[\ReturnTypeWillChange]
   public function current() {
     $count = count($this->dataset[$this->i]['id']);
     $ids = $this->dataset[$this->i]['id'];
@@ -357,18 +359,19 @@ class CRM_Contact_Form_Search_Custom_GroupTestDataProvider implements Iterator {
   /**
    * @return int
    */
+  #[\ReturnTypeWillChange]
   public function key() {
     return $this->i;
   }
 
-  public function next() {
+  public function next(): void {
     $this->i++;
   }
 
   /**
    * @return bool
    */
-  public function valid() {
+  public function valid(): bool {
     return isset($this->dataset[$this->i]);
   }
 
index 2f795a2a2b6dd097b964850ba52806fce4b4f0fb..a736c2aaf8a672daf9fa3d34594fdb693ec1f84c 100644 (file)
@@ -113,6 +113,7 @@ class CRM_Mailing_BAO_QueryTestDataProvider implements Iterator {
     $this->i = 0;
   }
 
+  #[\ReturnTypeWillChange]
   public function rewind() {
     $this->i = 0;
   }
@@ -120,6 +121,7 @@ class CRM_Mailing_BAO_QueryTestDataProvider implements Iterator {
   /**
    * @return array
    */
+  #[\ReturnTypeWillChange]
   public function current() {
     $count = count($this->dataset[$this->i]['id']);
     $ids = $this->dataset[$this->i]['id'];
@@ -137,18 +139,19 @@ class CRM_Mailing_BAO_QueryTestDataProvider implements Iterator {
   /**
    * @return int
    */
+  #[\ReturnTypeWillChange]
   public function key() {
     return $this->i;
   }
 
-  public function next() {
+  public function next(): void {
     $this->i++;
   }
 
   /**
    * @return bool
    */
-  public function valid() {
+  public function valid(): bool {
     return isset($this->dataset[$this->i]);
   }