ScannerNotFoundException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[email protected]>.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\AnthillBundle\Exception\Vacancy;
17
18
use RuntimeException;
19
use Symfony\Component\HttpFoundation\Response;
20
use Throwable;
21
use Veslo\AnthillBundle\Exception\AnthillBundleExceptionInterface;
22
23
/**
24
 * Will be thrown if roadmap is not found
25
 */
26
class ScannerNotFoundException extends RuntimeException implements AnthillBundleExceptionInterface
27
{
28
    /**
29
     * Default error message
30
     *
31
     * @const string
32
     */
33
    public const MESSAGE = 'Scanner is not found.';
34
35
    /**
36
     * Error message for context of invalid location dto structure
37
     *
38
     * @const string
39
     */
40
    public const MESSAGE_INVALID_LOCATION = 'Invalid vacancy location structure. Roadmap is not specified.';
41
42
    /**
43
     * Error message with name of unsupported roadmap
44
     *
45
     * @const string
46
     */
47
    public const MESSAGE_WITH_ROADMAP_NAME = "Scanner for roadmap '{roadmapName}' is not found. Declare it in roadmaps.yml";
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function __construct(
53
        string $message = self::MESSAGE,
54
        int $code = Response::HTTP_INTERNAL_SERVER_ERROR,
55
        Throwable $previous = null
56
    ) {
57
        parent::__construct($message, $code, $previous);
58
    }
59
60
    /**
61
     * Returns exception in context of unspecified roadmap in location dto
62
     *
63
     * @return ScannerNotFoundException
64
     */
65
    public static function invalidLocation(): ScannerNotFoundException
66
    {
67
        return new static(self::MESSAGE_INVALID_LOCATION);
68
    }
69
70
    /**
71
     * Returns exception in context of unsupported roadmap
72
     *
73
     * @param string $roadmapName Unsupported roadmap name
74
     *
75
     * @return ScannerNotFoundException
76
     */
77
    public static function withRoadmapName(string $roadmapName): ScannerNotFoundException
78
    {
79
        $message = str_replace('{roadmapName}', $roadmapName, self::MESSAGE_WITH_ROADMAP_NAME);
80
81
        return new static($message);
82
    }
83
}
84