StringBinding   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 40
loc 40
wmc 6
lcom 1
cbo 1
ccs 12
cts 18
cp 0.6667
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A getString() 4 4 1
A preSerialize() 6 6 1
A postUnserialize() 6 6 1
A equals() 9 9 2

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
/*
4
 * This file is part of the puli/discovery package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Discovery\Test\Fixtures;
13
14
use Puli\Discovery\Api\Binding\Binding;
15
use Puli\Discovery\Binding\AbstractBinding;
16
17
/**
18
 * @since  1.0
19
 *
20
 * @author Bernhard Schussek <[email protected]>
21
 *
22
 * @internal
23
 */
24 View Code Duplication
class StringBinding extends AbstractBinding
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...
25
{
26
    private $string;
27
28 97
    public function __construct($string, $typeName, array $parameterValues = array())
29
    {
30 97
        parent::__construct($typeName, $parameterValues);
31
32 97
        $this->string = $string;
33 97
    }
34
35
    public function getString()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
    {
37
        return $this->string;
38
    }
39
40
    public function equals(Binding $other)
41
    {
42
        if (!parent::equals($other)) {
43
            return false;
44
        }
45
46
        /* @var StringBinding $other */
47
        return $this->string === $other->string;
48
    }
49
50 69
    protected function preSerialize(array &$data)
51
    {
52 69
        parent::preSerialize($data);
53
54 69
        $data[] = $this->string;
55 69
    }
56
57 26
    protected function postUnserialize(array &$data)
58
    {
59 26
        $this->string = array_pop($data);
60
61 26
        parent::postUnserialize($data);
62 26
    }
63
}
64