Completed
Pull Request — master (#6)
by Woody
02:37
created

CommandException::getHttpStatus()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Equip\Command;
4
5
use RuntimeException;
6
7
class CommandException extends RuntimeException
8
{
9
    const NO_OPTIONS = 2000;
10
    const MISSING_OPTION = 2000;
11
12
    /**
13
     * @param Command $command
14
     *
15
     * @return static
16
     *
17
     * @since 1.3.0
18
     */
19 1
    public static function needsOptions(Command $command)
20
    {
21 1
        return new static(sprintf(
22 1
            'No options have been set for the `%s` command',
23 1
            get_class($command)
24 1
        ), static::NO_OPTIONS);
25
    }
26
27
    /*
28
     * @param array $names
29
     *
30
     * @return static
31
     *
32
     * @since 1.2.0
33
     */
34 2
    public static function missingOptions(array $names)
35
    {
36 2
        return new static(
37 2
            sprintf('Required options not defined: `%s`', implode('`, `', $names)),
38
            static::MISSING_OPTION
39 2
        );
40
    }
41
42
    /**
43
     * @param string $name
44
     *
45
     * @return static
46
     *
47
     * @deprecated 1.2.0
48
     */
49 1
    public static function missingOption($name)
50
    {
51 1
        return new static(
52 1
            sprintf('Required option `%s` is not defined', $name),
53
            static::MISSING_OPTION
54 1
        );
55
    }
56
57
    /**
58
     * Get the HTTP status for the exception.
59
     *
60
     * @return integer
61
     */
62 2
    public function getHttpStatus()
63
    {
64 2
        if ($this->getCode() === static::MISSING_OPTION) {
65 1
            return 400;
66
        }
67
68 1
        return 500;
69
    }
70
}
71