ConsoleApplicationConfigurator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 75
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setEventDispatcher() 0 4 1
A setCommandsLoader() 0 4 1
A setSingleStateConfigurator() 0 4 1
B configure() 0 21 5
1
<?php
2
3
  namespace Funivan\Console;
4
5
  use Funivan\Console\CommandsLoader\CommandsLoaderInterface;
6
  use Funivan\Console\SingleState\ConsoleSingleStateConfiguratorInterface;
7
  use Symfony\Component\Console\Application;
8
  use Symfony\Component\EventDispatcher\EventDispatcher;
9
10
  /**
11
   * @author Ivan Shcherbak <[email protected]>
12
   */
13
  class ConsoleApplicationConfigurator {
14
15
    /**
16
     * @var EventDispatcher
17
     */
18
    private $eventDispatcher = null;
19
20
    /**
21
     * @var CommandsLoaderInterface
22
     */
23
    private $commandsLoader = null;
24
25
    /**
26
     * @var ConsoleSingleStateConfiguratorInterface
27
     */
28
    private $singleStateConfigurator = null;
29
30
31
    /**
32
     * @param EventDispatcher $eventDispatcher
33
     * @return $this
34
     */
35
    public function setEventDispatcher(EventDispatcher $eventDispatcher) {
36
      $this->eventDispatcher = $eventDispatcher;
37
      return $this;
38
    }
39
40
41
    /**
42
     * @param CommandsLoaderInterface $commandsLoader
43
     * @return $this
44
     */
45
    public function setCommandsLoader(CommandsLoaderInterface $commandsLoader) {
46
      $this->commandsLoader = $commandsLoader;
47
      return $this;
48
    }
49
50
51
    /**
52
     * @param ConsoleSingleStateConfiguratorInterface $singleStateConfigurator
53
     * @return $this
54
     */
55
    public function setSingleStateConfigurator(ConsoleSingleStateConfiguratorInterface $singleStateConfigurator) {
56
      $this->singleStateConfigurator = $singleStateConfigurator;
57
      return $this;
58
    }
59
60
61
    /**
62
     * @param Application $app
63
     * @return ConsoleApplication
64
     */
65
    public function configure(Application $app) {
66
67
      $app->setCatchExceptions(false);
68
69
      if ($this->commandsLoader) {
70
        $this->commandsLoader->loadCommands($app);
71
      }
72
73
      if ($this->singleStateConfigurator) {
74
        if (empty($this->eventDispatcher)) {
75
          throw new \RuntimeException('Dispatcher component required');
76
        }
77
78
        $this->singleStateConfigurator->configureSingleState($this->eventDispatcher);
79
      }
80
81
      if (!empty($this->eventDispatcher)) {
82
        $app->setDispatcher($this->eventDispatcher);
83
      }
84
85
    }
86
87
  }