Passed
Push — 1.x ( 5b3b89...65c981 )
by Ulises Jeremias
02:37
created

FixedArray::key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php namespace Mbh\Collection;
2
3
/**
4
 * MBHFramework
5
 *
6
 * @link      https://github.com/MBHFramework/mbh-framework
7
 * @copyright Copyright (c) 2017 Ulises Jeremias Cornejo Fandos
8
 * @license   https://github.com/MBHFramework/mbh-framework/blob/master/LICENSE (MIT License)
9
 */
10
11
use Mbh\Collection\Interfaces\Collection as CollectionInterface;
12
use Mbh\Collection\Interfaces\Sequenceable as SequenceableInterface;
13
use Mbh\Collection\CallbackHeap;
14
use Mbh\Iterator\SliceIterator;
15
use Mbh\Iterator\ConcatIterator;
16
use SplFixedArray;
17
use SplHeap;
18
use SplStack;
19
use LimitIterator;
20
use Iterator;
21
use ArrayAccess;
22
use Countable;
23
use CallbackFilterIterator;
24
use JsonSerializable;
25
use RuntimeException;
26
use Traversable;
27
use ReflectionClass;
28
29
/**
30
 * The Fixed Array
31
 *
32
 * A FixedArray is a sequence of values in a contiguous buffer that grows and
33
 * shrinks automatically. It’s the most efficient sequential structure because
34
 * a value’s index is a direct mapping to its index in the buffer, and the
35
 * growth factor isn't bound to a specific multiple or exponent.
36
 *
37
 * @package structures
38
 * @author Ulises Jeremias Cornejo Fandos <[email protected]>
39
 */
40
41
class FixedArray implements SequenceableInterface
42
{
43
    use Traits\Sequenceable;
44
45
    // The secondary flash array - fixed array
46
    protected $sfa = null;
47
48
    /**
49
     * Create an fixed array
50
     *
51
     * @param Traversable $fixed data guaranteed to be immutable
52
     */
53
    protected function __construct(Traversable $fixed)
54
    {
55
        $this->sfa = $fixed;
56
    }
57
58
    public function toArray(): array
59
    {
60
        return $this->sfa->toArray();
0 ignored issues
show
Bug introduced by
The method toArray() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as MongoDB\Driver\Cursor or Guzzle\Http\Message\Header\HeaderCollection or Guzzle\Http\Message\Header\HeaderInterface or http\QueryString or Guzzle\Common\Event or Guzzle\Common\Collection or Mbh\Collection\Interfaces\Collection or Mbh\Iterator\SliceIterator or SplFixedArray or Guzzle\Service\Resource\ResourceIteratorInterface or Mbh\Iterator\ConcatIterator or Guzzle\Iterator\MethodProxyIterator or Mbh\Iterator\ConcatIterator or Mbh\Iterator\SliceIterator or Mbh\Collection\CallbackHeap. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        return $this->sfa->/** @scrutinizer ignore-call */ toArray();
Loading history...
61
    }
62
63
    private function validIndex(int $index)
64
    {
65
        return $index >= 0 && $index < count($this);
66
    }
67
68
    /**
69
     * Countable
70
     */
71
    public function count(): int
72
    {
73
        return count($this->sfa);
0 ignored issues
show
Bug introduced by
$this->sfa of type Traversable is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
        return count(/** @scrutinizer ignore-type */ $this->sfa);
Loading history...
74
    }
75
76
    /**
77
     * Iterator
78
     */
79
    public function current()
80
    {
81
        return $this->sfa->current();
0 ignored issues
show
Bug introduced by
The method current() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as IntlCodePointBreakIterator or IntlRuleBasedBreakIterator or Iterator or IntlBreakIterator or MongoGridFSCursor or SimpleXMLIterator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
        return $this->sfa->/** @scrutinizer ignore-call */ current();
Loading history...
82
    }
83
84
    public function key(): int
85
    {
86
        return $this->sfa->key();
0 ignored issues
show
Bug introduced by
The method key() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as Iterator or MongoGridFSCursor or SimpleXMLIterator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
        return $this->sfa->/** @scrutinizer ignore-call */ key();
Loading history...
87
    }
88
89
    public function next()
90
    {
91
        return $this->sfa->next();
0 ignored issues
show
Bug introduced by
The method next() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as IntlCodePointBreakIterator or IntlRuleBasedBreakIterator or Iterator or IntlBreakIterator or MongoGridFSCursor or SimpleXMLIterator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
        return $this->sfa->/** @scrutinizer ignore-call */ next();
Loading history...
92
    }
93
94
    public function rewind()
95
    {
96
        return $this->sfa->rewind();
0 ignored issues
show
Bug introduced by
The method rewind() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as Iterator or MongoGridFSCursor or SimpleXMLIterator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
        return $this->sfa->/** @scrutinizer ignore-call */ rewind();
Loading history...
97
    }
98
99
    public function valid()
100
    {
101
        return $this->sfa->valid();
0 ignored issues
show
Bug introduced by
The method valid() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as Iterator or MongoGridFSCursor or SimpleXMLIterator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
        return $this->sfa->/** @scrutinizer ignore-call */ valid();
Loading history...
102
    }
103
104
    /**
105
     * ArrayAccess
106
     */
107
    public function offsetExists($offset): bool
108
    {
109
        return is_integer($offset)
110
            && $this->validIndex($offset)
111
            && $this->sfa->offsetExists($offset);
0 ignored issues
show
Bug introduced by
The method offsetExists() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as Threaded or SimpleXMLElement or Thread or Worker or Stackable or Guzzle\Http\Message\Header\HeaderCollection or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Guzzle\Common\Event or Guzzle\Common\Collection or ArrayObject or SplDoublyLinkedList or Mbh\Iterator\SliceIterator or SplFixedArray or SplObjectStorage or Mbh\Iterator\ConcatIterator or Mbh\Collection\Interfaces\Sequenceable or CachingIterator or Guzzle\Iterator\MethodProxyIterator or Mbh\Iterator\ConcatIterator or Mbh\Iterator\SliceIterator or Phar or ArrayIterator or Phar or Phar or RecursiveCachingIterator or RecursiveArrayIterator or SimpleXMLIterator or Phar. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

111
            && $this->sfa->/** @scrutinizer ignore-call */ offsetExists($offset);
Loading history...
112
    }
113
114
    public function offsetGet($offset)
115
    {
116
        return $this->sfa->offsetGet($offset);
0 ignored issues
show
Bug introduced by
The method offsetGet() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as Threaded or SimpleXMLElement or Thread or Worker or Stackable or Guzzle\Http\Message\Header\HeaderCollection or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Guzzle\Common\Event or Guzzle\Common\Collection or ArrayObject or SplDoublyLinkedList or Mbh\Iterator\SliceIterator or SplFixedArray or SplObjectStorage or Mbh\Iterator\ConcatIterator or Mbh\Collection\Interfaces\Sequenceable or CachingIterator or Guzzle\Iterator\MethodProxyIterator or Mbh\Iterator\ConcatIterator or Mbh\Iterator\SliceIterator or Phar or ArrayIterator or Phar or Phar or RecursiveCachingIterator or RecursiveArrayIterator or SimpleXMLIterator or Phar. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

116
        return $this->sfa->/** @scrutinizer ignore-call */ offsetGet($offset);
Loading history...
117
    }
118
119
    public function offsetSet($offset, $value)
120
    {
121
        return is_integer($offset)
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_integer($offse...setSet($offset, $value) returns the type boolean which is incompatible with the return type mandated by ArrayAccess::offsetSet() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
122
            && $this->validIndex($offset)
123
            && $this->sfa->offsetSet($offset, $value);
0 ignored issues
show
Bug introduced by
The method offsetSet() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as Threaded or SimpleXMLElement or Thread or Worker or Stackable or Guzzle\Http\Message\Header\HeaderCollection or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Guzzle\Common\Event or Guzzle\Common\Collection or ArrayObject or SplDoublyLinkedList or Mbh\Iterator\SliceIterator or SplFixedArray or SplObjectStorage or Mbh\Iterator\ConcatIterator or Mbh\Collection\Interfaces\Sequenceable or CachingIterator or Guzzle\Iterator\MethodProxyIterator or Mbh\Iterator\ConcatIterator or Mbh\Iterator\SliceIterator or Phar or ArrayIterator or Phar or Phar or RecursiveCachingIterator or RecursiveArrayIterator or SimpleXMLIterator or Phar. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

123
            && $this->sfa->/** @scrutinizer ignore-call */ offsetSet($offset, $value);
Loading history...
124
    }
125
126
    public function offsetUnset($offset)
127
    {
128
        return is_integer($offset)
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_integer($offse...a->offsetUnset($offset) returns the type boolean which is incompatible with the return type mandated by ArrayAccess::offsetUnset() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
129
            && $this->validIndex($offset)
130
            && $this->sfa->offsetUnset($offset);
0 ignored issues
show
Bug introduced by
The method offsetUnset() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as Threaded or SimpleXMLElement or Thread or Worker or Stackable or Guzzle\Http\Message\Header\HeaderCollection or http\QueryString or Symfony\Component\EventDispatcher\GenericEvent or Guzzle\Common\Event or Guzzle\Common\Collection or ArrayObject or SplDoublyLinkedList or Mbh\Iterator\SliceIterator or SplFixedArray or SplObjectStorage or Mbh\Iterator\ConcatIterator or Mbh\Collection\Interfaces\Sequenceable or CachingIterator or Guzzle\Iterator\MethodProxyIterator or Mbh\Iterator\ConcatIterator or Mbh\Iterator\SliceIterator or Phar or ArrayIterator or Phar or Phar or RecursiveCachingIterator or RecursiveArrayIterator or SimpleXMLIterator or Phar. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

130
            && $this->sfa->/** @scrutinizer ignore-call */ offsetUnset($offset);
Loading history...
131
    }
132
133
    public function clear()
134
    {
135
        return $this->sfa->clear();
0 ignored issues
show
Bug introduced by
The method clear() does not exist on Traversable. It seems like you code against a sub-type of Traversable such as Guzzle\Plugin\History\HistoryPlugin or Guzzle\Http\Message\Header\HeaderCollection or Guzzle\Common\Collection or Mbh\Iterator\SliceIterator or Imagick or ImagickPixelIterator or Mbh\Collection\FixedArray or Guzzle\Iterator\MethodProxyIterator or Mbh\Iterator\SliceIterator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

135
        return $this->sfa->/** @scrutinizer ignore-call */ clear();
Loading history...
136
    }
137
138
    protected function getMainTraversable(): Traversable
139
    {
140
        return $this->sfa;
141
    }
142
143
    protected function setTraversable(Traversable $traversable)
144
    {
145
        $this->sfa = $traversable;
146
    }
147
}
148