Completed
Push — master ( 17fbce...9c0ecb )
by Nikola
02:12
created

RateFilter::matchesSource()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4286
cc 3
eloc 4
nc 2
nop 2
crap 12
1
<?php
2
3
namespace RunOpenCode\ExchangeRate\Utils;
4
5
use RunOpenCode\ExchangeRate\Contract\RateInterface;
6
7
final class RateFilter
8
{
9
    private function __construct() { }
10
11
    public static function matches(RateInterface $rate, array $criteria)
12
    {
13
        return
14
            self::matchesCurrencyCode($rate, $criteria)
15
            &&
16
            self::matchesCurrencyCodes($rate, $criteria)
17
            &&
18
            self::matchesDateFrom($rate, $criteria)
19
            &&
20
            self::matchesDateTo($rate, $criteria)
21
            &&
22
            self::matchesOnDate($rate, $criteria)
23
            &&
24
            self::matchesRateType($rate, $criteria)
25
            &&
26
            self::matchesRateTypes($rate, $criteria)
27
            &&
28
            self::matchesSource($rate, $criteria)
29
            &&
30
            self::matchesSources($rate, $criteria)
31
            ;
32
    }
33
34
    public static function matchesCurrencyCode(RateInterface $rate, array $criteria)
35
    {
36
        if (isset($criteria['currencyCode']) && $criteria['currencyCode'] != $rate->getCurrencyCode()) {
37
            return false;
38
        }
39
40
        return true;
41
    }
42
43 View Code Duplication
    public static function matchesCurrencyCodes(RateInterface $rate, array $criteria)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        if (isset($criteria['currencyCodes']) && !in_array($rate->getCurrencyCode(), $criteria['currencyCodes'])) {
46
            return false;
47
        }
48
49
        return true;
50
    }
51
52 View Code Duplication
    public static function matchesDateFrom(RateInterface $rate, array $criteria)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        if (isset($criteria['dateFrom']) && $criteria['dateFrom'] <= $rate->getDate()) {
55
            return false;
56
        }
57
58
        return true;
59
    }
60
61 View Code Duplication
    public static function matchesDateTo(RateInterface $rate, array $criteria)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
    {
63
        if (isset($criteria['dateTo']) && $criteria['dateTo'] >= $rate->getDate()) {
64
            return false;
65
        }
66
67
        return true;
68
    }
69
70
    public static function matchesOnDate(RateInterface $rate, array $criteria)
71
    {
72
        if (isset($criteria['onDate']) && $criteria['onDate']->format('Y-m-d') != $rate->getDate()->format('Y-m-d')) {
73
            return false;
74
        }
75
76
        return true;
77
    }
78
79
    public static function matchesRateType(RateInterface $rate, array $criteria)
80
    {
81
        if (isset($criteria['rateType']) && $criteria['rateType'] != $rate->getRateType()) {
82
            return false;
83
        }
84
85
        return true;
86
    }
87
88 View Code Duplication
    public static function matchesRateTypes(RateInterface $rate, array $criteria)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        if (isset($criteria['rateTypes']) && !in_array($rate->getRateType(), $criteria['rateTypes'])) {
91
            return false;
92
        }
93
94
        return true;
95
    }
96
97
    public static function matchesSource(RateInterface $rate, array $criteria)
98
    {
99
        if (isset($criteria['source']) && $criteria['source'] != $rate->getSourceName()) {
100
            return false;
101
        }
102
103
        return true;
104
    }
105
106 View Code Duplication
    public static function matchesSources(RateInterface $rate, array $criteria)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108
        if (isset($criteria['sources']) && !in_array($rate->getSourceName(), $criteria['sources'])) {
109
            return false;
110
        }
111
112
        return true;
113
    }
114
}
115