diff --git a/composer.json b/composer.json index c9d3dfd..6b3c649 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ "minimum-stability": "stable", "require": { - "php": "^8.1", - "jrosset/betterphptoken": "^1.0", - "jrosset/collections": "^3.0", + "php": "^8.1", + "jrosset/betterphptoken": "^1.0", "jrosset/extendedmonolog": "^2.0", - "psr/log": "^2.0", - "symfony/console": "^6.1" + "psr/log": "^2.0", + "symfony/console": "^6.1", + "voku/arrayy": "^7.9" }, "autoload": { "psr-4": { diff --git a/src/CliProgram/AutoDiscovery/AutoDiscoverySpotsList.php b/src/CliProgram/AutoDiscovery/AutoDiscoverySpotsList.php new file mode 100644 index 0000000..2556d25 --- /dev/null +++ b/src/CliProgram/AutoDiscovery/AutoDiscoverySpotsList.php @@ -0,0 +1,19 @@ + + */ +class AutoDiscoverySpotsList extends AbstractCollection { + /** + * @inheritDoc + */ + public function getType (): string { + return IAutoDiscoverySpot::class; + } +} \ No newline at end of file diff --git a/src/CliProgram/AutoDiscovery/TAutoDiscoveryApplication.php b/src/CliProgram/AutoDiscovery/TAutoDiscoveryApplication.php index 815a455..608088d 100644 --- a/src/CliProgram/AutoDiscovery/TAutoDiscoveryApplication.php +++ b/src/CliProgram/AutoDiscovery/TAutoDiscoveryApplication.php @@ -2,26 +2,23 @@ namespace jrosset\CliProgram\AutoDiscovery; -use jrosset\Collections\Collection; -use jrosset\Collections\ICollection; - /** * An application with command auto discovery */ trait TAutoDiscoveryApplication { /** - * @var ICollection The list of discovery spots + * @var AutoDiscoverySpotsList The list of discovery spots */ - private ICollection $autoDiscoverySpots; + private AutoDiscoverySpotsList $autoDiscoverySpots; /** * The list of discovery spots * - * @return ICollection The list of discovery spots + * @return AutoDiscoverySpotsList The list of discovery spots */ - public function getAutoDiscoverySpots (): ICollection { + public function getAutoDiscoverySpots (): AutoDiscoverySpotsList { if (!isset($this->autoDiscoverySpots)) { - $this->autoDiscoverySpots = new Collection(); + $this->autoDiscoverySpots = new AutoDiscoverySpotsList(); } return $this->autoDiscoverySpots; } @@ -31,7 +28,7 @@ trait TAutoDiscoveryApplication { * * @return $this */ - public function addAutoDiscoveredCommands (): self { + public function addAutoDiscoveredCommands (): static { foreach ($this->getAutoDiscoverySpots() as $autoDiscoverySpot) { foreach ($autoDiscoverySpot->getCommands() as $command) { $this->add($command); diff --git a/src/CliProgram/AutoPrefix/AutoPrefixManagersList.php b/src/CliProgram/AutoPrefix/AutoPrefixManagersList.php new file mode 100644 index 0000000..ebd1822 --- /dev/null +++ b/src/CliProgram/AutoPrefix/AutoPrefixManagersList.php @@ -0,0 +1,19 @@ + + */ +class AutoPrefixManagersList extends AbstractCollection { + /** + * @inheritDoc + */ + public function getType (): string { + return IAutoPrefixManager::class; + } +} \ No newline at end of file diff --git a/src/CliProgram/AutoPrefix/TAutoPrefixManagement.php b/src/CliProgram/AutoPrefix/TAutoPrefixManagement.php index 3c1dc87..c749c43 100644 --- a/src/CliProgram/AutoPrefix/TAutoPrefixManagement.php +++ b/src/CliProgram/AutoPrefix/TAutoPrefixManagement.php @@ -2,8 +2,6 @@ namespace jrosset\CliProgram\AutoPrefix; -use jrosset\Collections\Collection; -use jrosset\Collections\ICollection; use Symfony\Component\Console\Command\Command; /** @@ -11,18 +9,18 @@ use Symfony\Component\Console\Command\Command; */ trait TAutoPrefixManagement { /** - * @var ICollection The lists of manager for commands auto prefix + * @var AutoPrefixManagersList The lists of manager for commands auto prefix */ - private ICollection $autoPrefixManagers; + private AutoPrefixManagersList $autoPrefixManagers; /** * The lists of manager for commands auto prefix * - * @return ICollection The lists of manager for commands auto prefix + * @return AutoPrefixManagersList The lists of manager for commands auto prefix */ - public function getAutoPrefixManagers (): ICollection { + public function getAutoPrefixManagers (): AutoPrefixManagersList { if (!isset($this->autoPrefixManagers)) { - $this->autoPrefixManagers = new Collection(); + $this->autoPrefixManagers = new AutoPrefixManagersList(); } return $this->autoPrefixManagers; } diff --git a/src/CliProgram/Validation/TCommandWithValidation.php b/src/CliProgram/Validation/TCommandWithValidation.php index ba92d99..00893df 100644 --- a/src/CliProgram/Validation/TCommandWithValidation.php +++ b/src/CliProgram/Validation/TCommandWithValidation.php @@ -67,7 +67,7 @@ trait TCommandWithValidation { //region Get the argument value $argumentValue = $input->getArgument($argumentName); //endregion - //region Check the argument value is not + //region Check the argument value is not Null if ($argumentValue === null) { // If the value is strictly Null (the default value), don't check it → skip continue; diff --git a/src/CliProgram/Validation/Validators/DirectoryValidator.php b/src/CliProgram/Validation/Validators/DirectoryValidator.php index c7ace8c..8c1e631 100644 --- a/src/CliProgram/Validation/Validators/DirectoryValidator.php +++ b/src/CliProgram/Validation/Validators/DirectoryValidator.php @@ -3,8 +3,6 @@ namespace jrosset\CliProgram\Validation\Validators; use InvalidArgumentException; -use jrosset\Collections\Collection; -use jrosset\Collections\ICollection; use Stringable; /** @@ -14,16 +12,16 @@ class DirectoryValidator implements IValidator { use TInternalValueValidator; /** - * @var ICollection The options + * @var FilesystemValidationOptionsList The options */ - private ICollection $options; + private FilesystemValidationOptionsList $options; /** * Initialization * - * @param ICollection|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options + * @param FilesystemValidationOptionsList|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options */ - public function __construct (ICollection|array|FilesystemValidationOption|null $options = null) { + public function __construct (FilesystemValidationOptionsList|array|FilesystemValidationOption|null $options = null) { $this->setOptions($options); } @@ -65,13 +63,13 @@ class DirectoryValidator implements IValidator { return false; } - if ($this->getOptions()->contains(FilesystemValidationOption::IsReadable) && !is_readable($value)) { + if ($this->getOptions()->contains(FilesystemValidationOption::IsReadable->name) && !is_readable($value)) { return false; } - if ($this->getOptions()->contains(FilesystemValidationOption::IsWritable) && !is_writable($value)) { + if ($this->getOptions()->contains(FilesystemValidationOption::IsWritable->name) && !is_writable($value)) { return false; } - if ($this->getOptions()->contains(FilesystemValidationOption::MustExists) && !file_exists($value)) { + if ($this->getOptions()->contains(FilesystemValidationOption::MustExists->name) && !file_exists($value)) { return false; } @@ -82,24 +80,24 @@ class DirectoryValidator implements IValidator { /** * The options * - * @return ICollection The options + * @return FilesystemValidationOptionsList The options */ - public function getOptions (): ICollection { + public function getOptions (): FilesystemValidationOptionsList { return $this->options; } /** * Replace the options * - * @param ICollection|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options + * @param FilesystemValidationOptionsList|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options * * @return $this */ - public function setOptions (ICollection|array|FilesystemValidationOption|null $options = null): static { + public function setOptions (FilesystemValidationOptionsList|array|FilesystemValidationOption|null $options = null): static { $this->options = match (true) { - $options instanceof ICollection => $options, - $options instanceof FilesystemValidationOption => new Collection([$options]), - is_array($options) => new Collection($options), - $options === null => new Collection(), + $options instanceof FilesystemValidationOptionsList => $options, + $options instanceof FilesystemValidationOption => new FilesystemValidationOptionsList([$options]), + is_array($options) => new FilesystemValidationOptionsList($options), + $options === null => new FilesystemValidationOptionsList(), }; return $this; } diff --git a/src/CliProgram/Validation/Validators/EnumValidator.php b/src/CliProgram/Validation/Validators/EnumValidator.php index 83b39f1..d13cebb 100644 --- a/src/CliProgram/Validation/Validators/EnumValidator.php +++ b/src/CliProgram/Validation/Validators/EnumValidator.php @@ -2,7 +2,7 @@ namespace jrosset\CliProgram\Validation\Validators; -use jrosset\Collections\Collection; +use Arrayy\Type\StringCollection; use ReflectionEnum; use ReflectionException; use UnitEnum; @@ -30,7 +30,7 @@ class EnumValidator extends BasedValidator { public function __construct (string $enumClass) { $this->enum = new ReflectionEnum($enumClass); - $enumCases = new Collection(); + $enumCases = new StringCollection(); foreach ($this->enum->getCases() as $enumCase) { $enumCases->add($enumCase->getName()); } @@ -40,8 +40,6 @@ class EnumValidator extends BasedValidator { /** * @inheritDoc - * - * @throws ReflectionException */ public function getValidDefault (mixed $default): string|bool|int|float|array|null { if ($default instanceof UnitEnum) { diff --git a/src/CliProgram/Validation/Validators/FileValidator.php b/src/CliProgram/Validation/Validators/FileValidator.php index 24ccaa4..05fd0aa 100644 --- a/src/CliProgram/Validation/Validators/FileValidator.php +++ b/src/CliProgram/Validation/Validators/FileValidator.php @@ -3,7 +3,6 @@ namespace jrosset\CliProgram\Validation\Validators; use InvalidArgumentException; -use jrosset\Collections\ICollection; /** * An argument/option value validator for a file path @@ -17,10 +16,10 @@ class FileValidator extends DirectoryValidator { /** * Initialization * - * @param string|null $extensionsPattern The allowed extensions (regex pattern) - * @param ICollection|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options + * @param string|null $extensionsPattern The allowed extensions (regex pattern) + * @param FilesystemValidationOptionsList|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options */ - public function __construct (?string $extensionsPattern = null, ICollection|FilesystemValidationOption|array|null $options = null) { + public function __construct (?string $extensionsPattern = null, FilesystemValidationOptionsList|FilesystemValidationOption|array|null $options = null) { parent::__construct($options); $this->setExtensionsPattern($extensionsPattern); } diff --git a/src/CliProgram/Validation/Validators/FilesystemValidationOptionsList.php b/src/CliProgram/Validation/Validators/FilesystemValidationOptionsList.php new file mode 100644 index 0000000..a02a673 --- /dev/null +++ b/src/CliProgram/Validation/Validators/FilesystemValidationOptionsList.php @@ -0,0 +1,19 @@ + + */ +class FilesystemValidationOptionsList extends AbstractCollection { + /** + * @inheritDoc + */ + public function getType (): string { + return FilesystemValidationOption::class; + } +} \ No newline at end of file diff --git a/src/CliProgram/Validation/Validators/ListValidator.php b/src/CliProgram/Validation/Validators/ListValidator.php index 8254897..e6f33db 100644 --- a/src/CliProgram/Validation/Validators/ListValidator.php +++ b/src/CliProgram/Validation/Validators/ListValidator.php @@ -2,8 +2,7 @@ namespace jrosset\CliProgram\Validation\Validators; -use jrosset\Collections\Collection; -use jrosset\Collections\ICollection; +use Arrayy\Type\StringCollection; /** * An argument/option value validator based on a list of value @@ -17,17 +16,17 @@ class ListValidator implements IValidator { use TInternalValueValidator; /** - * @var ICollection The list of allowed values + * @var StringCollection The list of allowed values */ - private ICollection $allowedValues; + private StringCollection $allowedValues; /** * Create a validator * - * @param ICollection|null $allowedValues The list of allowed values + * @param StringCollection|null $allowedValues The list of allowed values */ - public function __construct (?ICollection $allowedValues = null) { - $this->setAllowedValues($allowedValues ?? new Collection()); + public function __construct (?StringCollection $allowedValues = null) { + $this->setAllowedValues($allowedValues ?? new StringCollection()); } /** @@ -44,19 +43,19 @@ class ListValidator implements IValidator { /** * The list of allowed values * - * @return ICollection The list of allowed values + * @return StringCollection The list of allowed values */ - public function getAllowedValues (): ICollection { + public function getAllowedValues (): StringCollection { return $this->allowedValues; } /** * Set the list of allowed values * - * @param ICollection $allowedValues The list of allowed values + * @param StringCollection $allowedValues The list of allowed values * * @return $this */ - public function setAllowedValues (ICollection $allowedValues): self { + public function setAllowedValues (StringCollection $allowedValues): self { $this->allowedValues = $allowedValues; return $this; }