Code Duplication    Length = 13-13 lines in 2 locations

src/Zicht/Itertools/filters.php 2 locations

@@ 153-165 (lines=13) @@
150
    $strategy = conversions\mixed_to_value_getter($strategy);
151
152
    // Support DateTimeInterface
153
    if ($expected instanceof \DateTimeInterface) {
154
        return function ($value, $key = null) use ($expected, $strategy, $orEqual) {
155
            $value = $strategy($value, $key);
156
            // Try to convert strings that look like ISO date format
157
            if (is_string($value) && preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}/', $value)) {
158
                try {
159
                    $value = new \DateTimeImmutable($value);
160
                } catch (\Exception $exception) {
161
                }
162
            }
163
            return $value instanceof \DateTimeInterface && ($orEqual ? $expected <= $value : $expected < $value);
164
        };
165
    }
166
167
    // Support numbers
168
    if (is_int($expected) || is_float($expected)) {
@@ 200-212 (lines=13) @@
197
    $strategy = conversions\mixed_to_value_getter($strategy);
198
199
    // Support DateTimeInterface
200
    if ($expected instanceof \DateTimeInterface) {
201
        return function ($value, $key = null) use ($expected, $strategy, $orEqual) {
202
            $value = $strategy($value, $key);
203
            // Try to convert strings that look like ISO date format
204
            if (is_string($value) && preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}/', $value)) {
205
                try {
206
                    $value = new \DateTimeImmutable($value);
207
                } catch (\Exception $exception) {
208
                }
209
            }
210
            return $value instanceof \DateTimeInterface && ($orEqual ? $expected >= $value : $expected > $value);
211
        };
212
    }
213
214
    // Support numbers
215
    if (is_int($expected) || is_float($expected)) {