Bit-Wasp /
bitcoin-php
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace BitWasp\Bitcoin\Script\Interpreter; |
||
| 4 | |||
| 5 | use BitWasp\Buffertools\BufferInterface; |
||
| 6 | |||
| 7 | class Stack extends \SplDoublyLinkedList implements StackInterface |
||
| 8 | { |
||
| 9 | 816 | public function __construct() |
|
| 10 | { |
||
| 11 | 816 | $this->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 12 | 816 | } |
|
| 13 | |||
| 14 | public function bottom() |
||
| 15 | { |
||
| 16 | return parent::offsetGet(count($this) - 1); |
||
|
0 ignored issues
–
show
|
|||
| 17 | } |
||
| 18 | 54 | ||
| 19 | /** |
||
| 20 | 54 | * @param mixed $value |
|
| 21 | * @throws \InvalidArgumentException |
||
| 22 | */ |
||
| 23 | 54 | private function typeCheck($value) |
|
| 24 | { |
||
| 25 | if (!$value instanceof BufferInterface) { |
||
| 26 | throw new \InvalidArgumentException('Value was not of type Buffer'); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | 486 | /** |
|
| 31 | * @see \ArrayAccess::offsetGet() |
||
| 32 | 486 | * @param int $offset |
|
| 33 | 486 | * @return \BitWasp\Buffertools\Buffer |
|
| 34 | */ |
||
| 35 | public function offsetGet($offset) |
||
| 36 | { |
||
| 37 | $offset = count($this) + $offset; |
||
| 38 | return parent::offsetGet($offset); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | 36 | * @see \ArrayAccess::offsetSet() |
|
| 43 | * @param int $offset |
||
| 44 | 36 | * @param BufferInterface $value |
|
| 45 | 36 | * @throws \InvalidArgumentException |
|
| 46 | 36 | */ |
|
| 47 | 36 | public function offsetSet($offset, $value) |
|
| 48 | { |
||
| 49 | $this->typeCheck($value); |
||
| 50 | $offset = count($this) + $offset; |
||
| 51 | parent::offsetSet($offset, $value); |
||
| 52 | } |
||
| 53 | |||
| 54 | 6 | /** |
|
| 55 | * @see \ArrayAccess::offsetExists() |
||
| 56 | 6 | * @param int $offset |
|
| 57 | 6 | * @return bool |
|
| 58 | */ |
||
| 59 | public function offsetExists($offset) |
||
| 60 | { |
||
| 61 | $offset = count($this) + $offset; |
||
| 62 | return parent::offsetExists($offset); |
||
| 63 | } |
||
| 64 | 36 | ||
| 65 | /** |
||
| 66 | 36 | * @see \ArrayAccess::offsetUnset() |
|
| 67 | 36 | * @param int $offset |
|
| 68 | 30 | */ |
|
| 69 | public function offsetUnset($offset) |
||
| 70 | { |
||
| 71 | $offset = count($this) + $offset; |
||
| 72 | parent::offsetUnset($offset); |
||
| 73 | } |
||
| 74 | 24 | ||
| 75 | /** |
||
| 76 | 24 | * @param int $first |
|
| 77 | 24 | * @param int $second |
|
| 78 | 24 | */ |
|
| 79 | 24 | public function swap($first, $second) |
|
| 80 | 24 | { |
|
| 81 | $val1 = $this->offsetGet($first); |
||
| 82 | $val2 = $this->offsetGet($second); |
||
| 83 | $this->offsetSet($second, $val1); |
||
| 84 | $this->offsetSet($first, $val2); |
||
| 85 | } |
||
| 86 | 18 | ||
| 87 | /** |
||
| 88 | 18 | * @param int $index |
|
| 89 | * @param BufferInterface $value |
||
| 90 | 18 | */ |
|
| 91 | 9 | public function add($index, $value) |
|
| 92 | 3 | { |
|
| 93 | 3 | $this->typeCheck($value); |
|
| 94 | 6 | ||
| 95 | 6 | if (getenv('HHVM_VERSION') || version_compare(phpversion(), '5.5.0', 'lt')) { |
|
| 96 | 6 | if ($index == $this->count()) { |
|
| 97 | 6 | $this->push($value); |
|
| 98 | 6 | } else { |
|
| 99 | $size = count($this); |
||
| 100 | 3 | $temp = []; |
|
| 101 | 3 | for ($i = $size; $i > $index; $i--) { |
|
| 102 | 3 | array_unshift($temp, $this->pop()); |
|
| 103 | 3 | } |
|
| 104 | |||
| 105 | $this->push($value); |
||
| 106 | 6 | foreach ($temp as $value) { |
|
| 107 | 9 | $this->push($value); |
|
| 108 | } |
||
| 109 | 12 | } |
|
| 110 | |||
| 111 | } else { |
||
| 112 | parent::add($index, $value); |
||
| 113 | } |
||
| 114 | 684 | } |
|
| 115 | |||
| 116 | 684 | /** |
|
| 117 | 684 | * @return int |
|
| 118 | 684 | */ |
|
| 119 | public function end() |
||
| 120 | { |
||
| 121 | 12 | $count = count($this); |
|
| 122 | if ($count === 0) { |
||
| 123 | return 0; |
||
| 124 | } |
||
| 125 | |||
| 126 | return $count - 1; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param $length |
||
| 131 | * @return $this |
||
| 132 | */ |
||
| 133 | public function resize($length) |
||
| 134 | { |
||
| 135 | if ($length > count($this)) { |
||
| 136 | throw new \RuntimeException('Invalid start or length'); |
||
| 137 | } |
||
| 138 | |||
| 139 | while (count($this) > $length) { |
||
| 140 | $this->pop(); |
||
| 141 | } |
||
| 142 | |||
| 143 | return $this; |
||
| 144 | } |
||
| 145 | } |
||
| 146 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.