Failed Conditions
Pull Request — master (#32)
by Bernhard
09:33 queued 20s
created

ClassBinding::equals()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 3
cts 3
cp 1
rs 9.6666
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the webmozart/booking 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\Binding;
13
14
use Puli\Discovery\Api\Binding\Binding;
15
use Puli\Discovery\Api\Type\MissingParameterException;
16
use Puli\Discovery\Api\Type\NoSuchParameterException;
17
18
/**
19
 * Binds a class name to a binding type.
20
 *
21
 * @since  1.0
22
 *
23
 * @author Bernhard Schussek <[email protected]>
24
 */
25
class ClassBinding extends AbstractBinding
26
{
27
    /**
28
     * @var string
29
     */
30
    private $className;
31
32
    /**
33
     * Creates a new class binding.
34
     *
35
     * @param string $className       The fully-qualified name of the bound
36
     *                                class.
37
     * @param string $typeName        The name of the type to bind against.
38
     * @param array  $parameterValues The values of the parameters defined
39
     *                                for the type.
40
     *
41
     * @throws NoSuchParameterException  If an invalid parameter was passed.
42
     * @throws MissingParameterException If a required parameter was not passed.
43
     */
44 50
    public function __construct($className, $typeName, array $parameterValues = array())
45
    {
46 50
        parent::__construct($typeName, $parameterValues);
47
48 49
        $this->className = $className;
49 49
    }
50
51
    /**
52
     * Returns the name of the bound class.
53
     *
54
     * @return string The fully-qualified class name.
55
     */
56 1
    public function getClassName()
57
    {
58 1
        return $this->className;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 13
    public function equals(Binding $other)
65
    {
66 13
        if (!parent::equals($other)) {
67 13
            return false;
68
        }
69
70
        /* @var ClassBinding $other */
71
        return $this->className === $other->className;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 30
    protected function preSerialize(array &$data)
78
    {
79 30
        parent::preSerialize($data);
80
81 30
        $data[] = $this->className;
82 30
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 9
    protected function postUnserialize(array &$data)
88
    {
89 9
        $this->className = array_pop($data);
90
91 9
        parent::postUnserialize($data);
92 9
    }
93
}
94