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

CommandException::needsOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
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