TemporaryPlugin::create()   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 1
Metric Value
c 1
b 0
f 1
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-temporary-plugin.
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
12
namespace holyshared\peridot\temporary;
13
14
use Peridot\Core\Suite;
15
use Evenement\EventEmitterInterface;
16
17
18
/**
19
 * TemporaryPlugin
20
 * @package holyshared\peridot\temporary
21
 */
22
class TemporaryPlugin implements Registrar
23
{
24
25
    /**
26
     * @param EventEmitterInterface $emitter
27
     */
28
    public function registerTo(EventEmitterInterface $emitter)
29
    {
30
        $emitter->on(self::START_EVENT, [ $this, 'onSuiteStart' ]);
31
    }
32
33
    /**
34
     * @param Suite $suite
35
     */
36
    public function onSuiteStart(Suite $suite)
37
    {
38
        $scope = new TemporaryScope();
39
        $suite->getScope()->peridotAddChildScope($scope);
40
41
        $suite->addTearDownFunction(function () use(&$scope) {
42
            $scope->cleanUpTemporary();
43
        });
44
    }
45
46
    public static function create()
47
    {
48
        return new self();
49
    }
50
51
}
52