PropertyEncoder::getUri()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Bridge\ContentType\Doctrine\PhpcrOdm;
6
7
/**
8
 * Responsible for encoding PHPCR property names which are managed by the
9
 * content-type component.
10
 */
11
class PropertyEncoder
12
{
13
    private $prefix;
14
    private $uri;
15
16
    public function __construct(string $prefix, string $uri)
17
    {
18
        $this->prefix = $prefix;
19
        $this->uri = $uri;
20
    }
21
22
    /**
23
     * Encode a field name. If the field reprents a compound type then $key
24
     * should be passed to represent the key for the value of the compound
25
     * field.
26
     */
27
    public function encode(string $fieldName, string $key = null): string
28
    {
29
        $propertyName = sprintf(
30
            '%s:%s',
31
            $this->prefix,
32
            $fieldName
33
        );
34
35
        if (null !== $key) {
36
            $propertyName .= '-' . $key;
37
        }
38
39
40
        return $propertyName;
41
    }
42
43
    /**
44
     * Return the PHPCR namespace prefix (alias).
45
     */
46
    public function getPrefix(): string
47
    {
48
        return $this->prefix;
49
    }
50
51
    /**
52
     * Return the namespace URI.
53
     */
54
    public function getUri(): string
55
    {
56
        return $this->uri;
57
    }
58
}
59