1 | <?php |
||
49 | class ExtractFirstItem |
||
50 | { |
||
51 | /** |
||
52 | * extract the first item from a dataset |
||
53 | * |
||
54 | * @param mixed $data |
||
55 | * the data to filter |
||
56 | * @param mixed $default |
||
57 | * the data to return when we cannot filter $data |
||
58 | * @return mixed |
||
59 | */ |
||
60 | public function __invoke($data, $default) |
||
64 | |||
65 | /** |
||
66 | * extract the first item from a dataset |
||
67 | * |
||
68 | * @param mixed $data |
||
69 | * the data to filter |
||
70 | * @param mixed $default |
||
71 | * the data to return when we cannot filter $data |
||
72 | * @return mixed |
||
73 | */ |
||
74 | public static function from($data, $default) |
||
79 | |||
80 | /** |
||
81 | * extract the first item from a dataset held in a string |
||
82 | * |
||
83 | * we take a very simplistic approach here, and assume that the string |
||
84 | * contains space-separated data |
||
85 | * |
||
86 | * @param string $data |
||
87 | * the data to filter |
||
88 | * @param mixed $default |
||
89 | * the data to return when we cannot filter $data |
||
90 | * @return mixed |
||
91 | */ |
||
92 | private static function fromString($data, $default) |
||
103 | |||
104 | /** |
||
105 | * extract the first item from a dataset |
||
106 | * |
||
107 | * @param array|Traversable $data |
||
108 | * the data to filter |
||
109 | * @param mixed $default |
||
110 | * the data to return when we cannot filter $data |
||
111 | * @return mixed |
||
112 | */ |
||
113 | private static function fromTraversable($data, $default) |
||
126 | |||
127 | /** |
||
128 | * called when we've been given a data type we do not support |
||
129 | * |
||
130 | * @param mixed $data |
||
131 | * the data to filter |
||
132 | * @param mixed $default |
||
133 | * the data to return when we cannot filter $data |
||
134 | * @return mixed |
||
135 | */ |
||
136 | private static function nothingMatchesTheInputType($data, $default) |
||
140 | |||
141 | /** |
||
142 | * lookup map of how to convert which data type |
||
143 | * |
||
144 | * @var array |
||
145 | */ |
||
146 | private static $dispatchMap = [ |
||
147 | 'String' => 'fromString', |
||
148 | 'Traversable' => 'fromTraversable' |
||
149 | ]; |
||
150 | } |
||
151 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.