Completed
Pull Request — develop (#13)
by Oguzhan
06:06 queued 02:55
created

BaseCommand::initializeMusicInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: oguzu
5
 * Date: 27-3-2017
6
 * Time: 16:52
7
 */
8
9
namespace Pbxg33k\MusicInfo\Command;
10
11
12
use Pbxg33k\MusicInfo\MusicInfo;
13
use Pbxg33k\Traits\HydratableTrait;
14
use Pbxg33k\Traits\PropertyTrait;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Helper\Table;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Symfony\Component\Yaml\Yaml;
19
20
abstract class BaseCommand extends Command
21
{
22
    const COMMAND_PREFIX = 'music-info';
23
24
    const COMMAND_NAME = 'undefined';
25
26
    const COMMAND_DESCRIPTION = 'Description not set';
27
28
    /**
29
     * @var MusicInfo
30
     */
31
    protected $musicInfo;
32
33
    protected function initializeMusicInfo()
34
    {
35
        $config = Yaml::parse(file_get_contents(__DIR__ . '/../Resources/config/config.yml'));
36
37
        $this->musicInfo = new MusicInfo($config['music_info']);
38
    }
39
40
    protected function configure()
41
    {
42
        if(!$this->musicInfo) {
43
            $this->initializeMusicInfo();
44
        }
45
46
        $this
47
            ->setName(static::COMMAND_PREFIX . ':' . static::COMMAND_NAME)
48
            ->setDescription(static::COMMAND_DESCRIPTION);
49
50
        parent::configure(); // TODO: Change the autogenerated stub
51
    }
52
53
    /**
54
     * @param       $collection
55
     * @param       $columns
56
     * @param Table $table
57
     * @return Table
58
     */
59
    protected function generateTableForSearchResult($collection, $columns, Table $table)
60
    {
61
        $table->setHeaders(array_values($columns));
62
63
        foreach($collection as $service => $serviceResult) {
64
            $table = $this->generateTableRows($serviceResult, $columns, $table);
65
        }
66
67
        return $table;
68
    }
69
70
    /**
71
     * @param                 $collection
72
     * @param                 $columns
73
     * @param OutputInterface $output
0 ignored issues
show
Bug introduced by
There is no parameter named $output. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
74
     * @return Table
75
     * @throws \Exception
76
     */
77
    protected function generateTableRows($collection, $columns, Table $table)
78
    {
79
        foreach($collection as $item) {
80
            $row = [];
81
82
            foreach($columns as $columnKey => $columnValue) {
83
                $row[] = $item->getPropertyValue($columnKey);
84
            }
85
86
            $table->addRow($row);
87
        }
88
89
        return $table;
90
    }
91
}