Tracking   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 58.82 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 20
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A track() 9 9 1
A trackMultiple() 11 11 2

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
3
namespace Nickcheek\USPSLookup\Service;
4
5
use Nickcheek\USPSLookup\USPSLookup;
6
7
class Tracking extends USPSLookup
8
{
9
    /**
10
     * Tracking a package by USPS Tracking number
11
     * @param $trackingnumber
12
     * @return \SimpleXMLElement
13
     */
14 View Code Duplication
    public static function track(string $trackingnumber): object
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...
15
    {
16
        $track = new \SimpleXMLElement("<TrackRequest></TrackRequest>");
17
        $track->addAttribute('USERID', self::$USPSuser);
18
        $pack = $track->addChild('TrackID');
19
        $pack->addAttribute('ID', $trackingnumber);
20
        $url = self::$service . 'TrackV2&XML=' . $track->asXML();
21
        return simplexml_load_file($url);
22
    }
23
24
    /**
25
     * Tracking more than one package by USPS Tracking number array
26
     * @param $trackingarray (Array)
27
     * @return \SimpleXMLElement
28
     */
29 View Code Duplication
    public static function trackMultiple(array $trackingarray): object
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...
30
    {
31
        $track = new \SimpleXMLElement("<TrackRequest></TrackRequest>");
32
        $track->addAttribute('USERID', self::$USPSuser);
33
        foreach($trackingarray as $trackingnumber){
34
            $pack = $track->addChild('TrackID');
35
            $pack->addAttribute('ID', $trackingnumber);
36
        }
37
        $url = self::$service . 'TrackV2&XML=' . $track->asXML();
38
        return simplexml_load_file($url);
39
    }
40
}
41