AttributeBuilderImpl::idAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Xml\Impl\Type\Attribute;
4
5
use Xml\ModelInterface;
6
use Xml\Impl\ModelBuildOperationInterface;
7
use Xml\Impl\Type\ModelElementTypeImpl;
8
use Xml\Type\Attribute\{
9
    AttributeInterface,
10
    AttributeBuilderInterface
11
};
12
13
abstract class AttributeBuilderImpl implements AttributeBuilderInterface, ModelBuildOperationInterface
14
{
15
    private $attribute;
16
    private $modelType;
17
18
    public function __construct(string $attributeName, ModelElementTypeImpl $modelType, AttributeImpl $attribute)
19
    {
20
        $this->modelType = $modelType;
21
        $this->attribute = $attribute;
22
        $this->attribute->setAttributeName($attributeName);
23
    }
24
25
    public function namespace(string $namespaceUri): AttributeBuilderInterface
26
    {
27
        $this->attribute->setNamespaceUri($namespaceUri);
28
        return $this;
29
    }
30
31
    public function idAttribute(): AttributeBuilderInterface
32
    {
33
        $this->attribute->setId();
34
        return $this;
35
    }
36
37
    /**
38
     * @param mixed $defaultValue
39
     */
40
    public function defaultValue($defaultValue): AttributeBuilderInterface
41
    {
42
        $this->attribute->setDefaultValue($defaultValue);
43
        return $this;
44
    }
45
46
    public function required(): AttributeBuilderInterface
47
    {
48
        $this->attribute->setRequired(true);
49
        return $this;
50
    }
51
52
    public function build(): AttributeInterface
53
    {
54
        $this->modelType->registerAttribute($this->attribute);
55
        return $this->attribute;
56
    }
57
58
    public function performModelBuild(ModelInterface $model): void
59
    {
60
        //do nothing
61
    }
62
}
63