1 | <?php |
||
54 | class BuildTypeFromEtcIssue |
||
55 | { |
||
56 | /** |
||
57 | * use /etc/issue (if it exists) to work out what operating system we |
||
58 | * are looking at |
||
59 | * |
||
60 | * @param string $path |
||
61 | * path to the file to parse |
||
62 | * @return null|OsType |
||
|
|||
63 | * OsType if we can determine the operating system |
||
64 | * null if we cannot |
||
65 | */ |
||
66 | public function __invoke($path = '/etc/issue') |
||
70 | |||
71 | /** |
||
72 | * use /etc/issue (if it exists) to work out what operating system we |
||
73 | * are looking at |
||
74 | * |
||
75 | * @return null|OsType |
||
76 | * OsType if we can determine the operating system |
||
77 | * null if we cannot |
||
78 | */ |
||
79 | public function inDefaultLocation() |
||
83 | |||
84 | /** |
||
85 | * use /etc/issue (if it exists) to work out what operating system we |
||
86 | * are looking at |
||
87 | * |
||
88 | * @param string $path |
||
89 | * path to the file to parse |
||
90 | * @return null|OsType |
||
91 | * OsType if we can determine the operating system |
||
92 | * null if we cannot |
||
93 | */ |
||
94 | public static function from($path) |
||
116 | |||
117 | /** |
||
118 | * does the given regex match our file |
||
119 | * |
||
120 | * @param string $type |
||
121 | * the OsType class to return if the regex matches |
||
122 | * @param string $regex |
||
123 | * the regex to try |
||
124 | * @param string $fileContents |
||
125 | * the text that we apply the regex to |
||
126 | * @return null|OsType |
||
127 | * OsType if the regex matches |
||
128 | * null otherwise |
||
129 | */ |
||
130 | private static function matchTypeToRegex($type, $regex, $fileContents) |
||
143 | |||
144 | /** |
||
145 | * a map of regexes to OsType classes |
||
146 | * |
||
147 | * @var array |
||
148 | */ |
||
149 | private static $osTypes = [ |
||
150 | "|^CentOS release (?<version>\d+\.\d+)|" => CentOS::class, |
||
151 | "|^Ubuntu (?<version>\d+\.\d+)|" => Ubuntu::class, |
||
152 | ]; |
||
153 | } |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.