AnimalReference.php$0 ➔ newInstance()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Tests\TestModel\Instance;
4
5
use Xml\ModelBuilder;
6
use Xml\Impl\Instance\{
7
    ModelElementInstanceImpl,
8
    ModelTypeInstanceContext
9
};
10
use Xml\Type\ModelTypeInstanceProviderInterface;
11
use Tests\TestModel\TestModelConstants;
12
13
class AnimalReference extends ModelElementInstanceImpl
14
{
15
    protected static $hrefAttribute;
16
17
    public function __construct(ModelTypeInstanceContext $instanceContext)
18
    {
19
        parent::__construct($instanceContext);
20
    }
21
22
    public function getHref(): string
23
    {
24
        return self::$hrefAttribute->getValue($this);
25
    }
26
27
    public function setHref(string $href): void
28
    {
29
        self::$hrefAttribute->setValue($this, $href);
30
    }
31
32
    public static function registerType(ModelBuilder $modelBuilder): void
33
    {
34
        $typeBuilder = $modelBuilder->defineType(
35
            AnimalReference::class,
36
            TestModelConstants::ELEMENT_NAME_ANIMAL_REFERENCE
37
        )
38
        ->namespaceUri(TestModelConstants::MODEL_NAMESPACE)
39
        ->instanceProvider(
40
            new class implements ModelTypeInstanceProviderInterface
41
            {
42
                public function newInstance(ModelTypeInstanceContext $instanceContext): AnimalReference
43
                {
44
                    return new AnimalReference($instanceContext);
45
                }
46
            }
47
        );
48
49
        self::$hrefAttribute = $typeBuilder->stringAttribute("href")->required()->build();
50
51
        $typeBuilder->build();
52
    }
53
}
54