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.

Itinerary   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 53
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A legs() 0 4 1
A sameValueAs() 0 20 2
1
<?php
2
/*
3
 * This file is part of the prooph/php-ddd-cargo-sample package.
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
declare(strict_types = 1);
10
11
namespace Codeliner\CargoBackend\Model\Cargo;
12
13
use Doctrine\Common\Collections\ArrayCollection;
14
15
/**
16
 *  Itinerary
17
 *
18
 * The Itinerary is a ValueObject that describes a route of a cargo.
19
 * It is composed of one or more Legs.
20
 * Each Leg describes a part of the entire route, f.e. from one port to another.
21
 * 
22
 * @author Alexander Miertsch <[email protected]>
23
 */
24
class Itinerary
25
{
26
    /**
27
     * @var Leg[]
28
     */
29
    protected $legs;
30
31
    /**
32
     * @param Leg[] $legs
33
     */
34
    public function __construct(array $legs)
35
    {
36
        $this->legs = $legs;
37
    }
38
    
39
    /**
40
     * @return Leg[] Immutable list of Legs
41
     */
42
    public function legs()
43
    {
44
        return $this->legs;
45
    }
46
47
    /**
48
     * @param Itinerary $other
49
     * @return bool
50
     */
51
    public function sameValueAs(Itinerary $other): bool
52
    {
53
        //We use doctrine's ArrayCollection only to ease comparison
54
        //If Legs would be stored in an ArrayCollection hole the time
55
        //Itinerary itself would not be immutable,
56
        //cause a client could call $itinerary->legs()->add($anotherLeg);
57
        //Keeping ValueObjects immutable is a rule of thumb
58
        $myLegs = new ArrayCollection($this->legs());
59
        $otherLegs = new ArrayCollection($other->legs());
60
        
61
        if ($myLegs->count() !== $otherLegs->count()) {
62
            return false;
63
        }
64
        
65
        return $myLegs->forAll(function($index, Leg $leg) use ($otherLegs) {
66
           return $otherLegs->exists(function($otherIndex, Leg $otherLeg) use ($leg) {
67
               return $otherLeg->sameValueAs($leg);
68
           });
69
        });
70
    }
71
72
    /**
73
     * surrogate key, required by doctrine
74
     */
75
    private $id;
76
}
77