1 | <?php |
||
51 | class BuildTypeFromEtcRedhatRelease |
||
52 | { |
||
53 | /** |
||
54 | * use /etc/redhat-release (if it exists) to work out what flavour of |
||
55 | * RedHat Linux we are looking at |
||
56 | * |
||
57 | * @param string $path |
||
58 | * path to the file to parse |
||
59 | * @return null|OsType |
||
|
|||
60 | * OsType if we can determine the operating system |
||
61 | * null if we cannot |
||
62 | */ |
||
63 | public function __invoke($path = '/etc/redhat-release') |
||
67 | |||
68 | /** |
||
69 | * use /etc/redhat-release (if it exists) to work out what flavour of |
||
70 | * RedHat Linux we are looking at |
||
71 | * |
||
72 | * @return null|OsType |
||
73 | * OsType if we can determine the operating system |
||
74 | * null if we cannot |
||
75 | */ |
||
76 | public function inDefaultLocation() |
||
80 | |||
81 | /** |
||
82 | * use /etc/redhat-release (if it exists) to work out what flavour of |
||
83 | * RedHat Linux we are looking at |
||
84 | * |
||
85 | * @param string $path |
||
86 | * path to the file to parse |
||
87 | * @return null|OsType |
||
88 | * OsType if we can determine the operating system |
||
89 | * null if we cannot |
||
90 | */ |
||
91 | public static function from($path) |
||
113 | |||
114 | /** |
||
115 | * does the given regex match our file |
||
116 | * |
||
117 | * @param string $type |
||
118 | * the OsType class to return if the regex matches |
||
119 | * @param string $regex |
||
120 | * the regex to try |
||
121 | * @param string $fileContents |
||
122 | * the text that we apply the regex to |
||
123 | * @return null|OsType |
||
124 | * OsType if the regex matches |
||
125 | * null otherwise |
||
126 | */ |
||
127 | private static function matchTypeToRegex($type, $regex, $fileContents) |
||
140 | |||
141 | /** |
||
142 | * a map of regexes to OsType classes |
||
143 | * |
||
144 | * @var array |
||
145 | */ |
||
146 | private static $osTypes = [ |
||
147 | "|^CentOS release (?<version>\d+\.\d+)|" => CentOS::class, |
||
148 | "|^CentOS Linux release (?<version>\d+\.\d+)|" => CentOS::class, |
||
149 | ]; |
||
150 | } |
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.