PropertyEncoder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A encode() 0 15 2
A getPrefix() 0 4 1
A getUri() 0 4 1
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