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

Renderer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A typeIndication() 0 18 4
A is() 0 4 1
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