UriElementReferenceCollectionImpl::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Xml\Impl\Type\Reference;
4
5
use Xml\Type\Child\ChildElementCollectionInterface;
6
use Xml\Instance\ModelElementInstanceInterface;
7
8
class UriElementReferenceCollectionImpl extends ElementReferenceCollectionImpl
9
{
10
    public function __construct(ChildElementCollectionInterface $referenceSourceCollection)
11
    {
12
        parent::__construct($referenceSourceCollection);
13
    }
14
15
    /**
16
     * @return mixed
17
     */
18
    public function getReferenceIdentifier(ModelElementInstanceInterface $referenceSourceElement)
19
    {
20
        $identifier = $referenceSourceElement->getAttributeValue("href");
21
        if ($identifier !== null) {
22
            $parts = explode('#', $identifier);
23
            if (count($parts) > 1) {
24
                return $parts[count($parts) - 1];
25
            } else {
26
                return $parts[0];
27
            }
28
        } else {
29
            return null;
30
        }
31
    }
32
33
    protected function setReferenceIdentifier(
34
        ModelElementInstanceInterface $referenceSourceElement,
35
        string $referenceIdentifier
36
    ): void {
37
        $referenceSourceElement->setAttributeValue("href", "#" . $referenceIdentifier);
38
    }
39
}
40