Passed
Push — master ( 2d5d29...0740c8 )
by ReliQ
04:50 queued 13s
created

ParsingFailed   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forFile() 0 7 1
A getFailedFile() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ReliqArts\Docweaver\Exception;
6
7
use ReliqArts\Docweaver\Contract\Exception as ExceptionContract;
8
9
final class ParsingFailed extends Exception
10
{
11
    private const CODE = 1004;
12
13
    /**
14
     * @var null|string
15
     */
16
    private ?string $failedFile;
17
18
    /**
19
     * @param ExceptionContract $previous
20
     */
21
    public static function forFile(string $file, ExceptionContract $previous = null): ExceptionContract
22
    {
23
        $message = sprintf('Failed to parse file `%s`.', $file);
24
        $self = new self($message, self::CODE, $previous);
25
        $self->failedFile = $file;
26
27
        return $self;
28
    }
29
30
    /**
31
     * Get the file which parsing failed for.
32
     */
33
    public function getFailedFile(): ?string
34
    {
35
        return $this->failedFile;
36
    }
37
}
38