Skip to content

Commit

Permalink
PHP 8.1 minimum version prep
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Mar 14, 2024
1 parent af83487 commit b7bb97d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ the following requirements:

* Your custom collection class must implement **\VersatileCollections\StrictlyTypedCollectionInterface** which currently contains the methods below:

* **public function checkType($item): bool** : it must return true if `$item` is of the expected type or false otherwise
* **public function checkType(mixed $item): bool** : it must return true if `$item` is of the expected type or false otherwise
* **public function getTypes()** : it must return an instance of **\VersatileCollections\StringsCollection** of strings representing the name(s) of the expected type(s)

* Your custom collection class should use **\VersatileCollections\StrictlyTypedCollectionInterfaceImplementationTrait** (which contains implementation of the methods in **\VersatileCollections\StrictlyTypedCollectionInterface**). If you choose not to use **\VersatileCollections\StrictlyTypedCollectionInterfaceImplementationTrait**, then you will have to implement all the methods specified in **\VersatileCollections\StrictlyTypedCollectionInterface** and make sure you call the **checkType($item)** method in every method where you add items to or modify items in the collection such as **offsetSet($key, $val)** and throw an **VersatileCollections\Exceptions\InvalidItemException** exception whenever **checkType($item)** returns false. If you use **\VersatileCollections\StrictlyTypedCollectionInterfaceImplementationTrait** in your custom collection class but add new methods that also add items to or modify items in the collection you can use the helper method **isRightTypeOrThrowInvalidTypeException($item, $calling_functions_name)** provided in **\VersatileCollections\StrictlyTypedCollectionInterfaceImplementationTrait** to validate items (it will automatically throw an exception for you if the item you are validating is of the wrong type; see **\VersatileCollections\StrictlyTypedCollectionInterfaceImplementationTrait::offsetSet($key, $val)** for an example of how this helper method should be used).

* You can optionally override **StrictlyTypedCollectionInterfaceImplementationTrait::__construct(...$arr_objs)** with a constructor
* You can optionally override **StrictlyTypedCollectionInterfaceImplementationTrait::__construct(mixed ...$arr_objs)** with a constructor
with the same signature but with the specific type. For example, **__construct(\PDO ...$pdo_objs)** ensures that only instances of
**\PDO** can be injected into the constructor via argument unpacking.

Expand All @@ -188,7 +188,7 @@ class PdoCollection implements StrictlyTypedCollectionInterface { //1. Implement
* @return bool true if $item is of the expected type, else false
*
*/
public function checkType($item): bool { //4. implement interface methods not implemented in trait above
public function checkType(mixed $item): bool { //4. implement interface methods not implemented in trait above

return ($item instanceof \PDO);
}
Expand Down

0 comments on commit b7bb97d

Please sign in to comment.