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) |
||
110 | |||
111 | /** |
||
112 | * do we have a regex that matches the contents of our file? |
||
113 | * |
||
114 | * @param string $fileContents |
||
115 | * the contents of the file to check |
||
116 | * @return null|OsType |
||
117 | * OsType if we can determine the operating system |
||
118 | * null if we cannot |
||
119 | */ |
||
120 | private static function matchContentsToType($fileContents) |
||
130 | |||
131 | /** |
||
132 | * does the given regex match our file |
||
133 | * |
||
134 | * @param string $type |
||
135 | * the OsType class to return if the regex matches |
||
136 | * @param string $regex |
||
137 | * the regex to try |
||
138 | * @param string $fileContents |
||
139 | * the text that we apply the regex to |
||
140 | * @return null|OsType |
||
141 | * OsType if the regex matches |
||
142 | * null otherwise |
||
143 | */ |
||
144 | private static function matchTypeToRegex($type, $regex, $fileContents) |
||
157 | |||
158 | /** |
||
159 | * a map of regexes to OsType classes |
||
160 | * |
||
161 | * @var array |
||
162 | */ |
||
163 | private static $osTypes = [ |
||
164 | "|^CentOS release (?<version>\d+\.\d+)|" => CentOS::class, |
||
165 | "|^Ubuntu (?<version>\d+\.\d+)|" => Ubuntu::class, |
||
166 | ]; |
||
167 | } |
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.