1 | <?php namespace BuildR\Collection\Collection; |
||
18 | trait StrictlyTypedCollectionTrait { |
||
19 | |||
20 | /** |
||
21 | * @type NULL|callable |
||
22 | */ |
||
23 | protected $typeChecker; |
||
24 | |||
25 | /** |
||
26 | * @type NULL|string |
||
27 | */ |
||
28 | protected $typeCheckFailMessage; |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | public function setStrictType(callable $typeCheck, $message = NULL) { |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | public function isStrict() { |
||
44 | |||
45 | /** |
||
46 | * Executes the type check if the collection is strict. Always |
||
47 | * returns true, when the collection is not strictly typed |
||
48 | * |
||
49 | * @param mixed $value |
||
50 | * |
||
51 | * @return bool |
||
52 | * |
||
53 | * @throws \BuildR\Collection\Exception\CollectionException |
||
54 | */ |
||
55 | protected function doTypeCheck($value) { |
||
68 | |||
69 | } |
||
70 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.