|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Symplify |
|
5
|
|
|
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz). |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Symplify\MultiCodingStandard\DI; |
|
9
|
|
|
|
|
10
|
|
|
use Nette\DI\CompilerExtension; |
|
11
|
|
|
use Nette\DI\Helpers; |
|
12
|
|
|
use Nette\DI\ServiceDefinition; |
|
13
|
|
|
use Symfony\Component\Console\Command\Command; |
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
15
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
16
|
|
|
use Symplify\MultiCodingStandard\Console\MultiCodingStandardApplication; |
|
17
|
|
|
use Symplify\PHP7_CodeSniffer\DI\ExtensionHelperTrait; |
|
18
|
|
|
|
|
19
|
|
|
final class MultiCodingStandardExtension extends CompilerExtension |
|
20
|
|
|
{ |
|
21
|
|
|
use ExtensionHelperTrait; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var string[] |
|
25
|
|
|
*/ |
|
26
|
|
|
private $defaults = [ |
|
27
|
|
|
'configPath' => '%appDir%/../multi-cs.json' |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
6 |
|
public function loadConfiguration() |
|
34
|
|
|
{ |
|
35
|
6 |
|
$this->setConfigToContainerBuilder($this->defaults); |
|
36
|
6 |
|
$this->loadServicesFromConfig(); |
|
37
|
6 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
6 |
|
public function beforeCompile() |
|
43
|
|
|
{ |
|
44
|
6 |
|
$this->loadCommandsToConsoleApplication(); |
|
45
|
6 |
|
$this->loadEventSubscribersToEventDispatcher(); |
|
46
|
6 |
|
} |
|
47
|
|
|
|
|
48
|
6 |
|
private function loadServicesFromConfig() |
|
49
|
|
|
{ |
|
50
|
6 |
|
$containerBuilder = $this->getContainerBuilder(); |
|
51
|
6 |
|
$config = $this->loadFromFile(__DIR__.'/../config/services.neon'); |
|
52
|
6 |
|
$this->compiler->parseServices($containerBuilder, $config); |
|
|
|
|
|
|
53
|
6 |
|
} |
|
54
|
|
|
|
|
55
|
6 |
|
private function loadCommandsToConsoleApplication() |
|
56
|
|
|
{ |
|
57
|
6 |
|
$this->addServicesToCollector(MultiCodingStandardApplication::class, Command::class, 'add'); |
|
58
|
6 |
|
} |
|
59
|
|
|
|
|
60
|
6 |
|
private function loadEventSubscribersToEventDispatcher() |
|
61
|
|
|
{ |
|
62
|
6 |
|
$this->addServicesToCollector(EventDispatcherInterface::class, EventSubscriberInterface::class, 'addSubscriber'); |
|
63
|
6 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string[] $defaults |
|
68
|
|
|
*/ |
|
69
|
6 |
|
private function setConfigToContainerBuilder(array $defaults) |
|
70
|
|
|
{ |
|
71
|
6 |
|
$config = $this->validateConfig($defaults); |
|
72
|
6 |
|
$config['configPath'] = Helpers::expand($config['configPath'], $this->getContainerBuilder()->parameters); |
|
73
|
6 |
|
$this->getContainerBuilder()->parameters += $config; |
|
74
|
6 |
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.