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

CommandException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 5
c 3
b 0
f 1
lcom 1
cbo 0
dl 0
loc 64
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A needsOptions() 0 7 1
A missingOptions() 0 7 1
A missingOption() 0 7 1
A getHttpStatus() 0 8 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