|
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
|
|
|
|
|
|
|
|
|
|
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
|
|
|
} |
|
|
|
|
|
|
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
|
|
|
} |