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 ( 1eec8d...b3b44b )
by Richard
05:28 queued 02:13
created

RclKaraokeRowMapper::getShortName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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 the RCL XLS file but only loads fields relevant to solo karaoke performance
20
 */
21
class RclKaraokeRowMapper implements RowMapperInterface
22
{
23
24
    const INPUT_FIELD_ARTIST = 'artist';
25
    const INPUT_FIELD_TITLE = 'title';
26
//    const INPUT_FIELD_HAS_HARMONY = 'hasHarmony';
27
//    const INPUT_FIELD_HAS_KEYS = 'hasKeys';
28
//    const INPUT_FIELD_SOURCE = 'source';
29
//    const INPUT_FIELD_IN_RB3 = 'inRb3';
30
//    const INPUT_FIELD_IN_RB4 = 'inRb4';
31
    const INPUT_FIELD_DURATION_MMSS = 'duration_mmss';
32
    const INPUT_FIELD_DURATION = 'duration';
33
34
    /**
35
     * Column map for input file
36
     *
37
     * @var string[]
38
     */
39
    protected $fileFields = [
40
        'B' => self::INPUT_FIELD_ARTIST,
41
        'C' => self::INPUT_FIELD_TITLE,
42
//        'D' => self::INPUT_FIELD_HAS_HARMONY,
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
//        'E' => self::INPUT_FIELD_HAS_KEYS,
44
//        'I' => self::INPUT_FIELD_SOURCE,
45
//        'F' => self::INPUT_FIELD_IN_RB3,
46
//        'G' => self::INPUT_FIELD_IN_RB4,
47
        'H' => self::INPUT_FIELD_DURATION_MMSS,
48
    ];
49
50
    protected $fieldLookup = [];
51
52
    /**
53
     * @var AbstractSql
54
     */
55
    protected $dataStore;
56
57
    /**
58
     * @var Instrument
59
     */
60
    protected $vocals;
61
62
    /**
63
     * @var Platform
64
     */
65
    protected $platform;
66
67
    /**
68
     * @var Platform
69
     */
70
    protected $source;
71
72
    /**
73
     * RclRowMapper constructor.
74
     * @param $dataStore
75
     */
76
    public function __construct(AbstractSql $dataStore)
77
    {
78
        $this->dataStore = $dataStore;
79
        $this->fieldLookup = array_flip($this->fileFields);
80
    }
81
82
    /**
83
     * Get formatter name for interface / selection
84
     *
85
     * @return string
86
     */
87
    public function getFormatterName()
88
    {
89
        return 'RCL Karaoke formatter';
90
    }
91
92
    /**
93
     * Initialise the RowMapper
94
     *
95
     * @return void
96
     */
97
    public function init()
98
    {
99
        $vocals = (new Instrument())->setId(1)->setName('Vocals')->setAbbreviation('V');
100
        $this->dataStore->storeInstrument($vocals);
101
        $this->vocals = $vocals;
102
103
        $platform = new Platform('Rock Band');
104
        $this->dataStore->storePlatform($platform);
105
        $this->platform = $platform;
106
107
        $source = new Source('Karaoke'); // TODO for RCL karaoke purposes we could keep the real source
108
        $this->dataStore->storeSource($source);
109
        $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...
110
    }
111
112
    /**
113
     * Store a single spreadsheet row
114
     *
115
     * @param array $row Character-indexed flattened DB row
116
     * @return bool True on success
117
     * @throws \Doctrine\DBAL\Exception\InvalidArgumentException
118
     */
119
    public function storeRawRow(array $row)
120
    {
121
        $song = new Song();
122
        $song
123
            ->setArtist($row[$this->fieldLookup[self::INPUT_FIELD_ARTIST]])
124
            ->setTitle($row[$this->fieldLookup[self::INPUT_FIELD_TITLE]])
125
            ->setSourceId($this->source->getId());
126
127
        $durationMS = trim($row[$this->fieldLookup[self::INPUT_FIELD_DURATION_MMSS]]);
128 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...
129
            $song->setDuration(($matches[1] * 60) + $matches[2]);
130
        }
131
132
        $this->dataStore->storeSong($song); // need id below
133
134
        try {
135
            $this->dataStore->storeSongPlatformLinks($song->getId(), [$this->platform->getId()]);
136
            $this->dataStore->storeSongInstrumentLinks($song->getId(), [$this->vocals->getId()]);
137
        } catch (InvalidArgumentException $e) {
138
            trigger_error($e->getMessage(), E_USER_WARNING);
139
            return false;
140
        }
141
142
        return true;
143
    }
144
145
    /**
146
     * Get short name for form keys, CLI etc
147
     *
148
     * @return string
149
     */
150
    public function getShortName()
151
    {
152
        return 'RclKaraoke';
153
    }
154
}
155