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.
Completed
Push — master ( 7b7e14...7726e9 )
by Kevin
01:35
created

Transport   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 59
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getCorrectTransportName() 0 16 4
1
<?php
2
3
4
namespace HomeDesignShops\LaravelBolComRetailer\Models;
5
6
7
class Transport
8
{
9
    /**
10
     * @var string
11
     */
12
    public $transporterCode;
13
14
    /**
15
     * @var string
16
     */
17
    public $trackingCode;
18
19
    /**
20
     * The key is de Bol.com shipment name.
21
     * The values will be mapped to the correct shipment name.
22
     *
23
     * @var array
24
     */
25
    protected $transportCodes = [
26
        'tnt' => [
27
            'postnl',
28
        ],
29
        'gls' => []
30
    ];
31
32
    /**
33
     * TransportItem constructor.
34
     * @param string $transporterCode
35
     * @param string $trackingCode
36
     */
37
    public function __construct(string $transporterCode, string $trackingCode)
38
    {
39
        $this->transporterCode = $this->getCorrectTransportName($transporterCode);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getCorrectTransportName($transporterCode) can also be of type integer or false. However, the property $transporterCode is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
40
        $this->trackingCode = $trackingCode;
41
    }
42
43
    /**
44
     * Returns the correct transport name.
45
     *
46
     * @param $name
47
     * @return bool|int|string
48
     */
49
    protected function getCorrectTransportName($name)
50
    {
51
        $name = strtolower($name);
52
53
        if(isset($this->shipmentMapping[$name])) {
0 ignored issues
show
Bug introduced by
The property shipmentMapping 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...
54
            return $name;
55
        }
56
57
        foreach ($this->transportCodes as $key => $shipments) {
58
            if(in_array($name, $shipments, true)) {
59
                return $key;
60
            }
61
        }
62
63
        return false;
64
    }
65
}
66