TestCaseTrait::overrideSubDomain()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 5
nop 1
1
<?php
2
3
namespace App\Ship\Parents\Tests\PhpUnit;
4
5
use Artisan;
6
7
/**
8
 * Class TestCaseTrait
9
 *
10
 * @author  Mahmoud Zalt  <[email protected]>
11
 */
12
trait TestCaseTrait
13
{
14
15
    /**
16
     * Migrate the database.
17
     */
18
    public function migrateDatabase()
19
    {
20
        Artisan::call('migrate');
21
    }
22
23
    /**
24
     * Override default URL subDomain in case you want to change it for some tests
25
     *
26
     * @param null $url
27
     */
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;
0 ignored issues
show
Bug introduced by
The property baseUrl does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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;
0 ignored issues
show
Bug introduced by
The property subDomain does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
46
        return $this->baseUrl = $newSubDomain;
47
    }
48
}
49