Location   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 60
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getLineNumber() 0 3 1
A getAbsoluteFileName() 0 3 1
A fromRelativeFileName() 0 8 1
A fromAbsoluteFileName() 0 8 1
A getRelativeFileName() 0 3 1
A compareTo() 0 7 2
A __construct() 0 5 1
1
<?php
2
3
/**
4
 * Static Analysis Results Baseliner (sarb).
5
 *
6
 * (c) Dave Liddament
7
 *
8
 * For the full copyright and licence information please view the LICENSE file distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Domain\Common;
14
15
final class Location
16
{
17
    /**
18
     * @throws InvalidPathException
19
     */
20
    public static function fromAbsoluteFileName(
21
        AbsoluteFileName $absoluteFileName,
22
        ProjectRoot $projectRoot,
23
        LineNumber $lineNumber,
24
    ): self {
25
        $relativeFileName = $projectRoot->getPathRelativeToRootDirectory($absoluteFileName);
26
27
        return new self($absoluteFileName, $relativeFileName, $lineNumber);
28
    }
29
30
    /**
31
     * @throws InvalidPathException
32
     */
33
    public static function fromRelativeFileName(
34
        RelativeFileName $relativeFileName,
35
        ProjectRoot $projectRoot,
36
        LineNumber $lineNumber,
37
    ): self {
38
        $absoluteFileName = $projectRoot->getAbsoluteFileName($relativeFileName);
39
40
        return new self($absoluteFileName, $relativeFileName, $lineNumber);
41
    }
42
43
    private function __construct(
44
        private AbsoluteFileName $absoluteFileName,
45
        private RelativeFileName $relativeFileName,
46
        private LineNumber $lineNumber,
47
    ) {
48
    }
49
50
    public function getRelativeFileName(): RelativeFileName
51
    {
52
        return $this->relativeFileName;
53
    }
54
55
    public function getLineNumber(): LineNumber
56
    {
57
        return $this->lineNumber;
58
    }
59
60
    public function getAbsoluteFileName(): AbsoluteFileName
61
    {
62
        return $this->absoluteFileName;
63
    }
64
65
    /**
66
     * Used for ordering Locations, first by FileName then by line number.
67
     */
68
    public function compareTo(self $other): int
69
    {
70
        if ($this->relativeFileName->getFileName() !== $other->relativeFileName->getFileName()) {
71
            return $this->relativeFileName->getFileName() <=> $other->relativeFileName->getFileName();
72
        }
73
74
        return $this->lineNumber->getLineNumber() <=> $other->lineNumber->getLineNumber();
75
    }
76
}
77