Completed
Push — master ( 993468...5fd9a9 )
by Markus
12s queued 10s
created

ClassDefinition   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 24
dl 0
loc 98
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A setName() 0 5 1
A getProperties() 0 3 1
A getId() 0 14 2
A setNamespace() 0 5 1
A getNamespace() 0 3 1
A setProperties() 0 5 1
1
<?php
2
3
namespace Jellyfish\Transfer\Definition;
4
5
class ClassDefinition implements ClassDefinitionInterface
6
{
7
    public const NAMESPACE_PREFIX = 'Generated\\Transfer';
8
    public const NAMESPACE_SEPARATOR = '\\';
9
    public const FACTORY_NAME_SUFFIX = 'Factory';
10
11
    /**
12
     * @var string
13
     */
14
    protected $name;
15
16
    /**
17
     * @var string|null
18
     */
19
    protected $namespace;
20
21
    /**
22
     * @var \Jellyfish\Transfer\Definition\ClassPropertyDefinitionInterface[]
23
     */
24
    protected $properties;
25
26
    /**
27
     * @return string
28
     */
29
    public function getId(): string
30
    {
31
        $pattern = '/(?<=\\w)(?=[A-Z])/';
32
        $replacement = '_$1';
33
        $id = \str_replace('\\', '', static::NAMESPACE_PREFIX);
34
35
        if ($this->namespace !== null) {
36
            $id .= $this->namespace;
37
        }
38
39
        $id .= $this->name;
40
        $id = \preg_replace($pattern, $replacement, $id);
41
42
        return \strtolower($id);
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getName(): string
49
    {
50
        return $this->name;
51
    }
52
53
    /**
54
     * @param string $name
55
     *
56
     * @return \Jellyfish\Transfer\Definition\ClassDefinitionInterface
57
     */
58
    public function setName(string $name): ClassDefinitionInterface
59
    {
60
        $this->name = $name;
61
62
        return $this;
63
    }
64
65
    /**
66
     * @return string|null
67
     */
68
    public function getNamespace(): ?string
69
    {
70
        return $this->namespace;
71
    }
72
73
    /**
74
     * @param string|null $namespace
75
     *
76
     * @return \Jellyfish\Transfer\Definition\ClassDefinitionInterface
77
     */
78
    public function setNamespace(?string $namespace): ClassDefinitionInterface
79
    {
80
        $this->namespace = $namespace;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @return \Jellyfish\Transfer\Definition\ClassPropertyDefinitionInterface[]
87
     */
88
    public function getProperties(): array
89
    {
90
        return $this->properties;
91
    }
92
93
    /**
94
     * @param \Jellyfish\Transfer\Definition\ClassPropertyDefinitionInterface[] $properties
95
     *
96
     * @return \Jellyfish\Transfer\Definition\ClassDefinitionInterface
97
     */
98
    public function setProperties(array $properties): ClassDefinitionInterface
99
    {
100
        $this->properties = $properties;
101
102
        return $this;
103
    }
104
}
105