TransDescriptor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 15
dl 0
loc 31
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Koriym\AppStateDiagram;
6
7
use Koriym\AppStateDiagram\Exception\MissingRtException;
8
use stdClass;
9
10
use function assert;
11
use function is_string;
12
use function strpos;
13
use function substr;
14
15
final class TransDescriptor extends AbstractDescriptor
16
{
17
    /** @var string */
18
    public $type;
19
20
    /** @var string */
21
    public $rt;
22
23
    /** @inheritdoc */
24
    public $parent;
25
26
    public function __construct(stdClass $descriptor, SemanticDescriptor $parent)
27
    {
28
        parent::__construct($descriptor);
29
        assert(is_string($descriptor->type));
30
        $this->type = $descriptor->type;
31
        if (! isset($descriptor->rt) || ! is_string($descriptor->rt)) {
32
            assert(is_string($descriptor->id));
33
34
            throw new MissingRtException($descriptor->id);
35
        }
36
37
        assert(is_string($descriptor->id));
38
39
        $pos = strpos($descriptor->rt, '#');
40
        if ($pos === false) {
41
            throw new MissingRtException($descriptor->id);
42
        }
43
44
        $this->rt = substr($descriptor->rt, $pos + 1);
45
        $this->parent = $parent;
46
    }
47
}
48