Completed
Push — master ( 7510c8...82c7bd )
by Kirill
08:19
created

Renderer::is()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler;
11
12
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesTypeIndication;
13
14
/**
15
 * Class Renderer
16
 */
17
class Renderer
18
{
19
    /**
20
     * @param string $name
21
     * @param int $modifiers
22
     * @return string
23
     */
24
    public static function typeIndication(string $name, int $modifiers = 0): string
25
    {
26
        $result = $name;
27
28
        if (self::is($modifiers, ProvidesTypeIndication::IS_NOT_NULL)) {
29
            $result .= '!';
30
        }
31
32
        if (self::is($modifiers, ProvidesTypeIndication::IS_LIST)) {
33
            $result = '[' . $result . ']';
34
        }
35
36
        if (self::is($modifiers, ProvidesTypeIndication::IS_LIST_OF_NOT_NULL)) {
37
            $result .= '!';
38
        }
39
40
        return $result;
41
    }
42
43
    /**
44
     * @param int $mask
45
     * @param int $val
46
     * @return bool
47
     */
48
    private static function is(int $mask, int $val): bool
49
    {
50
        return ($mask & $val) === $val;
51
    }
52
}
53
54