1 | <?php |
||
50 | class SiteAliasName |
||
51 | { |
||
52 | protected $location; |
||
53 | protected $sitename; |
||
54 | protected $env; |
||
55 | |||
56 | /** |
||
57 | * Match the parts of a regex name. |
||
58 | */ |
||
59 | const ALIAS_NAME_REGEX = '%^@?([a-zA-Z0-9_-]+)(\.[a-zA-Z0-9_-]+)?(\.[a-zA-Z0-9_-]+)?$%'; |
||
60 | |||
61 | /** |
||
62 | * Create a new site alias name |
||
63 | * |
||
64 | * @param string $item |
||
65 | * @return SiteAliasName |
||
66 | */ |
||
67 | public static function parse($item) |
||
73 | |||
74 | /** |
||
75 | * Creae a SiteAliasName object from an alias name string. |
||
76 | * |
||
77 | * @param string $sitename The alias name for the site. |
||
78 | * @param string $env The name for the site's environment. |
||
79 | */ |
||
80 | public function __construct($sitename = null, $env = null) |
||
86 | |||
87 | /** |
||
88 | * Convert an alias name back to a string. |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | public function __toString() |
||
103 | |||
104 | /** |
||
105 | * Determine whether or not the provided name is an alias name. |
||
106 | * |
||
107 | * @param string $aliasName |
||
108 | * @return bool |
||
109 | */ |
||
110 | public static function isAliasName($aliasName) |
||
118 | |||
119 | /** |
||
120 | * Return the sitename portion of the alias name. By definition, |
||
121 | * every alias must have a sitename. If the site name is implicit, |
||
122 | * then 'self' is assumed. |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | public function sitename() |
||
130 | |||
131 | /** |
||
132 | * Set the sitename portion of the alias name |
||
133 | * |
||
134 | * @param string $sitename |
||
135 | */ |
||
136 | public function setSitename($sitename) |
||
141 | |||
142 | /** |
||
143 | * In general, all aliases have a sitename. The time when one will not |
||
144 | * is when an environment name `@env` is used as a shortcut for `@self.env` |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | public function hasSitename() |
||
152 | |||
153 | /** |
||
154 | * Return true if this alias name contains an 'env' portion. |
||
155 | * |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function hasEnv() |
||
162 | |||
163 | /** |
||
164 | * Set the environment portion of the alias name. |
||
165 | * |
||
166 | * @param string |
||
167 | */ |
||
168 | public function setEnv($env) |
||
173 | |||
174 | /** |
||
175 | * Return the 'env' portion of the alias name. |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | public function env() |
||
183 | |||
184 | /** |
||
185 | * Return true if this alias name contains a 'location' portion |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function hasLocation() |
||
192 | |||
193 | /** |
||
194 | * Set the 'loation' portion of the alias name. |
||
195 | * @param string $location |
||
196 | */ |
||
197 | public function setLocation($location) |
||
202 | |||
203 | /** |
||
204 | * Return the 'location' portion of the alias name. |
||
205 | * |
||
206 | * @param string |
||
207 | */ |
||
208 | public function location() |
||
212 | |||
213 | /** |
||
214 | * Return true if this alias name is the 'self' alias. |
||
215 | * |
||
216 | * @return bool |
||
217 | */ |
||
218 | public function isSelf() |
||
222 | |||
223 | /** |
||
224 | * Return true if this alias name is the 'none' alias. |
||
225 | */ |
||
226 | public function isNone() |
||
230 | |||
231 | /** |
||
232 | * Convert the parts of an alias name to its various component parts. |
||
233 | * |
||
234 | * @param string $aliasName a string representation of an alias name. |
||
235 | */ |
||
236 | protected function doParse($aliasName) |
||
275 | |||
276 | /** |
||
277 | * Process an alias name provided as '@sitename'. |
||
278 | * |
||
279 | * @param string $sitename |
||
280 | * @return true |
||
281 | */ |
||
282 | protected function processSingleItem($item) |
||
292 | |||
293 | /** |
||
294 | * Determine whether the requested name is a special alias name. |
||
295 | * |
||
296 | * @param string $item |
||
297 | * @return boolean |
||
298 | */ |
||
299 | protected function isSpecialAliasName($item) |
||
303 | } |
||
304 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.