CannotAddArgumentException::existsAlready()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the webmozart/console package.
5
 *
6
 * (c) Bernhard Schussek <[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
12
namespace Webmozart\Console\Api\Args;
13
14
use Exception;
15
use RuntimeException;
16
17
/**
18
 * Thrown when an argument cannot be added.
19
 *
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class CannotAddArgumentException extends RuntimeException
25
{
26
    /**
27
     * Code: The argument exists already.
28
     */
29
    const EXISTS_ALREADY = 1;
30
31
    /**
32
     * Code: An argument was added after a multi-valued argument.
33
     */
34
    const MULTI_VALUED_EXISTS = 2;
35
36
    /**
37
     * Code: A required argument was added after an optional argument.
38
     */
39
    const REQUIRED_AFTER_OPTIONAL = 3;
40
41
    /**
42
     * Creates an exception with code {@link EXISTS_ALREADY}.
43
     *
44
     * @param string    $name  The argument name.
45
     * @param Exception $cause The exception that caused this exception.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $cause not be null|Exception?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
46
     *
47
     * @return static The created exception.
48
     */
49 2
    public static function existsAlready($name, Exception $cause = null)
50
    {
51 2
        return new static(sprintf(
52 2
            'An argument named "%s" exists already.',
53
            $name
54 2
        ), self::EXISTS_ALREADY, $cause);
55
    }
56
57
    /**
58
     * Creates an exception with code {@link ADD_AFTER_MULTI_VALUED}.
59
     *
60
     * @param Exception $cause The exception that caused this exception.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $cause not be null|Exception?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
61
     *
62
     * @return static The created exception.
63
     */
64 4
    public static function cannotAddAfterMultiValued(Exception $cause = null)
65
    {
66 4
        return new static(
67 4
            'Cannot add an argument after a multi-valued argument.',
68 4
            self::MULTI_VALUED_EXISTS,
69
            $cause
70
        );
71
    }
72
73
    /**
74
     * Creates an exception with code {@link ADD_REQUIRED_AFTER_OPTIONAL}.
75
     *
76
     * @param Exception $cause The exception that caused this exception.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $cause not be null|Exception?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
77
     *
78
     * @return static The created exception.
79
     */
80 2
    public static function cannotAddRequiredAfterOptional(Exception $cause = null)
81
    {
82 2
        return new static(
83 2
            'Cannot add a required argument after an optional one.',
84 2
            self::REQUIRED_AFTER_OPTIONAL,
85
            $cause
86
        );
87
    }
88
}
89