TypeEnumBuilder::rebuild()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 23
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: danchukas
6
 * Date: 2017-07-18 12:17
7
 */
8
9
namespace DanchukAS\Mock;
10
11
12
/**
13
 * Class TypeEnumBuilder
14
 * @package DanchukAS\Mock
15
 */
16
class TypeEnumBuilder
17
{
18
    // available types
19
    protected static $boolean = 'boolean';
20
    protected static $integer = 'integer';
21
    protected static $double = 'double';
22
    protected static $string = 'string';
23
    protected static $array = 'array';
24
    protected static $object = 'object';
25
    protected static $resource = 'resource';
26
    protected static $null = 'null';
27
    protected static $unknown = 'unknown';
28
29
    public static function rebuild()
30
    {
31
        $type_list = self::getTypeList();
32
33
        $property_list = [];
34
35
        foreach ($type_list as $type_name) {
36
            $property_name = strtoupper($type_name);
37
            if (5 > strlen($type_name)) {
38
                $no_inspect_name = "/** @noinspection PhpConstantNamingConventionInspection */\n\t\t";
39
                $property_name = $no_inspect_name . $property_name;
40
            }
41
            $property_list[] = "const $property_name = \"$type_name\";";
42
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
43
        }
44
45
        $property_code = implode("\n\t", $property_list);
46
47
        $template = file_get_contents(__DIR__ . '/TypeEnum.tpl');
48
49
        $file_content = str_replace('{PROPERTY}', $property_code, $template);
50
51
        file_put_contents(__DIR__ . '/TypeEnum.php', $file_content);
52
53
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
54
55
    /**
56
     * @return array
57
     */
58
    private static function getTypeList()
59
    {
60
        $type_list = [];
61
62
        $type_dir = __DIR__ . '/Type';
63
        // SCANDIR_SORT_ASCENDING - щоб уникнути зайвих комітів пов'язаних з білдом при різних умовах.
64
        $directory = scandir($type_dir, SCANDIR_SORT_ASCENDING);
65
66
        foreach ($directory as $file_mock) {
67
            if (is_file($type_dir . '/' . $file_mock)) {
68
                $type_mock = basename($file_mock, 'TypeMock.php');
69
                $type_list[] = strtolower($type_mock);
70
            }
71
        }
72
73
        return $type_list;
74
    }
75
76
}