Completed
Push — master ( 5875b6...d65a71 )
by brian
01:43
created

ObjectProperty   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
cbo 0
dl 0
loc 88
ccs 37
cts 37
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getVisibility() 0 4 1
A setVisibility() 0 4 1
A getClassName() 0 4 1
A setClassName() 0 4 1
A getPropertyName() 0 4 1
A setPropertyName() 0 4 1
A getValue() 0 4 1
A setValue() 0 4 1
A __toString() 0 16 3
1
<?php declare(strict_types=1);
2
3
/**
4
 * @copyright   (c) 2019-present brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 */
8
9
namespace ptlis\SerializedDataEditor\TypeFragment;
10
11
use ptlis\SerializedDataEditor\Parser\Token;
12
use ptlis\SerializedDataEditor\Type\Type;
13
14
/**
15
 * Class representing a single property of an object.
16
 */
17
final class ObjectProperty
18
{
19
    const PUBLIC = 'public';
20
    const PROTECTED = 'protected';
21
    const PRIVATE = 'private';
22
23
    /** @var string */
24
    private $visibility;
25
26
    /** @var string */
27
    private $className;
28
29
    /** @var string */
30
    private $propertyName;
31
32
    /** @var Type */
33
    private $value;
34
35
36 12
    public function __construct(
37
        string $visibility,
38
        string $className,
39
        string $propertyName,
40
        Type $value
41
    ) {
42 12
        $this->visibility = $visibility;
43 12
        $this->className = $className;
44 12
        $this->propertyName = $propertyName;
45 12
        $this->value = $value;
46 12
    }
47
48 1
    public function getVisibility(): string
49
    {
50 1
        return $this->visibility;
51
    }
52
53 1
    public function setVisibility(string $visibility): void
54
    {
55 1
        $this->visibility = $visibility;
56 1
    }
57
58 1
    public function getClassName(): string
59
    {
60 1
        return $this->className;
61
    }
62
63 1
    public function setClassName(string $className): void
64
    {
65 1
        $this->className = $className;
66 1
    }
67
68 1
    public function getPropertyName(): string
69
    {
70 1
        return $this->propertyName;
71
    }
72
73 1
    public function setPropertyName(string $propertyName): void
74
    {
75 1
        $this->propertyName = $propertyName;
76 1
    }
77
78 1
    public function getValue(): Type
79
    {
80 1
        return $this->value;
81
    }
82
83 1
    public function setValue(Type $value): void
84
    {
85 1
        $this->value = $value;
86 1
    }
87
88 4
    public function __toString(): string
89
    {
90 4
        $serializedPropName = '';
91 4
        switch ($this->visibility) {
92 4
            case self::PROTECTED:
93 2
                $serializedPropName = "\0*\0";
94 2
                break;
95
96 3
            case self::PRIVATE:
97 2
                $serializedPropName = "\0" . $this->className . "\0";
98 2
                break;
99
        }
100 4
        $serializedPropName .= $this->propertyName;
101
102 4
        return Token::PREFIX_STRING . ':' . strlen($serializedPropName) . ':"' . $serializedPropName . '";' . strval($this->value);
103
    }
104
}