ContextControlCodeTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 11
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getContextControlCode() 0 3 1
A setContextControlCode() 0 8 2
A renderContextControlCode() 0 7 2
A hasContextControlCode() 0 3 1
1
<?php
2
3
/**
4
 * The MIT License
5
 *
6
 * Copyright 2018  Peter Gee <https://github.com/pgee70>.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
28
namespace i3Soft\CDA\Traits;
29
30
31
use i3Soft\CDA\Interfaces\ContextControlCodeInterface;
32
33
/**
34
 * Trait ContextControlCodeTrait
35
 *
36
 * @package i3Soft\CDA\Traits
37
 */
38
trait ContextControlCodeTrait
39
{
40
  /** @var string */
41
  private $contextControlCode = '';
42
43
  /**
44
   * @param \DOMElement $el
45
   *
46
   * @return self
47
   */
48
  public function renderContextControlCode (\DOMElement $el): self
49
  {
50
    if ($this->hasContextControlCode())
51
    {
52
      $el->setAttribute('contextControlCode', $this->getContextControlCode());
53
    }
54
    return $this;
55
  }
56
57
  /**
58
   * @return bool
59
   */
60
  public function hasContextControlCode (): bool
61
  {
62
    return '' !== $this->contextControlCode;
63
  }
64
65
  /**
66
   * @return string
67
   */
68
  public function getContextControlCode (): string
69
  {
70
    return $this->contextControlCode;
71
  }
72
73
  /**
74
   * @param string $contextControlCode
75
   *
76
   * @return self
77
   */
78
  public function setContextControlCode (string $contextControlCode): self
79
  {
80
    if (\in_array($contextControlCode, ContextControlCodeInterface::CDA, TRUE) === FALSE)
81
    {
82
      throw new \InvalidArgumentException("The context control value $contextControlCode was not valid!");
83
    }
84
    $this->contextControlCode = $contextControlCode;
85
    return $this;
86
  }
87
88
}