CloakPlugin::onRunnerStart()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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