Total Complexity | 5 |
Total Lines | 64 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | class With |
||
20 | { |
||
21 | private $thing; |
||
22 | |||
23 | /** |
||
24 | * The constructor. |
||
25 | * |
||
26 | * @param mixed $thing Any thing (but non-objects preferred). |
||
27 | */ |
||
28 | public function __construct($thing) |
||
29 | { |
||
30 | $this->thing = $thing; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * The method call is delegated to the thing initially `with`ed. |
||
35 | * |
||
36 | * By default The initial thing will be first parameter to the method to be called. |
||
37 | * You can change this behavior by suffixing underscore (_) to the method name. |
||
38 | * |
||
39 | * @param string $method |
||
40 | * @param array $things |
||
41 | * |
||
42 | * @return With |
||
43 | */ |
||
44 | public function __call(string $method, array $things): With |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Call as a function to get the final value! |
||
60 | * |
||
61 | * @return mixed |
||
62 | */ |
||
63 | public function __invoke() |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Pass the value via any callable and optionally extra arguments. |
||
70 | * |
||
71 | * @param callable $method |
||
72 | * @param array $things |
||
73 | * |
||
74 | * @return With |
||
75 | */ |
||
76 | public function via(callable $method, array $things = []): With |
||
83 | } |
||
84 | } |
||
85 |