Passed
Pull Request — master (#69)
by Dave
02:21
created

ParseException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocation() 0 3 1
A fromDiffParseException() 0 3 1
A __construct() 0 6 1
A getReason() 0 3 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\HistoryAnalyser\UnifiedDiffParser;
14
15
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\HistoryAnalyserException;
16
use DaveLiddament\StaticAnalysisResultsBaseliner\Domain\HistoryAnalyser\UnifiedDiffParser\internal\DiffParseException;
17
use Throwable;
18
19
class ParseException extends HistoryAnalyserException
20
{
21
    /**
22
     * @var string
23
     */
24
    public const UNEXPECTED_END_OF_FILE = 'Unexpected end of file';
25
26
    /**
27
     * @var string
28
     */
29
    private $location;
30
31
    /**
32
     * @var string
33
     */
34
    private $reason;
35
36
    /**
37
     * Create from DiffParseException.
38
     *
39
     * @return ParseException
40
     */
41
    public static function fromDiffParseException(string $location, DiffParseException $e): self
42
    {
43
        return new self($location, $e->getReason(), $e->getDetails(), $e);
44
    }
45
46
    /**
47
     * ParseException constructor.
48
     */
49
    public function __construct(string $location, string $reason, string $details, ?Throwable $previous)
50
    {
51
        $message = "Error parsing diff. Line {$location}. Reason: {$reason}. Details: [$details]";
52
        parent::__construct($message, 0, $previous);
53
        $this->location = $location;
54
        $this->reason = $reason;
55
    }
56
57
    public function getLocation(): string
58
    {
59
        return $this->location;
60
    }
61
62
    public function getReason(): string
63
    {
64
        return $this->reason;
65
    }
66
}
67