TestCaseTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A migrateDatabase() 0 4 1
A overrideSubDomain() 0 20 4
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