1 | <?php |
||
50 | class ExtractFirstItemWithContent |
||
51 | { |
||
52 | /** |
||
53 | * extract the first item from a dataset. if the dataset is empty, or all |
||
54 | * the content is empty, return the default value |
||
55 | * |
||
56 | * @param mixed $data |
||
57 | * the data to filter |
||
58 | * @param mixed $default |
||
59 | * the data to return when we cannot filter $data |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public function __invoke($data, $default) |
||
66 | |||
67 | /** |
||
68 | * extract the first item from a dataset. if the dataset is empty, or all |
||
69 | * the content is empty, return the default value |
||
70 | * |
||
71 | * @param mixed $data |
||
72 | * the data to filter |
||
73 | * @param mixed $default |
||
74 | * the data to return when we cannot filter $data |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public static function from($data, $default) |
||
82 | |||
83 | /** |
||
84 | * extract the first item from a dataset held in a string. if the string |
||
85 | * is empty, return the default value |
||
86 | * |
||
87 | * we assume that the string contains space-separated items |
||
88 | * |
||
89 | * @param string $data |
||
90 | * the data to filter |
||
91 | * @param mixed $default |
||
92 | * the data to return when we cannot filter $data |
||
93 | * @return mixed |
||
94 | */ |
||
95 | private static function fromString($data, $default) |
||
106 | |||
107 | /** |
||
108 | * extract the first item from a dataset |
||
109 | * |
||
110 | * @param array|Traversable $data |
||
111 | * the data to filter |
||
112 | * @param mixed $default |
||
113 | * the data to return when we cannot filter $data |
||
114 | * @return mixed |
||
115 | */ |
||
116 | private static function fromTraversable($data, $default) |
||
131 | |||
132 | /** |
||
133 | * called when we've been given a data type we do not support |
||
134 | * |
||
135 | * @param mixed $data |
||
136 | * the data to filter |
||
137 | * @param mixed $default |
||
138 | * the data to return when we cannot filter $data |
||
139 | * @return mixed |
||
140 | */ |
||
141 | private static function nothingMatchesTheInputType($data, $default) |
||
145 | |||
146 | /** |
||
147 | * lookup map of how to convert which data type |
||
148 | * |
||
149 | * @var array |
||
150 | */ |
||
151 | private static $dispatchMap = [ |
||
152 | 'String' => 'fromString', |
||
153 | 'Traversable' => 'fromTraversable' |
||
154 | ]; |
||
155 | } |
||
156 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.