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 ( d70a9b...6b18d7 )
by Oleg
02:56
created

TelematicsVendor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 13
loc 78
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 11 3
A GetTelematicsVendors() 13 13 1
A GetRandomVendorID() 0 21 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Route4Me;
3
4
use Route4Me\Common;
5
use Route4Me\Exception\BadParam;
6
use Route4Me\Enum\Endpoint;
7
8
class TelematicsVendor extends Common
9
{
10
    public $vendor_id; // Telematics Vendor id
11
    public $is_integrated; // If 1, the vendor is integrated in Route4Me 
12
    public $page; // starting page
13
    public $per_page; // Vendors per page in a response
14
    public $country; // Country Alpha 2 code
15
    public $feature; // Vendor's feature
16
    public $search; // Searched text
17
    public $vendors; // Comma-delimited list of the vendors IDs.
18
    
19
    public static function fromArray(array $params) {
20
        $vendorsParameters = new TelematicsVendor();
21
        
22
        foreach ($params as $key => $value) {
23
            if (property_exists($vendorsParameters, $key)) {
24
                $vendorsParameters->{$key} = $value;
25
            }
26
        }
27
        
28
        return $vendorsParameters;
29
    }
30
    
31 View Code Duplication
    public static function GetTelematicsVendors($params) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
        Route4Me::setBaseUrl(Endpoint::TELEMATICS_VENDORS);
33
        
34
        $allQueryFields = array('vendor_id', 'is_integrated', 'page', 'per_page', 'country', 'feature', 'search', 'vendors');
35
36
        $vendors = Route4Me::makeRequst(array(
37
            'url'    => "",
38
            'method' => 'GET',
39
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
40
        ));
41
42
        return $vendors;
43
    }
44
45
    public static function GetRandomVendorID($offset, $limit) {
46
        $allVendors  = self::GetTelematicsVendors(null);
47
        $vendorsNumber = sizeof($allVendors['vendors']);
48
        
49
        if ($vendorsNumber < $limit) {
50
            if ($vendorsNumber > $offset) {
51
                $limit = $vendorsNumber;
52
            } else {
53
                if ($vendorsNumber == $offset) {
54
                    return $allVendors['vendors'][$offset]->{'vendor_id'};
55
                } else {
56
                    echo "The vendors numbers are less than offset";
57
                    return null;
58
                }
59
            }
60
        }
61
        
62
        $randNumber = rand($offset, $limit);
63
        
64
        return $allVendors['vendors'][$randNumber]['id'];
65
    }
66
    
67
    /*
68
    public static function GetTelematicsVendor($params) {
69
        Route4Me::setBaseUrl(Endpoint::TELEMATICS_VENDORS);
70
        
71
        $allQueryFields = array('vendor_id', 'is_integrated', 'page', 'per_page', 'country', 'feature', 'search', 'vendors');
72
        
73
        $query = Route4Me::generateRequestParameters($allQueryFields, $params);
74
75
        $vendors = Route4Me::makeRequst(array(
76
            'url'    => "",
77
            'method' => 'GET',
78
            'query'  => Route4Me::generateRequestParameters($allQueryFields, $params)
79
        ));
80
81
        return $vendors;
82
    }
83
    */
84
    
85
}
86