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.

CargoRoutingDto   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 125
Duplicated Lines 6.4 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 12
lcom 1
cbo 3
dl 8
loc 125
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getFinalDestination() 0 4 1
A addLeg() 0 4 1
A getLegs() 0 4 1
A getOrigin() 0 4 1
A getTrackingId() 0 4 1
A setFinalDestination() 0 6 1
A setLegs() 0 8 2
A setOrigin() 0 6 1
A setTrackingId() 0 6 1
A getArrayCopy() 8 20 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
 * This file is part of the prooph/php-ddd-cargo-sample.
4
 * (c) Alexander Miertsch <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 * 
9
 * Date: 29.03.14 - 16:59
10
 */
11
declare(strict_types = 1);
12
13
namespace Codeliner\CargoBackend\Application\Booking\Dto;
14
use Assert\Assertion;
15
16
/**
17
 * Class CargoRoutingDto
18
 *
19
 * @package CargoBackend\API\Booking\Dto
20
 * @author Alexander Miertsch <[email protected]>
21
 */
22
class CargoRoutingDto 
23
{
24
    /**
25
     * @var string
26
     */
27
    private $trackingId;
28
29
    /**
30
     * @var string
31
     */
32
    private $origin;
33
34
    /**
35
     * @var string
36
     */
37
    private $finalDestination;
38
39
    /**
40
     * @var LegDto[]
41
     */
42
    private $legs = array();
43
44
    /**
45
     * @param string $finalDestination
46
     */
47
    public function setFinalDestination(string $finalDestination)
48
    {
49
        \Assert\that($finalDestination)->notEmpty()->string();
50
51
        $this->finalDestination = $finalDestination;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getFinalDestination(): string
58
    {
59
        return $this->finalDestination;
60
    }
61
62
    /**
63
     * @param LegDto[] $legs
64
     */
65
    public function setLegs(array $legs): array
66
    {
67
        foreach($legs as $leg) {
68
            Assertion::isInstanceOf($leg, LegDto::class);
69
        }
70
71
        $this->legs = $legs;
72
    }
73
74
    public function addLeg(LegDto $leg)
75
    {
76
        $this->legs[] = $leg;
77
    }
78
79
    /**
80
     * @return LegDto[]
81
     */
82
    public function getLegs(): array
83
    {
84
        return $this->legs;
85
    }
86
87
    /**
88
     * @param string $origin
89
     */
90
    public function setOrigin(string $origin)
91
    {
92
        Assertion::notEmpty($origin);
93
94
        $this->origin = $origin;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getOrigin()
101
    {
102
        return $this->origin;
103
    }
104
105
    /**
106
     * @param string $trackingId
107
     */
108
    public function setTrackingId(string $trackingId)
109
    {
110
        Assertion::uuid($trackingId);
111
112
        $this->trackingId = $trackingId;
113
    }
114
115
    /**
116
     * @return string
117
     */
118
    public function getTrackingId(): string
119
    {
120
        return $this->trackingId;
121
    }
122
123
    /**
124
     * @return array
125
     */
126
    public function getArrayCopy(): array
127
    {
128
        $legsArrayCopy = array();
129
130 View Code Duplication
        foreach ($this->getLegs() as $leg) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
131
            $legsArrayCopy[] = array(
132
                'load_location'   => $leg->getLoadLocation(),
133
                'unload_location' => $leg->getUnloadLocation(),
134
                'load_time'       => $leg->getLoadTime(),
135
                'unload_time'     => $leg->getUnloadTime()
136
            );
137
        }
138
139
        return array(
140
            'tracking_id'        => $this->getTrackingId(),
141
            'origin'             => $this->getOrigin(),
142
            'final_destination'  => $this->getFinalDestination(),
143
            'legs'               => $legsArrayCopy
144
        );
145
    }
146
}
147