1: <?php declare(strict_types=1);
2:
3: namespace Salient\Collection;
4:
5: use Salient\Contract\Collection\CollectionInterface;
6: use Salient\Contract\Core\Immutable;
7: use Salient\Core\Concern\HasMutator;
8: use Salient\Core\Concern\ImmutableArrayAccessTrait;
9:
10: /**
11: * Implements CollectionInterface for immutable collections
12: *
13: * Mutable collections should use {@see CollectionTrait} instead.
14: *
15: * @see CollectionInterface
16: *
17: * @api
18: *
19: * @template TKey of array-key
20: * @template TValue
21: *
22: * @phpstan-require-implements CollectionInterface
23: * @phpstan-require-implements Immutable
24: */
25: trait ImmutableCollectionTrait
26: {
27: /** @use CollectionTrait<TKey,TValue> */
28: use CollectionTrait;
29: /** @use ImmutableArrayAccessTrait<TKey,TValue> */
30: use ImmutableArrayAccessTrait {
31: ImmutableArrayAccessTrait::offsetSet insteadof CollectionTrait;
32: ImmutableArrayAccessTrait::offsetUnset insteadof CollectionTrait;
33: }
34: use HasMutator;
35:
36: /**
37: * @return static
38: */
39: protected function maybeClone()
40: {
41: return clone $this;
42: }
43: }
44: