onPostDispatchDeployment()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 6
rs 10
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
}