1 | <?php |
||
26 | class CannotResolveCommandException extends RuntimeException |
||
27 | { |
||
28 | /** |
||
29 | * Code: The passed command name was not found. |
||
30 | */ |
||
31 | const NAME_NOT_FOUND = 1; |
||
32 | |||
33 | /** |
||
34 | * Code: No command was passed and no default was configured. |
||
35 | */ |
||
36 | const NO_DEFAULT_COMMAND = 2; |
||
37 | |||
38 | /** |
||
39 | * Creates an exception for the code {@link NAME_NOT_FOUND}. |
||
40 | * |
||
41 | * Suggested alternatives are searched in the passed commands. |
||
42 | * |
||
43 | * @param string $commandName The command name that was not found. |
||
44 | * @param CommandCollection $commands A list of available commands that |
||
45 | * is searched for similar names. |
||
46 | * @param Exception $cause The exception that caused this |
||
|
|||
47 | * exception. |
||
48 | * |
||
49 | * @return static The created exception. |
||
50 | */ |
||
51 | 1 | public static function nameNotFound($commandName, CommandCollection $commands, Exception $cause = null) |
|
52 | { |
||
53 | 1 | $message = sprintf('The command "%s" is not defined.', $commandName); |
|
54 | |||
55 | 1 | $suggestedNames = SimilarCommandName::find($commandName, $commands); |
|
56 | |||
57 | 1 | if (count($suggestedNames) > 0) { |
|
58 | 1 | if (1 === count($suggestedNames)) { |
|
59 | $message .= "\n\nDid you mean this?\n "; |
||
60 | } else { |
||
61 | 1 | $message .= "\n\nDid you mean one of these?\n "; |
|
62 | } |
||
63 | 1 | $message .= implode("\n ", $suggestedNames); |
|
64 | } |
||
65 | |||
66 | 1 | return new static($message, self::NAME_NOT_FOUND, $cause); |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Creates an exception for the code {@link NO_DEFAULT_COMMAND}. |
||
71 | * |
||
72 | * @param Exception $cause The exception that caused this exception. |
||
73 | * |
||
74 | * @return static The created exception. |
||
75 | */ |
||
76 | public static function noDefaultCommand(Exception $cause = null) |
||
80 | } |
||
81 |
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.