|
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
|
|
|
class TypeEnumBuilder |
|
13
|
|
|
{ |
|
14
|
|
|
// available types |
|
15
|
|
|
protected static $boolean = "boolean"; |
|
16
|
|
|
protected static $integer = "integer"; |
|
17
|
|
|
protected static $double = "double"; |
|
18
|
|
|
protected static $string = "string"; |
|
19
|
|
|
protected static $array = "array"; |
|
20
|
|
|
protected static $object = "object"; |
|
21
|
|
|
protected static $resource = "resource"; |
|
22
|
|
|
protected static $null = "null"; |
|
23
|
|
|
protected static $unknown = "unknown"; |
|
24
|
|
|
|
|
25
|
|
|
public static function rebuild() |
|
26
|
|
|
{ |
|
27
|
|
|
$typeList = self::getTypeList(); |
|
28
|
|
|
|
|
29
|
|
|
$property_list = []; |
|
30
|
|
|
|
|
31
|
|
|
foreach ($typeList as $type) { |
|
32
|
|
|
$property_name = strtoupper($type); |
|
33
|
|
|
if (5 > strlen($type)) { |
|
34
|
|
|
$no_inspect_name = "/** @noinspection PhpConstantNamingConventionInspection */\n\t\t"; |
|
35
|
|
|
$property_name = $no_inspect_name . $property_name; |
|
36
|
|
|
} |
|
37
|
|
|
$property_list[] = "public const $property_name = \"$type\";"; |
|
38
|
|
|
|
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$property_code = implode("\n\t", $property_list); |
|
42
|
|
|
|
|
43
|
|
|
$template = file_get_contents(__DIR__ . '/TypeEnum.tpl'); |
|
44
|
|
|
|
|
45
|
|
|
$code = str_replace("{PROPERTY}", $property_code, $template); |
|
46
|
|
|
|
|
47
|
|
|
file_put_contents(__DIR__ . "/TypeEnum.php", $code); |
|
48
|
|
|
|
|
49
|
|
|
} |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return array |
|
53
|
|
|
*/ |
|
54
|
|
|
private static function getTypeList() |
|
55
|
|
|
{ |
|
56
|
|
|
$typeList = []; |
|
57
|
|
|
|
|
58
|
|
|
$type_dir = __DIR__ . "/Type"; |
|
59
|
|
|
$directory = scandir($type_dir); |
|
60
|
|
|
|
|
61
|
|
|
foreach ($directory as $file) { |
|
62
|
|
|
if (is_file($type_dir . '/' . $file)) { |
|
63
|
|
|
$type = basename($file, "TypeMock.php"); |
|
64
|
|
|
$typeList[] = strtolower($type); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $typeList; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
} |