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

InvalidDirectory::forDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
class InvalidDirectory extends Exception
10
{
11
    protected const MESSAGE_TEMPLATE = 'Invalid directory: `%s`.';
12
13
    private const CODE = 4002;
14
15
    /**
16
     * @var null|string
17
     */
18
    protected ?string $directory;
19
20
    /**
21
     * @param string            $directory Directory
22
     * @param ExceptionContract $previous  Previous Exception if nested exception
23
     */
24
    public static function forDirectory(string $directory, ExceptionContract $previous = null): ExceptionContract
25
    {
26
        $message = sprintf(static::MESSAGE_TEMPLATE, $directory);
27
        $self = new static($message, self::CODE, $previous);
28
        $self->directory = $directory;
29
30
        return $self;
31
    }
32
33
    final public function getDirectory(): ?string
34
    {
35
        return $this->directory;
36
    }
37
}
38