DNSisAlreadyConfigured::dnsResolutionIsOk()   B
last analyzed

Complexity

Conditions 8
Paths 13

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 11
nc 13
nop 2
dl 0
loc 18
rs 7.7777
c 0
b 0
f 0
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