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.

DomainMessage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 104
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A recordNow() 0 4 1
A getPlayHead() 0 4 1
A getMetadata() 0 4 1
A getPayload() 0 4 1
A getId() 0 4 1
A getRecordedOn() 0 4 1
A getType() 0 4 1
1
<?php
2
namespace SmoothPhp\Domain;
3
4
use DateTime;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, SmoothPhp\Domain\DateTime.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
5
use SmoothPhp\Contracts\Domain\DomainMessage as DomainMessageInterface;
6
7
/**
8
 * Class DomainMessage
9
 * @package SmoothPhp\Domain
10
 * @author Simon Bennett <[email protected]>
11
 */
12
final class DomainMessage implements DomainMessageInterface
13
{
14
    /**
15
     * @var int
16
     */
17
    private $playHead;
18
19
    /**
20
     * @var Metadata
21
     */
22
    private $metadata;
23
24
    /**
25
     * @var mixed
26
     */
27
    private $payload;
28
29
    /**
30
     * @var string
31
     */
32
    private $id;
33
34
    /**
35
     * @var DateTime
36
     */
37
    private $recordedOn;
38
39
    /**
40
     * @param string $id
41
     * @param int $playHead
42
     * @param Metadata $metadata
43
     * @param mixed $payload
44
     * @param DateTime $recordedOn
45 33
     */
46
    public function __construct($id, $playHead, Metadata $metadata, $payload, DateTime $recordedOn)
47 33
    {
48 33
        $this->id = $id;
49 33
        $this->playHead = $playHead;
50 33
        $this->metadata = $metadata;
51 33
        $this->payload = $payload;
52 33
        $this->recordedOn = $recordedOn;
53
    }
54
55
    /**
56
     * @param string   $id
57
     * @param int      $playHead
58
     * @param Metadata $metadata
59
     * @param mixed    $payload
60
     *
61
     * @return DomainMessage
62 21
     */
63
    public static function recordNow($id, $playHead, Metadata $metadata, $payload)
64 21
    {
65
        return new DomainMessage($id, $playHead, $metadata, $payload, new DateTime);
66
    }
67
68
    /**
69
     * @return int
70 6
     */
71
    public function getPlayHead()
72 6
    {
73
        return $this->playHead;
74
    }
75
76
    /**
77
     * @return Metadata
78 6
     */
79
    public function getMetadata()
80 6
    {
81
        return $this->metadata;
82
    }
83
84
    /**
85
     * @return mixed
86 12
     */
87
    public function getPayload()
88 12
    {
89
        return $this->payload;
90
    }
91
92
    /**
93
     * @return string
94 6
     */
95
    public function getId()
96 6
    {
97
        return $this->id;
98
    }
99
100
    /**
101
     * @return DateTime
102 6
     */
103
    public function getRecordedOn()
104 6
    {
105
        return $this->recordedOn;
106
    }
107
108
    /**
109
     * @return string
110 6
     */
111
    public function getType()
112 6
    {
113
        return strtr(get_class($this->payload), '\\', '.');
114
    }
115
}