Conditions | 4 |
Paths | 5 |
Total Lines | 20 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function overrideSubDomain($url = null) |
||
29 | { |
||
30 | // `subDomain` is a property defined in your class. |
||
31 | if (!property_exists($this, 'subDomain')) { |
||
32 | return; |
||
33 | } |
||
34 | |||
35 | $url = ($url) ? : $this->baseUrl; |
||
|
|||
36 | |||
37 | $info = parse_url($url); |
||
38 | |||
39 | $array = explode('.', $info['host']); |
||
40 | |||
41 | $withoutDomain = (array_key_exists(count($array) - 2, |
||
42 | $array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1]; |
||
43 | |||
44 | $newSubDomain = $info['scheme'] . '://' . $this->subDomain . '.' . $withoutDomain; |
||
45 | |||
46 | return $this->baseUrl = $newSubDomain; |
||
47 | } |
||
48 | } |
||
49 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: