|
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 |
|
|
|
|
|
|
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
|
|
|
} |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.