ExecutionWrapper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 2 Features 2
Metric Value
wmc 4
c 7
b 2
f 2
lcom 1
cbo 6
dl 0
loc 42
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getEventDispatcher() 0 4 1
A exec() 0 12 2
1
<?php
2
namespace ivol;
3
4
use ivol\Config\ConfigurationFactory;
5
use ivol\EventDispatcher\AfterExecuteEvent;
6
use ivol\EventDispatcher\BeforeExecuteEvent;
7
use ivol\EventDispatcher\EscapeArgsSubscriber;
8
use Symfony\Component\EventDispatcher\EventDispatcher;
9
10
class ExecutionWrapper
11
{
12
    /** @var array  */
13
    private $config;
14
    /** @var EventDispatcher */
15
    private $eventDispatcher;
16
17
    /**
18
     * @param array $config
19
     */
20 5
    public function __construct($config = array())
21
    {
22 5
        $this->config = ConfigurationFactory::createFromArray($config);
23 5
        $this->eventDispatcher = new EventDispatcher();
24 5
    }
25
26
    /**
27
     * @return EventDispatcher
28
     */
29 2
    public function getEventDispatcher()
30
    {
31 2
        return $this->eventDispatcher;
32
    }
33
34
    /**
35
     * @param string $command Sprintf formatted string @see http://php.net/manual/en/function.sprintf.php
36
     * @param array $params
37
     * @return ExecutionResult
38
     */
39 5
    public function exec($command, $params)
40
    {
41 5
        $execParams = new ExecutionContext($command, $params);
42 5
        $execParams->setConfig($this->config);
43 5
        $beforeExecuteEvent = new BeforeExecuteEvent($execParams);
44 5
        $this->eventDispatcher->dispatch(BeforeExecuteEvent::EVENT_NAME, $beforeExecuteEvent);
45 5
        exec($beforeExecuteEvent->getParams()->getFullCommand(), $output, $returnValue);
46 5
        $output = $output ?: array();
47 5
        $afterExecuteEvent = new AfterExecuteEvent(new ExecutionResult($returnValue, $output));
48 5
        $this->eventDispatcher->dispatch(AfterExecuteEvent::EVENT_NAME, $afterExecuteEvent);
49 5
        return $afterExecuteEvent->getResult();
50
    }
51
}