Violation::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\DependencyGuard\Violation;
8
9
use Composer\Package\PackageInterface;
10
use Mediact\DependencyGuard\Candidate\CandidateInterface;
11
use Mediact\DependencyGuard\Php\SymbolIteratorInterface;
12
13
class Violation implements ViolationInterface
14
{
15
    /** @var string */
16
    private $message;
17
18
    /** @var CandidateInterface */
19
    private $result;
20
21
    /**
22
     * Constructor.
23
     *
24
     * @param string             $message
25
     * @param CandidateInterface $result
26
     */
27 1
    public function __construct(string $message, CandidateInterface $result)
28
    {
29 1
        $this->message = $message;
30 1
        $this->result  = $result;
31 1
    }
32
33
    /**
34
     * Get the violation message.
35
     *
36
     * @return string
37
     */
38 1
    public function getMessage(): string
39
    {
40 1
        return $this->message;
41
    }
42
43
    /**
44
     * Get the composer package.
45
     *
46
     * @return PackageInterface
47
     */
48 1
    public function getPackage(): PackageInterface
49
    {
50 1
        return $this->result->getPackage();
51
    }
52
53
    /**
54
     * Get the symbols.
55
     *
56
     * @return SymbolIteratorInterface
57
     */
58 1
    public function getSymbols(): SymbolIteratorInterface
59
    {
60 1
        return $this->result->getSymbols();
61
    }
62
63
    /**
64
     * Specify data that should be serialized to JSON.
65
     *
66
     * @return array
67
     */
68 1
    public function jsonSerialize(): array
69
    {
70
        return [
71 1
            'message' => $this->message,
72 1
            'package' => $this->getPackage()->getName(),
73 1
            'symbols' => $this->getSymbols()
74
        ];
75
    }
76
}
77