LessThanEqualsDateFilter::match()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 3
nc 1
nop 3
1
<?php
2
/**
3
 * This file is part of the ArrayQuery package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace ArrayQuery\Filters\Criterion;
12
13
class LessThanEqualsDateFilter implements FilterInterface
14
{
15
    /**
16
     * @param $value
17
     * @param $valueToCompare
18
     * @return bool
19
     */
20
    public function match($value, $valueToCompare, $dateFormat = null)
21
    {
22
        $valueDate = \DateTimeImmutable::createFromFormat(($dateFormat) ?: 'Y-m-d', $value);
23
        $valueToComapareDate = \DateTimeImmutable::createFromFormat(($dateFormat) ?: 'Y-m-d', $valueToCompare);
24
25
        return $valueDate <= $valueToComapareDate;
26
    }
27
}
28