Engine::getError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Aszone\SearchHacking\Engines;
4
5
abstract class Engine implements EngineInterface
6
{
7
    protected $error;
8
    protected $listOfVirginProxies;
9
    protected $usingVirginProxies;
10
    protected $tor;
11
    protected $commandData;
12
    protected $proxies;
13
    protected $proxy;
14
15
    private $defaultCommandData = [
16
        'dork' => false,
17
        'pl' => false,
18
        'tor' => false,
19
        'virginProxies' => false,
20
        'proxyOfSites' => false,
21
    ];
22
23
    public function __construct(array $data)
24
    {
25
        $this->commandData = array_merge($this->defaultCommandData, $data);
26
27
        if ($this->hasProxy()) {
28
            $this->proxies = new Proxies();
29
        }
30
31
        if ($this->commandData['tor']) {
32
            $this->proxy = $this->proxies->getTor();
33
        }
34
35
        if ($this->commandData['proxyOfSites']) {
36
            $this->proxy = $this->proxies->getProxyOfSites();
37
        }
38
39
        if ($this->commandData['virginProxies']) {
40
            $this->listOfVirginProxies = $this->proxies->getVirginSiteProxies();
41
            $this->usingVirginProxies = true;
42
        }
43
    }
44
45
    public function validate()
46
    {
47
        if ($this->commandData['virginProxies'] && !$this->proxies->checkVirginProxiesExist()) {
48
            $error['type'] = 'vp';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$error was never initialized. Although not strictly required by PHP, it is generally a good practice to add $error = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
49
            $error['result'] = 'There is no list of botnets Virgin Proxy';
50
51
            $this->error = $error;
52
53
            return false;
54
        }
55
56
        return true;
57
    }
58
59
    public function hasProxy()
60
    {
61
        return $this->commandData['virginProxies']
62
                || $this->commandData['proxyOfSites']
63
                || $this->commandData['tor'];
64
    }
65
66
    public function getError()
67
    {
68
        return $this->error;
69
    }
70
71
    public function output($value)
72
    {
73
        echo $value;
74
    }
75
76
    public function run()
77
    {
78
    }
79
}
80