Issues (38)

src/Domain/Common/PreviousLocation.php (2 issues)

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
use Webmozart\Assert\Assert;
16
17
final class PreviousLocation
18
{
19
    public static function noPreviousLocation(): self
20
    {
21
        return new self(null, null);
22
    }
23
24
    public static function fromFileNameAndLineNumber(RelativeFileName $relativeFileName, LineNumber $lineNumber): self
25
    {
26
        return new self($relativeFileName, $lineNumber);
27
    }
28
29
    private function __construct(
30
        private ?RelativeFileName $relativeFileName,
31
        private ?LineNumber $lineNumber,
32
    ) {
33
    }
34
35
    public function isNoPreviousLocation(): bool
36
    {
37
        return null === $this->relativeFileName;
38
    }
39
40
    public function getRelativeFileName(): RelativeFileName
41
    {
42
        Assert::notNull($this->relativeFileName, 'Trying to get FileName when PreviousLocation is not set');
43
44
        return $this->relativeFileName;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->relativeFileName could return the type null which is incompatible with the type-hinted return DaveLiddament\StaticAnal...Common\RelativeFileName. Consider adding an additional type-check to rule them out.
Loading history...
45
    }
46
47
    public function getLineNumber(): LineNumber
48
    {
49
        Assert::notNull($this->lineNumber, 'Trying to get LineNumber when PreviousLocation is not set');
50
51
        return $this->lineNumber;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->lineNumber could return the type null which is incompatible with the type-hinted return DaveLiddament\StaticAnal...omain\Common\LineNumber. Consider adding an additional type-check to rule them out.
Loading history...
52
    }
53
}
54