|
1
|
|
|
<?php |
|
2
|
|
|
namespace Jmw\Collection; |
|
3
|
|
|
|
|
4
|
|
|
use Jmw\Collection\Exception\UnsupportedOperationException; |
|
5
|
|
|
/** |
|
6
|
|
|
* This trait is ensures immutability by throwing an exception |
|
7
|
|
|
* on all mutable CollectionInterface methods |
|
8
|
|
|
* @author john |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
trait ImmutableCollectionTrait |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* add is not supported by immutable objects. |
|
15
|
|
|
* @param multitype $element |
|
16
|
|
|
* @throws UnsupportedOperationException |
|
17
|
|
|
*/ |
|
18
|
|
|
public function add($element) |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
throw new UnsupportedOperationException('add'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* addAll is not supported by immutable objects. |
|
25
|
|
|
* @param CollectionInterface $collection |
|
26
|
|
|
* @throws UnsupportedOperationException |
|
27
|
|
|
*/ |
|
28
|
|
|
public function addAll(CollectionInterface $collection) |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
throw new UnsupportedOperationException('addAll'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* clear is not supported by immutable objects. |
|
35
|
|
|
* @throws UnsupportedOperationException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function clear() |
|
38
|
|
|
{ |
|
39
|
|
|
throw new UnsupportedOperationException('clear'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Remove is not supported by immutable objects. |
|
44
|
|
|
* @param multitype $element |
|
45
|
|
|
* @throws UnsupportedOperationException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function remove($element) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
throw new UnsupportedOperationException('remove'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* removeAll is not supported by immutable objects. |
|
54
|
|
|
* @param CollectionInterface $collection |
|
55
|
|
|
*/ |
|
56
|
|
|
public function removeAll(CollectionInterface $collection) |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
throw new UnsupportedOperationException('removeAll'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* retainAll is not supported by immutable objects. |
|
63
|
|
|
* @param CollectionInterface $collection |
|
64
|
|
|
* @throws UnsupportedOperationException |
|
65
|
|
|
*/ |
|
66
|
|
|
public function retainAll(CollectionInterface $collection) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
throw new UnsupportedOperationException('retainAll'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.