1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Collection; |
4: | |
5: | use Salient\Contract\Collection\CollectionInterface; |
6: | |
7: | /** |
8: | * @api |
9: | * |
10: | * @template TKey of array-key |
11: | * @template TValue |
12: | * @template TKeyless |
13: | * |
14: | * @phpstan-require-implements CollectionInterface |
15: | */ |
16: | trait CollectionTrait |
17: | { |
18: | /** @use DictionaryTrait<TKey,TValue> */ |
19: | use DictionaryTrait; |
20: | |
21: | /** |
22: | * @inheritDoc |
23: | */ |
24: | public function add($value) |
25: | { |
26: | $items = $this->Items; |
27: | $items[] = $value; |
28: | /** @var TKeyless */ |
29: | return $this->replaceItems($items, true); |
30: | } |
31: | |
32: | /** |
33: | * @inheritDoc |
34: | */ |
35: | public function push(...$items) |
36: | { |
37: | if (!$items) { |
38: | /** @var TKeyless */ |
39: | return $this; |
40: | } |
41: | $_items = $this->Items; |
42: | array_push($_items, ...$items); |
43: | /** @var TKeyless */ |
44: | return $this->replaceItems($_items, true); |
45: | } |
46: | |
47: | /** |
48: | * @inheritDoc |
49: | */ |
50: | public function unshift(...$items) |
51: | { |
52: | if (!$items) { |
53: | /** @var TKeyless */ |
54: | return $this; |
55: | } |
56: | $_items = $this->Items; |
57: | array_unshift($_items, ...$items); |
58: | /** @var TKeyless */ |
59: | return $this->replaceItems($_items, true); |
60: | } |
61: | } |
62: |