Yahoo::run()   C
last analyzed

Complexity

Conditions 7
Paths 13

Size

Total Lines 48
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 28
nc 13
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lenon
5
 * Date: 23/04/16
6
 * Time: 01:43.
7
 */
8
9
namespace Aszone\SearchHacking\Engines;
10
11
use Aszone\SearchHacking\Utils;
12
13
class Yahoo extends Engine
14
{
15
    public function run()
16
    {
17
        $exit = false;
18
        $count = 0;
19
        $numPaginator = 0;
20
        $countProxyVirgin = rand(0, count($this->listOfVirginProxies) - 1);
21
        $resultFinal = array();
22
23
        while ($exit == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
24
            if ($count != 0) {
25
                $numPaginator = (100 * $count) + 1;
26
            }
27
28
            $urlOfSearch = 'https://search.yahoo.com/search?p='.urlencode($this->commandData['dork']).'&fr=yfp-t-707&pz=100&b='.$numPaginator;
29
30
            $this->output('Page '.$count."\n");
31
32
            if ($this->commandData['virginProxies']) {
33
                $body = Utils::getBodyByVirginProxies($urlOfSearch, $this->listOfVirginProxies[$countProxyVirgin], $this->proxy);
34
35
                $arrLinks = Utils::getLinks($body);
36
37
                if ($countProxyVirgin == count($this->listOfVirginProxies) - 1) {
38
                    $countProxyVirgin = 0;
39
                } else {
40
                    ++$countProxyVirgin;
41
                }
42
            } else {
43
                $body = Utils::getBody($urlOfSearch, $this->proxy);
44
45
                $arrLinks = Utils::getLinks($body);
46
            }
47
48
            $this->output("\n".$urlOfSearch."\n");
49
50
            $results = Utils::sanitazeLinks($arrLinks);
0 ignored issues
show
Documentation introduced by
$arrLinks is of type object<Symfony\Component\DomCrawler\Crawler>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
52
            if ((count($results) == 0 and $body != 'repeat')) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
53
                $exit = true;
54
            }
55
56
            $resultFinal = array_merge($resultFinal, $results);
57
58
            ++$count;
59
        }
60
61
        return $resultFinal;
62
    }
63
}
64