ResolvableTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 9 3
A resolve() 0 7 2
1
<?php
2
3
/**
4
 * This file is part of Railt package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Railt\SDL\Frontend\Ast;
13
14
use Phplrt\Contracts\Ast\NodeInterface;
15
16
/**
17
 * Trait ResolvableTrait
18
 */
19
trait ResolvableTrait
20
{
21
    /**
22
     * @param array|NodeInterface[] $children
23
     * @return self
24
     * @throws \LogicException
25
     */
26
    public static function resolve(array $children): self
27
    {
28
        if ($result = self::find($children)) {
29
            return $result;
30
        }
31
32
        throw new \LogicException(static::class . ' not resolvable');
33
    }
34
35
    /**
36
     * @param array|NodeInterface[] $children
37
     * @return self|null
38
     */
39
    public static function find(array $children): ?self
40
    {
41
        foreach ($children as $name) {
42
            if ($name instanceof static) {
43
                return $name;
44
            }
45
        }
46
47
        return null;
48
    }
49
}
50