GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

DataSetCustomizer::customizeByRouteName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace JDolba\SlimHttpSmokeTesting;
5
6
class DataSetCustomizer
7
{
8
9
    /**
10
     * @var \JDolba\SlimHttpSmokeTesting\RequestDataSet[]
11
     */
12
    private $dataSets;
13
14 6
    public function __construct(array $dataSets)
15
    {
16 6
        $this->dataSets = $dataSets;
17 6
    }
18
19
    /**
20
     * invoke callback on all RequestDataSets
21
     * @param callable $callback
22
     * @return $this
23
     */
24 3
    public function customize(callable $callback): self
25
    {
26 3
        foreach ($this->dataSets as $dataSet) {
27 3
            $callback(
28 3
                $dataSet
29
            );
30
        }
31
32 3
        return $this;
33
    }
34
35
    /**
36
     * invoke callback on RequestDataSets matching routeName
37
     * @see \JDolba\SlimHttpSmokeTesting\RouteConfiguration\RouteConfigurationInterface::getRouteName()
38
     *
39
     * @param string $routeName
40
     * @param callable $callback
41
     * @return $this
42
     */
43
    public function customizeByRouteName(string $routeName, callable $callback): self
44
    {
45
        $this->customizeByConditionCallback(
46
            function (RequestDataSet $dataSet) use ($routeName) {
47
                return $dataSet->getRouteConfiguration()->getRouteName() === $routeName;
48
            },
49
            $callback
50
        );
51
52
        return $this;
53
    }
54
55
    /**
56
     * invoke callback on RequestDataSets matching routeName and http method
57
     * @see \JDolba\SlimHttpSmokeTesting\RouteConfiguration\RouteConfigurationInterface::getRouteName()
58
     * @see \JDolba\SlimHttpSmokeTesting\RequestDataSet::getMethod()
59
     *
60
     * @param string $routeName
61
     * @param string $method
62
     * @param callable $callback
63
     * @return $this
64
     */
65
    public function customizeByRouteNameAndMethod(string $routeName, string $method, callable $callback)
66
    {
67
        $this->customizeByConditionCallback(
68
            function (RequestDataSet $dataSet) use ($routeName, $method) {
69
                return $dataSet->getMethod() === $method
70
                    && $dataSet->getRouteConfiguration()->getRouteName() === $routeName;
71
            },
72
            $callback
73
        );
74
75
        return $this;
76
    }
77
78
    /**
79
     * invoke callback on RequestDataSet if conditionCallback on same RequestDataSet is evaluated as true
80
     *
81
     * @param callable $conditionCallback
82
     * @param callable $callback
83
     * @return $this
84
     */
85 3
    public function customizeByConditionCallback(callable $conditionCallback, callable $callback)
86
    {
87 3
        $found = [];
88 3
        foreach ($this->dataSets as $dataSet) {
89 3
            if (true === $conditionCallback($dataSet)) {
90 3
                $found[] = $dataSet;
91
            }
92
        }
93
94 3
        if (count($found) === 0) {
95
            throw new \InvalidArgumentException('No DataSet found by given callback');
96
        }
97
98 3
        foreach ($found as $dataSet) {
99 3
            $callback($dataSet);
100
        }
101
102 3
        return $this;
103
    }
104
}
105