1 | <?php |
||
57 | class BuildTypeFromLsbRelease |
||
58 | { |
||
59 | /** |
||
60 | * use the output of /usr/bin/lsb_release (if present) to determine which |
||
61 | * Linux distro we are using |
||
62 | * |
||
63 | * @param string $path |
||
64 | * path to the binary to run |
||
65 | * @return null|OsType |
||
|
|||
66 | * OsType if we know which Linux distro we are using |
||
67 | * null otherwise |
||
68 | */ |
||
69 | public function __invoke($path = "/usr/bin/lsb_release") |
||
73 | |||
74 | /** |
||
75 | * use the output of /usr/bin/lsb_release (if present) to determine which |
||
76 | * Linux distro we are using |
||
77 | * |
||
78 | * @return null|OsType |
||
79 | * OsType if we know which Linux distro we are using |
||
80 | * null otherwise |
||
81 | */ |
||
82 | public static function usingDefaultPath() |
||
86 | |||
87 | /** |
||
88 | * use the output of /usr/bin/lsb_release (if present) to determine which |
||
89 | * Linux distro we are using |
||
90 | * |
||
91 | * @param string $path |
||
92 | * path to the binary to run |
||
93 | * @return null|OsType |
||
94 | * OsType if we know which Linux distro we are using |
||
95 | * null otherwise |
||
96 | */ |
||
97 | public static function usingBinary($pathToBinary) |
||
113 | |||
114 | /** |
||
115 | * get the Linux distro name & version from /usr/bin/lsb_release |
||
116 | * |
||
117 | * @param string $pathToBinary |
||
118 | * the binary to call to get the LSB details |
||
119 | * @return array |
||
120 | * [0] is the Linux distro name |
||
121 | * [1] is the Linux distro version |
||
122 | */ |
||
123 | private static function getDistroDetails($pathToBinary) |
||
132 | |||
133 | /** |
||
134 | * call /usr/bin/lsb_release and return the output |
||
135 | * |
||
136 | * @param string $pathToBinary |
||
137 | * path to the binary to call |
||
138 | * @return string |
||
139 | * output from the binary |
||
140 | */ |
||
141 | private static function getOutputFromBinary($pathToBinary) |
||
157 | |||
158 | /** |
||
159 | * extract the info we need from the output of /usr/bin/lsb_release |
||
160 | * |
||
161 | * @param string $output |
||
162 | * the output from running the command |
||
163 | * @return array |
||
164 | * [0] is the Linux distro name |
||
165 | * [1] is the Linux distro version |
||
166 | */ |
||
167 | private static function extractDistroDetails($output) |
||
180 | |||
181 | /** |
||
182 | * extract a named field from the output of /usr/bin/lsb_release |
||
183 | * |
||
184 | * @param array $lines |
||
185 | * the output of /usr/bin/lsb_release |
||
186 | * @param string $fieldName |
||
187 | * the field that we are looking for |
||
188 | * @return string|null |
||
189 | * the value of the field (if found) |
||
190 | */ |
||
191 | private static function extractField($lines, $fieldName) |
||
199 | |||
200 | /** |
||
201 | * a map of distro names onto OsType classes |
||
202 | * @var array |
||
203 | */ |
||
204 | private static $osTypes = [ |
||
205 | 'CentOS' => CentOS::class, |
||
206 | 'Debian' => Debian::class, |
||
207 | 'Ubuntu' => Ubuntu::class, |
||
208 | ]; |
||
209 | } |
||
210 |
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.