DNSisAlreadyConfigured   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B dnsResolutionIsOk() 0 18 8
A obtainDomain() 0 4 2
A obtainIp() 0 4 2
1
<?php
2
3
namespace Acacha\ForgePublish\Commands\Traits;
4
5
/**
6
 * Trait DNSisAlreadyConfigured
7
 *
8
 * @package Acacha\ForgePublish\Commands\Traits
9
 */
10
trait DNSisAlreadyConfigured
11
{
12
    /**
13
     * Check if DNS is already configured.
14
     *
15
     * @param null $domain
16
     * @param null $ip
17
     * @return bool
18
     */
19
    protected function dnsResolutionIsOk($domain = null, $ip = null)
20
    {
21
        if ($this->dnsAlreadyResolved) {
0 ignored issues
show
Bug introduced by
The property dnsAlreadyResolved 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...
22
            return true;
23
        }
24
25
        $domain = $domain ? $domain: $this->obtainDomain();
26
        $ip = $ip ? $ip: $this->obtainIp();
27
28
        if ($domain != null && $ip != null) {
29
            $resolved_ip = gethostbyname($domain);
30
            if ($resolved_ip != $domain && $resolved_ip == $ip) {
31
                $this->dnsAlreadyResolved = true;
32
                return true;
33
            }
34
        }
35
        return false;
36
    }
37
38
    /**
39
     * Obtain domain.
40
     *
41
     * @return mixed
42
     */
43
    protected function obtainDomain()
44
    {
45
        return $this->domain ? $this->domain : fp_env('ACACHA_FORGE_DOMAIN', null);
0 ignored issues
show
Bug introduced by
The property domain 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...
46
    }
47
48
    /**
49
     * Obtain IP.
50
     *
51
     * @return mixed
52
     */
53
    protected function obtainIp()
54
    {
55
        return $this->ip ? $this->ip : fp_env('ACACHA_FORGE_IP_ADDRESS', null);
0 ignored issues
show
Bug introduced by
The property ip 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...
56
    }
57
}
58