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.

PlaylistExporter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 93
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B exportToFile() 0 57 5
A performersByInstrument() 0 17 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: wechsler
5
 * Date: 28/10/15
6
 * Time: 08:11
7
 */
8
9
namespace Phase\TakeATicket;
10
11
use Doctrine\DBAL\Connection;
12
use Phase\TakeATicket\DataSource\Factory;
13
14
class PlaylistExporter
15
{
16
    /**
17
     * @var Connection
18
     */
19
    protected $dbConn;
20
21
    /**
22
     * PlaylistExporter constructor.
23
     *
24
     * @param Connection $dbConn
25
     */
26
    public function __construct(Connection $dbConn)
27
    {
28
        $this->dbConn = $dbConn;
29
    }
30
31
    public function exportToFile($outFile)
32
    {
33
        $dataSource = Factory::datasourceFromDbConnection($this->dbConn);
34
35
        $tickets = $dataSource->fetchPerformedTickets();
36
37
        $handle = fopen($outFile, 'w');
38
39
        if ($handle === false) {
40
            echo "Failed to open '$outFile'\n";
41
        }
42
43
        $title = [
44
            'Ticket Id',
45
            'Start Time',
46
            'Song Id',
47
            'Artist',
48
            'Title',
49
            'Duration (seconds)',
50
            'Band Name',
51
            'Vocals',
52
            'Guitar',
53
            'Bass',
54
            'Drums',
55
            'Keytar',
56
            'RB3',
57
            'RB4',
58
        ];
59
60
        fputcsv($handle, $title);
61
62
        foreach ($tickets as $ticket) {
63
            $band = $ticket['band'];
64
65
            $line = [
66
                $ticket['id'],
67
                date('H:i:s', $ticket['startTime']),
68
                $ticket['song']['id'],
69
                $ticket['song']['artist'],
70
                $ticket['song']['title'],
71
                $ticket['song']['duration'],
72
                $ticket['title'],
73
                $this->performersByInstrument($band, 'V'),
74
                $this->performersByInstrument($band, 'G'),
75
                $this->performersByInstrument($band, 'B'),
76
                $this->performersByInstrument($band, 'D'),
77
                $this->performersByInstrument($band, 'K'),
78
                $ticket['song']['inRb3'] ? 'x' : '',
79
                $ticket['song']['inRb4'] ? 'x' : '',
80
            ];
81
82
            fputcsv($handle, $line);
83
        }
84
        fputcsv($handle, ['ENDS']);
85
86
//        echo "\n Wrote to '$outFile'\n";
87
    }
88
89
    public function performersByInstrument($band, $instrument)
90
    {
91
        $performers = '';
92
93
        if (is_array($band) && !empty($band[$instrument])) {
94
            $performers = array_map(
95
                function ($performer) {
96
                    return $performer['performerName'];
97
                },
98
                $band[$instrument]
99
            );
100
101
            $performers = implode(', ', $performers);
102
        }
103
104
        return $performers;
105
    }
106
}
107