CloakPlugin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 7
Bugs 1 Features 4
Metric Value
wmc 5
c 7
b 1
f 4
lcom 1
cbo 4
dl 0
loc 55
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 9 1
A registerTo() 0 5 1
A onRunnerStart() 0 4 1
A onRunnerEnd() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of peridot-cloak package.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
namespace cloak\peridot;
12
13
use cloak\CoverageAnalyzer;
14
use cloak\ReportableAnalyzer;
15
use cloak\configuration\ConfigurationLoader;
16
use Evenement\EventEmitterInterface;
17
18
/**
19
 * Class CloakPlugin
20
 */
21
class CloakPlugin implements Registrar
22
{
23
    /**
24
     * @var \cloak\ReportableAnalyzer
25
     */
26
    private $analyzer;
27
28
    /**
29
     * @param ReportableAnalyzer $analyzer
30
     */
31
    public function __construct(ReportableAnalyzer $analyzer)
32
    {
33
        $this->analyzer = $analyzer;
34
    }
35
36
    /**
37
     * @param string $configurationFile
38
     *
39
     * @return CloakPlugin
40
     */
41
    public static function create($configurationFile)
42
    {
43
        $loader = new ConfigurationLoader();
44
        $configuration = $loader->loadConfiguration($configurationFile);
45
46
        $analyzer = new CoverageAnalyzer($configuration);
47
48
        return new self($analyzer);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function registerTo(EventEmitterInterface $emitter)
55
    {
56
        $emitter->on(self::START_EVENT, [ $this, 'onRunnerStart' ]);
57
        $emitter->on(self::END_EVENT, [ $this, 'onRunnerEnd' ]);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function onRunnerStart()
64
    {
65
        $this->analyzer->start();
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function onRunnerEnd($processingTime)
72
    {
73
        $this->analyzer->stop();
74
    }
75
}
76