GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WebHostReportEntryCollection::__construct()   B
last analyzed

Complexity

Conditions 9
Paths 24

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 41
rs 7.7084
cc 9
nc 24
nop 1
1
<?php
2
namespace Checkdomain\Comodo\Model\Result;
3
use Checkdomain\Comodo\Model\Exception\UnknownException;
4
5
/**
6
 * Class WebHostReportEntryCollection
7
 */
8
class WebHostReportEntryCollection implements \Iterator
9
{
10
11
    /**
12
     * @var int
13
     */
14
    private $position = 0;
15
16
    /**
17
     * @var array
18
     */
19
    private $entries = [];
20
21
    /**
22
     *
23
     */
24
    public function rewind() {
25
        $this->position = 0;
26
    }
27
28
    /**
29
     * @return mixed
30
     */
31
    public function current() {
32
        return $this->entries[$this->position];
33
    }
34
35
    /**
36
     * @return int
37
     */
38
    public function key() {
39
        return $this->position;
40
    }
41
42
    /**
43
     *
44
     */
45
    public function next() {
46
        ++$this->position;
47
    }
48
49
    /**
50
     * @param WebHostReportEntry $webHostReportEntry
51
     * @return WebHostReportEntryCollection
52
     */
53
    public function add($webHostReportEntry) {
54
        $this->entries[] = $webHostReportEntry;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @return bool
61
     */
62
    public function valid() {
63
        return isset($this->entries[$this->position]);
64
    }
65
66
    /**
67
     * WebHostReportEntryCollection constructor.
68
     * @param $webHostReportRawResult
69
     *
70
     * @return WebHostReportEntryCollection
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
71
     */
72
    public function __construct($webHostReportRawResult)
73
    {
74
        $pos = 0;
75
        foreach ($webHostReportRawResult as $key => $line) {
76
            $keyArray = explode('_', $key);
77
78
            if (is_numeric($keyArray[0])) {
79
                if ($pos < $keyArray[0]) {
80
                    $pos = $keyArray[0];
81
                    $entry = new WebHostReportEntry();
82
                    $this->add($entry);
83
                    $entry->setRowNumber($pos);
84
                }
85
86
                switch (count($keyArray)) {
87
                    case 2:
88
                        $setter = 'set' . ucwords($keyArray[1]);
89
                        $itempos = 0;
90
                        break;
91
                    case 3:
92
                        if ($itempos < $keyArray[1]) {
0 ignored issues
show
Bug introduced by
The variable $itempos does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
93
                            $item = new WebHostReportEntryItem();
94
                            $entry->getItems()->add($item);
0 ignored issues
show
Bug introduced by
The variable $entry does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Documentation introduced by
$item is of type object<Checkdomain\Comod...WebHostReportEntryItem>, but the function expects a object<Checkdomain\Comod...ult\WebHostReportEntry>.

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...
95
                            $itempos = $keyArray[1];
96
                        }
97
                        $itemsetter = 'set' . ucwords($keyArray[2]);
98
                        if (method_exists($item, $itemsetter)) {
99
                            $item->$itemsetter($webHostReportRawResult[$key]);
0 ignored issues
show
Bug introduced by
The variable $item does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
100
                        }
101
                        break;
102
                    default:
103
                        throw new UnknownException(99, 'UnknownException', 'Malformed result from api call.');
104
                }
105
                if (method_exists($entry, $setter)) {
106
                    $entry->$setter($webHostReportRawResult[$key]);
0 ignored issues
show
Bug introduced by
The variable $setter does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
107
                }
108
            }
109
        }
110
111
        return $this;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
112
    }
113
114
}
115