Completed
Push — master ( d11b01...1c170b )
by Daniel
17:01 queued 13:33
created

PropertyEncoder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 45
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
    public function __construct(string $prefix, string $uri)
14
    {
15
        $this->prefix = $prefix;
0 ignored issues
show
Bug introduced by
The property prefix does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
16
        $this->uri = $uri;
0 ignored issues
show
Bug introduced by
The property uri does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
    }
18
19
    /**
20
     * Encode a field name. If the field reprents a compound type then $key
21
     * should be passed to represent the key for the value of the compound
22
     * field.
23
     */
24
    public function encode(string $fieldName, string $key = null): string
25
    {
26
        $propertyName = sprintf(
27
            '%s:%s',
28
            $this->prefix,
29
            $fieldName
30
        );
31
32
        if (null !== $key) {
33
            $propertyName .= '-' . $key;
34
        }
35
36
37
        return $propertyName;
38
    }
39
40
    /**
41
     * Return the PHPCR namespace prefix (alias).
42
     */
43
    public function getPrefix(): string
44
    {
45
        return $this->prefix;
46
    }
47
48
    /**
49
     * Return the namespace URI.
50
     */
51
    public function getUri(): string
52
    {
53
        return $this->uri;
54
    }
55
}
56