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.
Passed
Push — master ( b6fac6...dceac4 )
by Dušan
01:15
created

GroupingFlightsTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 79
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
1
<?php
2
3
namespace DusanKasan\Knapsack\Tests\Scenarios;
4
5
use DusanKasan\Knapsack\Collection;
6
use PHPUnit_Framework_TestCase;
7
8
/**
9
 * More advanced usage of collection pipeline, see
10
 * http://martinfowler.com/articles/refactoring-pipelines.html#GroupingFlightRecords for reference.
11
 */
12
class GroupingFlightsTest extends PHPUnit_Framework_TestCase
13
{
14
    private $inputData = [
15
        [
16
            "origin" => "BOS",
17
            "dest" => "LAX",
18
            "date" => "2015-01-12",
19
            "number" => "25",
20
            "carrier" => "AA",
21
            "delay" => 10.0,
22
            "cancelled" => false
23
        ],
24
        [
25
            "origin" => "BOS",
26
            "dest" => "LAX",
27
            "date" => "2015-01-13",
28
            "number" => "25",
29
            "carrier" => "AA",
30
            "delay" => 0.0,
31
            "cancelled" => true
32
        ],
33
    ];
34
35
    public function testIt()
36
    {
37
        $collection = new Collection($this->inputData);
38
39
        $result = $collection
40
            ->groupBy(function ($v) {
41
                return $v['dest'];
42
            })
43
            ->map([$this, 'summarize'])
44
            ->map([$this, 'buildResults'])
45
            ->toArray();
46
47
        $expected = [
48
            'LAX' => [
49
                'meanDelay' => 10,
50
                'cancellationRate' => 0.5
51
            ]
52
        ];
53
54
        $this->assertEquals($expected, $result);
55
    }
56
57
    public function summarize(Collection $flights)
58
    {
59
        $numCancellations = $flights
60
            ->filter(function ($f) {
61
                return $f['cancelled'];
62
            })
63
            ->size();
64
65
        $totalDelay = $flights
66
            ->reject(function ($f) {
67
                return $f['cancelled'];
68
            })
69
            ->reduce(
70
                function ($tmp, $f) {
71
                    return $tmp + $f['delay'];
72
                },
73
                0
74
            );
75
76
        return [
77
            'numFlights' => $flights->size(),
78
            'numCancellations' => $numCancellations,
79
            'totalDelay' => $totalDelay
80
        ];
81
    }
82
83
    public function buildResults(array $airport)
84
    {
85
        return [
86
            'meanDelay' => $airport['totalDelay'] / ($airport['numFlights'] - $airport['numCancellations']),
87
            'cancellationRate' => $airport['numCancellations'] / $airport['numFlights']
88
        ];
89
    }
90
}
91