SimpleFactoryPlugin::throwException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Dazzle\Util\Factory;
4
5
use Dazzle\Throwable\Exception\Runtime\ExecutionException;
6
use Error;
7
use Exception;
8
9 View Code Duplication
abstract class SimpleFactoryPlugin implements SimpleFactoryPluginInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * @var bool
13
     */
14
    private $registered;
15
16
    /**
17
     * @override
18
     * @inheritDoc
19
     */
20 4
    public function registerPlugin(SimpleFactoryInterface $factory)
21
    {
22
        try
23
        {
24 4
            $this->register($factory);
25 3
            $this->registered = true;
26
        }
27 1
        catch (Error $ex)
28
        {
29
            $this->throwException($ex);
30
        }
31 1
        catch (Exception $ex)
32
        {
33 1
            $this->throwException($ex);
34
        }
35
36 3
        return $this;
37
    }
38
39
    /**
40
     * @override
41
     * @inheritDoc
42
     */
43 3
    public function unregisterPlugin(SimpleFactoryInterface $factory)
44
    {
45 3
        if ($this->registered)
46
        {
47 1
            $this->unregister($factory);
48 1
            $this->registered = false;
49
        }
50
51 3
        return $this;
52
    }
53
54
    /**
55
     * Define how plugin should be registered.
56
     *
57
     * @param SimpleFactoryInterface $factory
58
     */
59
    protected function register(SimpleFactoryInterface $factory)
0 ignored issues
show
Unused Code introduced by
The parameter $factory is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {}
61
62
    /**
63
     * Define how plugin should be unregistered.
64
     *
65
     * @param SimpleFactoryInterface $factory
66
     */
67
    protected function unregister(SimpleFactoryInterface $factory)
0 ignored issues
show
Unused Code introduced by
The parameter $factory is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {}
69
70
    /**
71
     * @param Error|Exception $ex
72
     * @throws ExecutionException
73
     */
74 1
    private function throwException($ex)
75
    {
76 1
        throw new ExecutionException("SimpleFactoryPlugin [" . get_class($this) . "] raised an error.", 0, $ex);
77
    }
78
}
79