PostDispatchDeploymentSubscriber   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 37
ccs 0
cts 17
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onPostDispatchDeployment() 0 9 2
A getSubscribedEvents() 0 4 1
A __construct() 0 3 1
1
<?php
2
3
namespace Deployee\Plugins\DeployHistory\Subscriber;
4
5
6
use Deployee\Components\Persistence\LazyPDO;
7
use Deployee\Plugins\Deploy\Events\PostDispatchDeploymentEvent;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10
class PostDispatchDeploymentSubscriber implements EventSubscriberInterface
11
{
12
    /**
13
     * @var LazyPDO
14
     */
15
    private $lazyPdo;
16
17
    /**
18
     * @return array
19
     */
20
    public static function getSubscribedEvents(): array
21
    {
22
        return [
23
            PostDispatchDeploymentEvent::class => 'onPostDispatchDeployment'
24
        ];
25
    }
26
27
    /**
28
     * @param LazyPDO $lazyPdo
29
     */
30
    public function __construct(LazyPDO $lazyPdo)
31
    {
32
        $this->lazyPdo = $lazyPdo;
33
    }
34
35
    /**
36
     * @param PostDispatchDeploymentEvent $event
37
     */
38
    public function onPostDispatchDeployment(PostDispatchDeploymentEvent $event){
39
40
        $statement = $this->lazyPdo->prepare(
41
            'INSERT INTO deployee_exec_history (`name`, `success`) VALUES(:name, :success)'
42
        );
43
44
        $statement->execute([
45
            ':name' => get_class($event->getDeployDefinition()),
46
            ':success' => $event->isSuccess() ? 1 : 0
47
        ]);
48
    }
49
}