Passed
Push — master ( c85748...2fd0ab )
by Petr
08:11
created

TContent::checkContentKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
1
<?php
2
3
namespace kalanis\kw_mapper\Mappers\Shared;
4
5
6
use kalanis\kw_mapper\MapperException;
7
8
9
/**
10
 * Trait TContent
11
 * @package kalanis\kw_mapper\Mappers\Shared
12
 */
13
trait TContent
14
{
15
    /** @var string */
16
    protected $contentKey = '';
17
18 17
    public function setContentKey(string $contentKey): self
19
    {
20 17
        $this->contentKey = $contentKey;
21 17
        return $this;
22
    }
23
24
    /**
25
     * @throws MapperException
26
     * @return string
27
     */
28 10
    public function getContentKey(): string
29
    {
30 10
        $this->checkContentKey();
31 9
        return $this->contentKey;
32
    }
33
34
    /**
35
     * @throws MapperException
36
     */
37 10
    protected function checkContentKey(): void
38
    {
39 10
        if (empty($this->contentKey)) {
40 1
            throw new MapperException('Cannot manipulate content without data key - content itself!');
41
        }
42
    }
43
}
44