Skip to content

Commit

Permalink
Rector tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi authored and rotimi committed Apr 13, 2021
1 parent e96f5b5 commit 57dfcc6
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 48 deletions.
3 changes: 3 additions & 0 deletions src/ArraysCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class ArraysCollection implements StrictlyTypedCollectionInterface

use StrictlyTypedCollectionInterfaceImplementationTrait;

/**
* @param array[] ...$arrays
*/
public function __construct(array ...$arrays) {

$this->versatile_collections_items = $arrays;
Expand Down
3 changes: 3 additions & 0 deletions src/CallablesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class CallablesCollection implements StrictlyTypedCollectionInterface

use StrictlyTypedCollectionInterfaceImplementationTrait;

/**
* @param callable[] ...$callables
*/
public function __construct(callable ...$callables) {

$this->versatile_collections_items = $callables;
Expand Down
26 changes: 12 additions & 14 deletions src/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,18 +585,17 @@ public function containsKey($key): bool;
public function containsKeys(array $keys): bool;

/**
*
*
* Appends all items from $other collection to the end of $this collection.
* Note that appended items will be assigned numeric keys.
*
*
*
*
*
*
* @used-for: adding-items
*
*
* @title: Appends all items from a specified collection to the end of a collection. Note that appended items will be assigned numeric keys.
*
*
* @noRector \Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector
*
*/
public function appendCollection(CollectionInterface $other): CollectionInterface;

Expand All @@ -617,18 +616,17 @@ public function appendCollection(CollectionInterface $other): CollectionInterfac
public function appendItem($item): CollectionInterface;

/**
*
*
* Prepends all items from $other collection to the front of $this collection.
* Note that all numeric keys will be modified to start counting from zero while literal keys won't be changed.
*
*
*
*
*
*
* @used-for: adding-items
*
*
* @title: Prepends all items from a specified collection to the front of a collection.
*
*
* @noRector \Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector
*
*/
public function prependCollection(CollectionInterface $other): CollectionInterface;

Expand Down
28 changes: 16 additions & 12 deletions src/CollectionInterfaceImplementationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ public function offsetExists($key): bool {
}

/**
*
*
* @see \VersatileCollections\CollectionInterface::offsetGet()
*
*
* @return mixed|void
*/
public function offsetGet($key) {

Expand Down Expand Up @@ -438,9 +439,10 @@ public function toArray(): array {
}

/**
*
*
* @see \VersatileCollections\CollectionInterface::getIterator()
*
*
* @return \ArrayIterator
*/
public function getIterator(): Iterator {

Expand Down Expand Up @@ -471,9 +473,10 @@ public function __construct(...$items) {
////////////////////////////////////////////////////////////////////////////
////////// OTHER COLLECTION METHODS ////////////////////////////////////////
/**
*
*
* @see \VersatileCollections\CollectionInterface::firstItem()
*
*
* @return null|mixed
*/
public function firstItem(){

Expand All @@ -483,9 +486,10 @@ public function firstItem(){
}

/**
*
*
* @see \VersatileCollections\CollectionInterface::lastItem()
*
*
* @return null|mixed
*/
public function lastItem(){

Expand Down Expand Up @@ -856,9 +860,9 @@ public function containsKeys(array $keys): bool {
}

/**
*
*
* @see \VersatileCollections\CollectionInterface::appendCollection()
*
*
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function appendCollection(CollectionInterface $other): CollectionInterface
Expand Down Expand Up @@ -930,9 +934,9 @@ public function mergeMeWith(array $items): CollectionInterface
}

/**
*
*
* @see \VersatileCollections\CollectionInterface::prependCollection()
*
*
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function prependCollection(CollectionInterface $other): CollectionInterface
Expand Down
6 changes: 2 additions & 4 deletions src/FloatsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ public function getType() {

/**
* @param $str
* @return float
* @noinspection PhpMissingReturnTypeInspection
*/
protected function itemFromString($str) {
protected function itemFromString(string $str): float {

return ((float) ($str.''));
}

/**
* @param $item
* @return string
* @noinspection PhpMissingReturnTypeInspection
*/
protected function itemToString($item) {
protected function itemToString($item): string {

return $item.'';
}
Expand Down
6 changes: 2 additions & 4 deletions src/IntsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ public function getType() {

/**
* @param $str
* @return int
* @noinspection PhpMissingReturnTypeInspection
*/
protected function itemFromString($str) {
protected function itemFromString(string $str): int {

return ((int) ($str.''));
}

/**
* @param $item
* @return string
* @noinspection PhpMissingReturnTypeInspection
*/
protected function itemToString($item) {
protected function itemToString($item): string {

return $item.'';
}
Expand Down
4 changes: 3 additions & 1 deletion src/MultiSortParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class MultiSortParameters {
SORT_FLAG_CASE, (SORT_FLAG_CASE | SORT_STRING), (SORT_FLAG_CASE | SORT_NATURAL)
];

/** @noinspection PhpUnhandledExceptionInspection */
/** @noinspection PhpUnhandledExceptionInspection
* @param int $sort_direction
* @param int $sort_type */
public function __construct(string $field_name, ?int $sort_direction=null, ?int $sort_type=null) {

if( $this->validateFieldName($field_name) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/NumericsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getType() {
*
* @noinspection PhpMissingParamTypeInspection
*/
protected function itemFromString($str) {
protected function itemFromString(string $str) {

if( \strpos($str, '.') !== false ) {

Expand All @@ -96,7 +96,7 @@ protected function itemFromString($str) {
*
* @noinspection PhpMissingReturnTypeInspection
*/
protected function itemToString($item) {
protected function itemToString($item): string {

return $item.'';
}
Expand Down
3 changes: 3 additions & 0 deletions src/ObjectsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class ObjectsCollection implements StrictlyTypedCollectionInterface
StrictlyTypedCollectionInterfaceImplementationTrait::__construct as strictlyTypedCollectionTrait__construct;
}

/**
* @param object[] ...$objects
*/
public function __construct(object ...$objects) {

$this->versatile_collections_items = $objects;
Expand Down
1 change: 1 addition & 0 deletions src/SpecificObjectsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class SpecificObjectsCollection extends ObjectsCollection {

/** @noinspection PhpMissingParentConstructorInspection
* @noinspection PhpUnnecessaryStaticReferenceInspection
* @param object[] ...$objects
*/
protected function __construct(object ...$objects) {

Expand Down
6 changes: 3 additions & 3 deletions src/StrictlyTypedCollectionInterfaceImplementationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(...$arr_objs) {
}

/**
*
*
* @see \VersatileCollections\CollectionInterface::appendCollection()
*
* @noinspection PhpDocSignatureInspection
Expand Down Expand Up @@ -125,12 +125,12 @@ public function offsetSet($key, $val): void {
}

/**
*
*
* @see \VersatileCollections\CollectionInterface::prependCollection()
*
* @noinspection PhpDocSignatureInspection
* @noinspection PhpUnhandledExceptionInspection
*
*
* @psalm-suppress LessSpecificImplementedReturnType
*/
public function prependCollection(CollectionInterface $other): CollectionInterface {
Expand Down
4 changes: 2 additions & 2 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function canReallyBind(callable $callback): bool {
/**
*
*
* @return mixed
* @return int|string|null
*/
public static function array_key_first(array $array) {

Expand All @@ -85,7 +85,7 @@ public static function array_key_first(array $array) {
/**
*
*
* @return mixed
* @return int|string|null
*/
public static function array_key_last(array $array) {

Expand Down
11 changes: 5 additions & 6 deletions src/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,20 @@ function get_object_property_value(object $obj, $property, $default_val=null, bo
}

/**
*
*
* A more robust way than property_exists of checking if an instance of a class
* has a specified property.
*
*
* @param object $obj
* @param string|int $property
*
* @return bool
*
*
*
* @throws InvalidArgumentException
*
* @noinspection PhpMissingReturnTypeInspection
* @psalm-suppress DocblockTypeContradiction
*/
function object_has_property(object $obj, $property) {
function object_has_property(object $obj, $property): bool {

if( !\is_string($property) && !\is_int($property) ) {

Expand Down

0 comments on commit 57dfcc6

Please sign in to comment.