SimpleFactoryPlugin   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 70
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 73.68%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 70
loc 70
ccs 14
cts 19
cp 0.7368
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerPlugin() 18 18 3
A unregisterPlugin() 10 10 2
A register() 2 2 1
A unregister() 2 2 1
A throwException() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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