dzikismigol /
barenote-sdk-php
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace Barenote\Collection; |
||
| 3 | |||
| 4 | use ArrayIterator; |
||
| 5 | use Closure; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Class ArrayCollection |
||
| 9 | * @package Barenote\Collection |
||
| 10 | */ |
||
| 11 | class ArrayCollection implements \Countable, \IteratorAggregate, \ArrayAccess, \JsonSerializable |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var array |
||
| 15 | */ |
||
| 16 | private $elements; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * ArrayCollection constructor. |
||
| 20 | * @param array $elements |
||
| 21 | */ |
||
| 22 | public function __construct(array $elements = []) |
||
| 23 | { |
||
| 24 | $this->elements = $elements; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function isEmpty() |
||
| 28 | { |
||
| 29 | return count($this->elements) == 0; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function first() |
||
|
0 ignored issues
–
show
|
|||
| 33 | { |
||
| 34 | return reset($this->elements); |
||
| 35 | } |
||
| 36 | public function firstOrNull() |
||
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a Loading history...
|
|||
| 37 | { |
||
| 38 | if ($result = $this->first()) { |
||
| 39 | return $result; |
||
| 40 | } |
||
| 41 | return null; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param $value |
||
| 46 | */ |
||
| 47 | public function add($value) |
||
| 48 | { |
||
| 49 | $this->elements[] = $value; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Clear the internal array |
||
| 54 | */ |
||
| 55 | public function clear() |
||
| 56 | { |
||
| 57 | $this->elements = []; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Checks if collection contains provided element. |
||
| 62 | * |
||
| 63 | * @param $element |
||
| 64 | * |
||
| 65 | * @return bool |
||
| 66 | */ |
||
| 67 | public function contains($element) |
||
| 68 | { |
||
| 69 | return in_array($element, $this->elements, true); |
||
| 70 | } |
||
| 71 | |||
| 72 | public function getIterator() |
||
| 73 | { |
||
| 74 | return new ArrayIterator($this->elements); |
||
| 75 | } |
||
| 76 | |||
| 77 | public function offsetExists($offset) |
||
| 78 | { |
||
| 79 | return $this->containsKey($offset); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Checks if collection contains provided key. |
||
| 84 | * |
||
| 85 | * @param $key |
||
| 86 | * |
||
| 87 | * @return bool |
||
| 88 | */ |
||
| 89 | public function containsKey($key) |
||
| 90 | { |
||
| 91 | return isset($this->elements[$key]) || array_key_exists($key, $this->elements); |
||
| 92 | } |
||
| 93 | |||
| 94 | public function offsetGet($offset) |
||
| 95 | { |
||
| 96 | return $this->get($offset); |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @param $key |
||
| 101 | * @return mixed|null |
||
| 102 | */ |
||
| 103 | public function get($key) |
||
| 104 | { |
||
| 105 | if (isset($this->elements[$key])) { |
||
| 106 | return $this->elements[$key]; |
||
| 107 | } |
||
| 108 | |||
| 109 | return null; |
||
| 110 | } |
||
| 111 | |||
| 112 | public function offsetSet($offset, $value) |
||
| 113 | { |
||
| 114 | $this->set($offset, $value); |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @param $key |
||
| 119 | * @param $element |
||
| 120 | */ |
||
| 121 | public function set($key, $element) |
||
| 122 | { |
||
| 123 | $this->elements[$key] = $element; |
||
| 124 | } |
||
| 125 | |||
| 126 | public function offsetUnset($offset) |
||
| 127 | { |
||
| 128 | $this->remove($offset); |
||
| 129 | } |
||
| 130 | |||
| 131 | public function remove($key) |
||
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a Loading history...
|
|||
| 132 | { |
||
| 133 | if (isset($this->elements[$key]) || array_key_exists($key, $this->elements)) { |
||
| 134 | $removed = $this->elements[$key]; |
||
| 135 | unset($this->elements[$key]); |
||
| 136 | |||
| 137 | return $removed; |
||
| 138 | } |
||
| 139 | |||
| 140 | return null; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function count() |
||
| 144 | { |
||
| 145 | return count($this->elements); |
||
| 146 | } |
||
| 147 | |||
| 148 | public function jsonSerialize() |
||
| 149 | |||
| 150 | { |
||
| 151 | return $this->toArray(); |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @return array |
||
| 156 | */ |
||
| 157 | public function toArray() |
||
| 158 | { |
||
| 159 | return $this->elements; |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * {@inheritdoc} |
||
| 164 | */ |
||
| 165 | public function filter(Closure $p) |
||
| 166 | { |
||
| 167 | return new static(array_filter($this->elements, $p)); |
||
| 168 | } |
||
| 169 | |||
| 170 | protected function extractProperties($propertyFetchMethod) |
||
| 171 | { |
||
| 172 | $values = []; |
||
| 173 | $this->forAll( |
||
| 174 | function ($entry) use (&$values, $propertyFetchMethod) { |
||
| 175 | $values[] = $entry->{$propertyFetchMethod}(); |
||
| 176 | } |
||
| 177 | ); |
||
| 178 | |||
| 179 | return $values; |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @param callable|Closure $p |
||
| 184 | */ |
||
| 185 | public function forAll(Closure $p) |
||
| 186 | { |
||
| 187 | foreach ($this->elements as $key => $element) { |
||
| 188 | $p($element, $key); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.