diff --git a/src/Argument/Argument.php b/src/Argument/Argument.php index 0a2ed7ea..400192ff 100644 --- a/src/Argument/Argument.php +++ b/src/Argument/Argument.php @@ -2,7 +2,7 @@ namespace League\CLImate\Argument; -use League\CLImate\Exceptions\InvalidArgumentCastTypeException; +use League\CLImate\Exceptions\UnexpectedValueException; use function is_array; class Argument @@ -281,13 +281,15 @@ public function castTo() * * Valid data types are "string", "int", "float", and "bool". * - * @throws \Exception if $castTo is not a valid data type. * @param string $castTo + * + * @return void + * @throws UnexpectedValueException if $castTo is not a valid data type. */ protected function setCastTo($castTo) { if (!in_array($castTo, ['string', 'int', 'float', 'bool'])) { - throw new InvalidArgumentCastTypeException( + throw new UnexpectedValueException( "An argument may only be cast to the data type " . "'string', 'int', 'float', or 'bool'." ); diff --git a/src/Argument/Manager.php b/src/Argument/Manager.php index 5a62b307..93e379b0 100644 --- a/src/Argument/Manager.php +++ b/src/Argument/Manager.php @@ -3,7 +3,7 @@ namespace League\CLImate\Argument; use League\CLImate\CLImate; -use League\CLImate\Exceptions\InvalidTypeException; +use League\CLImate\Exceptions\InvalidArgumentException; class Manager { @@ -52,9 +52,11 @@ public function __construct() /** * Add an argument. * - * @throws \Exception if $argument isn't an array or Argument object. * @param Argument|string|array $argument * @param $options + * + * @return void + * @throws InvalidArgumentException if $argument isn't an array or Argument object. */ public function add($argument, array $options = []) { @@ -67,8 +69,8 @@ public function add($argument, array $options = []) $argument = Argument::createFromArray($argument, $options); } - if (!($argument instanceof Argument)) { - throw new InvalidTypeException('Please provide an argument name or object.'); + if (!$argument instanceof Argument) { + throw new InvalidArgumentException('Please provide an argument name or object.'); } $this->arguments[$argument->name()] = $argument; @@ -228,7 +230,6 @@ public function usage(CLImate $climate, array $argv = null) /** * Parse command line arguments into CLImate arguments. * - * @throws \Exception if required arguments aren't defined. * @param array $argv */ public function parse(array $argv = null) diff --git a/src/Argument/Parser.php b/src/Argument/Parser.php index f42ad89e..b91e4d6e 100644 --- a/src/Argument/Parser.php +++ b/src/Argument/Parser.php @@ -2,7 +2,7 @@ namespace League\CLImate\Argument; -use League\CLImate\Exceptions\MissingRequiredArgumentException; +use League\CLImate\Exceptions\InvalidArgumentException; class Parser { @@ -44,8 +44,10 @@ public function setFilter($filter, $arguments) /** * Parse command line arguments into CLImate arguments. * - * @throws \Exception if required arguments aren't defined. * @param array $argv + * + * @return void + * @throws InvalidArgumentException if required arguments aren't defined. */ public function parse(array $argv = null) { @@ -64,7 +66,7 @@ public function parse(array $argv = null) $missingArguments = $this->filter->missing(); if (count($missingArguments) > 0) { - throw new MissingRequiredArgumentException( + throw new InvalidArgumentException( 'The following arguments are required: ' . $this->summary->short($missingArguments) . '.' ); diff --git a/src/Exceptions/InvalidArgumentCastTypeException.php b/src/Exceptions/InvalidArgumentCastTypeException.php deleted file mode 100644 index 62aef788..00000000 --- a/src/Exceptions/InvalidArgumentCastTypeException.php +++ /dev/null @@ -1,7 +0,0 @@ -characters = $characters; diff --git a/src/TerminalObject/Helper/Art.php b/src/TerminalObject/Helper/Art.php index 14cb1519..ade8105e 100644 --- a/src/TerminalObject/Helper/Art.php +++ b/src/TerminalObject/Helper/Art.php @@ -2,7 +2,7 @@ namespace League\CLImate\TerminalObject\Helper; -use League\CLImate\Exceptions\SPLUnexpectedValueException; +use League\CLImate\Exceptions\UnexpectedValueException; trait Art { @@ -95,7 +95,7 @@ protected function artFile($art) } if (count($files) === 0) { - throw new SPLUnexpectedValueException("Unable to find an art file with the name '{$art}'"); + throw new UnexpectedValueException("Unable to find an art file with the name '{$art}'"); } return reset($files); diff --git a/src/TerminalObject/Router/ExtensionCollection.php b/src/TerminalObject/Router/ExtensionCollection.php index 1312eea5..fea4f2a3 100644 --- a/src/TerminalObject/Router/ExtensionCollection.php +++ b/src/TerminalObject/Router/ExtensionCollection.php @@ -2,8 +2,8 @@ namespace League\CLImate\TerminalObject\Router; -use League\CLImate\Exceptions\InvalidTypeException; -use League\CLImate\Exceptions\MissingClassException; +use League\CLImate\Exceptions\InvalidArgumentException; +use League\CLImate\Exceptions\UnexpectedValueException; use League\CLImate\Util\Helper; class ExtensionCollection @@ -39,7 +39,7 @@ public function collection() * @param string $original_key * @param string|object|array $original_class * - * @return type + * @return void */ protected function createCollection($original_key, $original_class) { @@ -82,19 +82,19 @@ protected function validateExtension($class) /** * @param string|object $class * - * @throws \Exception if extension class does not exist + * @throws UnexpectedValueException if extension class does not exist */ protected function validateClassExists($class) { if (is_string($class) && !class_exists($class)) { - throw new MissingClassException('Class does not exist: ' . $class); + throw new UnexpectedValueException('Class does not exist: ' . $class); } } /** * @param string|object $class * - * @throws \Exception if extension class does not implement either Dynamic or Basic interface + * @throws InvalidArgumentException if extension class does not implement either Dynamic or Basic interface */ protected function validateClassImplementation($class) { @@ -104,7 +104,7 @@ protected function validateClassImplementation($class) || is_a($class, $this->dynamic_interface, $str_class)); if (!$valid_implementation) { - throw new InvalidTypeException('Class must implement either ' + throw new InvalidArgumentException('Class must implement either ' . $this->basic_interface . ' or ' . $this->dynamic_interface); } } diff --git a/src/Util/Output.php b/src/Util/Output.php index a158c190..51d6dcca 100644 --- a/src/Util/Output.php +++ b/src/Util/Output.php @@ -2,7 +2,8 @@ namespace League\CLImate\Util; -use League\CLImate\Exceptions\InvalidTypeException; +use League\CLImate\Exceptions\InvalidArgumentException; +use League\CLImate\Exceptions\UnexpectedValueException; use League\CLImate\Util\Writer\WriterInterface; class Output @@ -133,15 +134,15 @@ public function persist($persist = true) /** * Get a specific writer * - * @throws \Exception if writer key doesn't exist * @param string $writer * * @return WriterInterface|array + * @throws UnexpectedValueException if writer key doesn't exist */ public function get($writer) { if (!array_key_exists($writer, $this->writers)) { - throw new InvalidTypeException('Unknown writer [' . $writer . ']'); + throw new UnexpectedValueException('Unknown writer [' . $writer . ']'); } if (count($this->writers[$writer]) == 1) { @@ -243,19 +244,19 @@ protected function resolveStringWriter($writer) /** * @param mixed $writer - * @throws \Exception For non-valid writer + * @throws InvalidArgumentException For non-valid writer */ protected function handleUnknownWriter($writer) { // If we've gotten this far and don't know what it is, // let's at least try and give a helpful error message if (is_object($writer)) { - throw new InvalidTypeException('Class [' . get_class($writer) . '] must implement ' + throw new InvalidArgumentException('Class [' . get_class($writer) . '] must implement ' . 'League\CLImate\Util\Writer\WriterInterface.'); } // No idea, just tell them we can't resolve it - throw new InvalidTypeException('Unable to resolve writer [' . $writer . ']'); + throw new InvalidArgumentException('Unable to resolve writer [' . $writer . ']'); } /** diff --git a/src/Util/Reader/Stdin.php b/src/Util/Reader/Stdin.php index 9c92a9a4..28f5996f 100644 --- a/src/Util/Reader/Stdin.php +++ b/src/Util/Reader/Stdin.php @@ -57,7 +57,7 @@ public function hidden() * Lazily re-opens STDIN after hitting an EOF * * @return resource - * @throws \Exception + * @throws RuntimeException */ protected function getStdIn() { @@ -77,7 +77,8 @@ protected function getStdIn() /** * Attempt to set the stdin property * - * @throws \Exception + * @return void + * @throws RuntimeException */ protected function setStdIn() {