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

RateFilter   B

Complexity

Total Complexity 37

Size/Duplication

Total Lines 108
Duplicated Lines 37.04 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 37
c 1
b 0
f 0
lcom 1
cbo 1
dl 40
loc 108
ccs 0
cts 85
cp 0
rs 8.6

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
C matches() 0 22 9
A matchesCurrencyCode() 0 8 3
A matchesCurrencyCodes() 8 8 3
A matchesDateFrom() 8 8 3
A matchesDateTo() 8 8 3
A matchesOnDate() 0 8 3
A matchesRateType() 0 8 3
A matchesRateTypes() 8 8 3
A matchesSource() 0 8 3
A matchesSources() 8 8 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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