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.

SimpleKaraokeRowMapper::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: wechsler
5
 * Date: 03/03/2017
6
 * Time: 18:11
7
 */
8
9
namespace Phase\TakeATicket\SongLoader;
10
11
use Doctrine\DBAL\Exception\InvalidArgumentException;
12
use Phase\TakeATicket\DataSource\AbstractSql;
13
use Phase\TakeATicket\Model\Instrument;
14
use Phase\TakeATicket\Model\Platform;
15
use Phase\TakeATicket\Model\Song;
16
use Phase\TakeATicket\Model\Source;
17
18
/**
19
 * Imports an XLS file with Column A: Artist, B: Song Title, C: Duration (min:sec)
20
 */
21
class SimpleKaraokeRowMapper implements RowMapperInterface
22
{
23
24
    const INPUT_FIELD_ARTIST = 'artist';
25
    const INPUT_FIELD_TITLE = 'title';
26
    const INPUT_FIELD_DURATION_MMSS = 'duration_mmss';
27
    const INPUT_FIELD_DURATION = 'duration';
28
29
    /**
30
     * Column map for input file
31
     *
32
     * @var string[]
33
     */
34
    protected $fileFields = [
35
        'A' => self::INPUT_FIELD_ARTIST,
36
        'B' => self::INPUT_FIELD_TITLE,
37
        'C' => self::INPUT_FIELD_DURATION_MMSS,
38
    ];
39
40
    protected $fieldLookup = [];
41
42
    /**
43
     * @var AbstractSql
44
     */
45
    protected $dataStore;
46
47
    /**
48
     * @var Instrument
49
     */
50
    protected $vocals;
51
52
    /**
53
     * @var Platform
54
     */
55
    protected $platform;
56
57
    /**
58
     * @var Platform
59
     */
60
    protected $source;
61
62
    /**
63
     * RclRowMapper constructor.
64
     * @param $dataStore
65
     */
66
    public function __construct(AbstractSql $dataStore)
67
    {
68
        $this->dataStore = $dataStore;
69
        $this->fieldLookup = array_flip($this->fileFields);
70
    }
71
72
    /**
73
     * Get formatter name for interface / selection
74
     *
75
     * @return string
76
     */
77
    public function getFormatterName()
78
    {
79
        return 'Simple Karaoke formatter';
80
    }
81
82
    protected function getDefaultPlatformName()
83
    {
84
        return 'Karaoke';
85
    }
86
87
    /**
88
     * Initialise the RowMapper
89
     *
90
     * @return void
91
     */
92
    public function init()
93
    {
94
        $vocals = (new Instrument())->setId(1)->setName('Vocals')->setAbbreviation('V');
95
        $this->dataStore->storeInstrument($vocals);
96
        $this->vocals = $vocals;
97
98
        $platform = new Platform($this->getDefaultPlatformName());
99
        $this->dataStore->storePlatform($platform);
100
        $this->platform = $platform;
101
102
        $source = new Source('Karaoke');
103
        $this->dataStore->storeSource($source);
104
        $this->source = $source;
0 ignored issues
show
Documentation Bug introduced by
It seems like $source of type object<Phase\TakeATicket\Model\Source> is incompatible with the declared type object<Phase\TakeATicket\Model\Platform> of property $source.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
105
    }
106
107
    /**
108
     * Store a single spreadsheet row
109
     *
110
     * @param array $row Character-indexed flattened DB row
111
     * @return bool True on success
112
     * @throws \Doctrine\DBAL\Exception\InvalidArgumentException
113
     */
114
    public function storeRawRow(array $row)
115
    {
116
        $song = new Song();
117
        $song
118
            ->setArtist($row[$this->fieldLookup[self::INPUT_FIELD_ARTIST]])
119
            ->setTitle($row[$this->fieldLookup[self::INPUT_FIELD_TITLE]])
120
            ->setSourceId($this->source->getId());
121
122
        $durationMS = trim($row[$this->fieldLookup[self::INPUT_FIELD_DURATION_MMSS]]);
123 View Code Duplication
        if ($durationMS && preg_match('/^\s*(\d+):(\d+)\s*$/', $durationMS, $matches)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
124
            $song->setDuration(($matches[1] * 60) + $matches[2]);
125
        }
126
127
        $this->dataStore->storeSong($song); // need id below
128
129
        try {
130
            $this->dataStore->storeSongPlatformLinks($song->getId(), [$this->platform->getId()]);
131
            $this->dataStore->storeSongInstrumentLinks($song->getId(), [$this->vocals->getId()]);
132
        } catch (InvalidArgumentException $e) {
133
            trigger_error($e->getMessage(), E_USER_WARNING);
134
            return false;
135
        }
136
137
        return true;
138
    }
139
140
    /**
141
     * Get short name for form keys, CLI etc
142
     *
143
     * @return string
144
     */
145
    public function getShortName()
146
    {
147
        return 'Karaoke';
148
    }
149
}
150