Trait for the Collection > type hinting

This commit is contained in:
Meritoo
2019-05-10 22:17:40 +02:00
parent 98d0fed61d
commit 9a1f49d373
4 changed files with 15 additions and 15 deletions

View File

@@ -19,7 +19,7 @@ trait ArrayAccessTrait
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function offsetExists($offset) public function offsetExists($offset): bool
{ {
return $this->exists($offset); return $this->exists($offset);
} }
@@ -39,7 +39,7 @@ trait ArrayAccessTrait
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function offsetSet($offset, $value) public function offsetSet($offset, $value): void
{ {
$this->elements[$offset] = $value; $this->elements[$offset] = $value;
} }
@@ -47,7 +47,7 @@ trait ArrayAccessTrait
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function offsetUnset($offset) public function offsetUnset($offset): void
{ {
if ($this->exists($offset)) { if ($this->exists($offset)) {
unset($this->elements[$offset]); unset($this->elements[$offset]);
@@ -60,7 +60,7 @@ trait ArrayAccessTrait
* @param int|string $index The index/key of element * @param int|string $index The index/key of element
* @return bool * @return bool
*/ */
private function exists($index) private function exists($index): bool
{ {
return isset($this->elements[$index]) || array_key_exists($index, $this->elements); return isset($this->elements[$index]) || array_key_exists($index, $this->elements);
} }

View File

@@ -19,7 +19,7 @@ trait CountableTrait
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function count() public function count(): int
{ {
return count($this->elements); return count($this->elements);
} }

View File

@@ -21,7 +21,7 @@ trait IteratorAggregateTrait
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getIterator() public function getIterator(): ArrayIterator
{ {
return new ArrayIterator($this->elements); return new ArrayIterator($this->elements);
} }

View File

@@ -33,7 +33,7 @@ trait MainTrait
* @param mixed $index (optional) Index / key of the element * @param mixed $index (optional) Index / key of the element
* @return $this * @return $this
*/ */
public function add($element, $index = null) public function add($element, $index = null): self
{ {
if (null === $index || '' === $index) { if (null === $index || '' === $index) {
$this->elements[] = $element; $this->elements[] = $element;
@@ -52,7 +52,7 @@ trait MainTrait
* this collection. Otherwise - not. * this collection. Otherwise - not.
* @return $this * @return $this
*/ */
public function addMultiple($elements, $useIndexes = false) public function addMultiple($elements, bool $useIndexes = false): self
{ {
if (!empty($elements)) { if (!empty($elements)) {
foreach ($elements as $index => $element) { foreach ($elements as $index => $element) {
@@ -75,7 +75,7 @@ trait MainTrait
* @param mixed $element The element to prepend * @param mixed $element The element to prepend
* @return $this * @return $this
*/ */
public function prepend($element) public function prepend($element): self
{ {
array_unshift($this->elements, $element); array_unshift($this->elements, $element);
@@ -88,7 +88,7 @@ trait MainTrait
* @param mixed $element The element to remove * @param mixed $element The element to remove
* @return $this * @return $this
*/ */
public function remove($element) public function remove($element): self
{ {
if ($this->count() > 0) { if ($this->count() > 0) {
foreach ($this->elements as $index => $existing) { foreach ($this->elements as $index => $existing) {
@@ -108,7 +108,7 @@ trait MainTrait
* *
* @return bool * @return bool
*/ */
public function isEmpty() public function isEmpty(): bool
{ {
return empty($this->elements); return empty($this->elements);
} }
@@ -119,7 +119,7 @@ trait MainTrait
* @param mixed $element The element to verify * @param mixed $element The element to verify
* @return bool * @return bool
*/ */
public function isFirst($element) public function isFirst($element): bool
{ {
return reset($this->elements) === $element; return reset($this->elements) === $element;
} }
@@ -130,7 +130,7 @@ trait MainTrait
* @param mixed $element The element to verify * @param mixed $element The element to verify
* @return bool * @return bool
*/ */
public function isLast($element) public function isLast($element): bool
{ {
return end($this->elements) === $element; return end($this->elements) === $element;
} }
@@ -141,7 +141,7 @@ trait MainTrait
* @param mixed $element The element to verify * @param mixed $element The element to verify
* @return bool * @return bool
*/ */
public function has($element) public function has($element): bool
{ {
$index = Arrays::getIndexOf($this->elements, $element); $index = Arrays::getIndexOf($this->elements, $element);
@@ -210,7 +210,7 @@ trait MainTrait
* *
* @return array * @return array
*/ */
public function toArray() public function toArray(): array
{ {
return $this->elements; return $this->elements;
} }