Replace jrosset/collections with voku/arrayy

master
Julien Rosset 2 years ago
parent 98319dafb4
commit 6258c680df

@ -15,12 +15,12 @@
"minimum-stability": "stable", "minimum-stability": "stable",
"require": { "require": {
"php": "^8.1", "php": "^8.1",
"jrosset/betterphptoken": "^1.0", "jrosset/betterphptoken": "^1.0",
"jrosset/collections": "^3.0",
"jrosset/extendedmonolog": "^2.0", "jrosset/extendedmonolog": "^2.0",
"psr/log": "^2.0", "psr/log": "^2.0",
"symfony/console": "^6.1" "symfony/console": "^6.1",
"voku/arrayy": "^7.9"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

@ -0,0 +1,19 @@
<?php
namespace jrosset\CliProgram\AutoDiscovery;
use Arrayy\Collection\AbstractCollection;
/**
* A list of command auto discovery spots
*
* @extends AbstractCollection<AutoDiscoverySpotsList>
*/
class AutoDiscoverySpotsList extends AbstractCollection {
/**
* @inheritDoc
*/
public function getType (): string {
return IAutoDiscoverySpot::class;
}
}

@ -2,26 +2,23 @@
namespace jrosset\CliProgram\AutoDiscovery; namespace jrosset\CliProgram\AutoDiscovery;
use jrosset\Collections\Collection;
use jrosset\Collections\ICollection;
/** /**
* An application with command auto discovery * An application with command auto discovery
*/ */
trait TAutoDiscoveryApplication { trait TAutoDiscoveryApplication {
/** /**
* @var ICollection<IAutoDiscoverySpot> The list of discovery spots * @var AutoDiscoverySpotsList The list of discovery spots
*/ */
private ICollection $autoDiscoverySpots; private AutoDiscoverySpotsList $autoDiscoverySpots;
/** /**
* The list of discovery spots * The list of discovery spots
* *
* @return ICollection<IAutoDiscoverySpot> The list of discovery spots * @return AutoDiscoverySpotsList The list of discovery spots
*/ */
public function getAutoDiscoverySpots (): ICollection { public function getAutoDiscoverySpots (): AutoDiscoverySpotsList {
if (!isset($this->autoDiscoverySpots)) { if (!isset($this->autoDiscoverySpots)) {
$this->autoDiscoverySpots = new Collection(); $this->autoDiscoverySpots = new AutoDiscoverySpotsList();
} }
return $this->autoDiscoverySpots; return $this->autoDiscoverySpots;
} }
@ -31,7 +28,7 @@ trait TAutoDiscoveryApplication {
* *
* @return $this * @return $this
*/ */
public function addAutoDiscoveredCommands (): self { public function addAutoDiscoveredCommands (): static {
foreach ($this->getAutoDiscoverySpots() as $autoDiscoverySpot) { foreach ($this->getAutoDiscoverySpots() as $autoDiscoverySpot) {
foreach ($autoDiscoverySpot->getCommands() as $command) { foreach ($autoDiscoverySpot->getCommands() as $command) {
$this->add($command); $this->add($command);

@ -0,0 +1,19 @@
<?php
namespace jrosset\CliProgram\AutoPrefix;
use Arrayy\Collection\AbstractCollection;
/**
* A list of managers of commands auto prefix
*
* @extends AbstractCollection<IAutoPrefixManager>
*/
class AutoPrefixManagersList extends AbstractCollection {
/**
* @inheritDoc
*/
public function getType (): string {
return IAutoPrefixManager::class;
}
}

@ -2,8 +2,6 @@
namespace jrosset\CliProgram\AutoPrefix; namespace jrosset\CliProgram\AutoPrefix;
use jrosset\Collections\Collection;
use jrosset\Collections\ICollection;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
/** /**
@ -11,18 +9,18 @@ use Symfony\Component\Console\Command\Command;
*/ */
trait TAutoPrefixManagement { trait TAutoPrefixManagement {
/** /**
* @var ICollection<IAutoPrefixManager> 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 * The lists of manager for commands auto prefix
* *
* @return ICollection<IAutoPrefixManager> 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)) { if (!isset($this->autoPrefixManagers)) {
$this->autoPrefixManagers = new Collection(); $this->autoPrefixManagers = new AutoPrefixManagersList();
} }
return $this->autoPrefixManagers; return $this->autoPrefixManagers;
} }

@ -67,7 +67,7 @@ trait TCommandWithValidation {
//region Get the argument value //region Get the argument value
$argumentValue = $input->getArgument($argumentName); $argumentValue = $input->getArgument($argumentName);
//endregion //endregion
//region Check the argument value is not //region Check the argument value is not Null
if ($argumentValue === null) { if ($argumentValue === null) {
// If the value is strictly Null (the default value), don't check it → skip // If the value is strictly Null (the default value), don't check it → skip
continue; continue;

@ -3,8 +3,6 @@
namespace jrosset\CliProgram\Validation\Validators; namespace jrosset\CliProgram\Validation\Validators;
use InvalidArgumentException; use InvalidArgumentException;
use jrosset\Collections\Collection;
use jrosset\Collections\ICollection;
use Stringable; use Stringable;
/** /**
@ -14,16 +12,16 @@ class DirectoryValidator implements IValidator {
use TInternalValueValidator; use TInternalValueValidator;
/** /**
* @var ICollection<FilesystemValidationOption> The options * @var FilesystemValidationOptionsList The options
*/ */
private ICollection $options; private FilesystemValidationOptionsList $options;
/** /**
* Initialization * Initialization
* *
* @param ICollection<FilesystemValidationOption>|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); $this->setOptions($options);
} }
@ -65,13 +63,13 @@ class DirectoryValidator implements IValidator {
return false; return false;
} }
if ($this->getOptions()->contains(FilesystemValidationOption::IsReadable) && !is_readable($value)) { if ($this->getOptions()->contains(FilesystemValidationOption::IsReadable->name) && !is_readable($value)) {
return false; return false;
} }
if ($this->getOptions()->contains(FilesystemValidationOption::IsWritable) && !is_writable($value)) { if ($this->getOptions()->contains(FilesystemValidationOption::IsWritable->name) && !is_writable($value)) {
return false; return false;
} }
if ($this->getOptions()->contains(FilesystemValidationOption::MustExists) && !file_exists($value)) { if ($this->getOptions()->contains(FilesystemValidationOption::MustExists->name) && !file_exists($value)) {
return false; return false;
} }
@ -82,24 +80,24 @@ class DirectoryValidator implements IValidator {
/** /**
* The options * The options
* *
* @return ICollection<FilesystemValidationOption> The options * @return FilesystemValidationOptionsList The options
*/ */
public function getOptions (): ICollection { public function getOptions (): FilesystemValidationOptionsList {
return $this->options; return $this->options;
} }
/** /**
* Replace the options * Replace the options
* *
* @param ICollection<FilesystemValidationOption>|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options * @param FilesystemValidationOptionsList|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options
* *
* @return $this * @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) { $this->options = match (true) {
$options instanceof ICollection => $options, $options instanceof FilesystemValidationOptionsList => $options,
$options instanceof FilesystemValidationOption => new Collection([$options]), $options instanceof FilesystemValidationOption => new FilesystemValidationOptionsList([$options]),
is_array($options) => new Collection($options), is_array($options) => new FilesystemValidationOptionsList($options),
$options === null => new Collection(), $options === null => new FilesystemValidationOptionsList(),
}; };
return $this; return $this;
} }

@ -2,7 +2,7 @@
namespace jrosset\CliProgram\Validation\Validators; namespace jrosset\CliProgram\Validation\Validators;
use jrosset\Collections\Collection; use Arrayy\Type\StringCollection;
use ReflectionEnum; use ReflectionEnum;
use ReflectionException; use ReflectionException;
use UnitEnum; use UnitEnum;
@ -30,7 +30,7 @@ class EnumValidator extends BasedValidator {
public function __construct (string $enumClass) { public function __construct (string $enumClass) {
$this->enum = new ReflectionEnum($enumClass); $this->enum = new ReflectionEnum($enumClass);
$enumCases = new Collection(); $enumCases = new StringCollection();
foreach ($this->enum->getCases() as $enumCase) { foreach ($this->enum->getCases() as $enumCase) {
$enumCases->add($enumCase->getName()); $enumCases->add($enumCase->getName());
} }
@ -40,8 +40,6 @@ class EnumValidator extends BasedValidator {
/** /**
* @inheritDoc * @inheritDoc
*
* @throws ReflectionException
*/ */
public function getValidDefault (mixed $default): string|bool|int|float|array|null { public function getValidDefault (mixed $default): string|bool|int|float|array|null {
if ($default instanceof UnitEnum) { if ($default instanceof UnitEnum) {

@ -3,7 +3,6 @@
namespace jrosset\CliProgram\Validation\Validators; namespace jrosset\CliProgram\Validation\Validators;
use InvalidArgumentException; use InvalidArgumentException;
use jrosset\Collections\ICollection;
/** /**
* An argument/option value validator for a file path * An argument/option value validator for a file path
@ -17,10 +16,10 @@ class FileValidator extends DirectoryValidator {
/** /**
* Initialization * Initialization
* *
* @param string|null $extensionsPattern The allowed extensions (regex pattern) * @param string|null $extensionsPattern The allowed extensions (regex pattern)
* @param ICollection<FilesystemValidationOption>|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options * @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); parent::__construct($options);
$this->setExtensionsPattern($extensionsPattern); $this->setExtensionsPattern($extensionsPattern);
} }

@ -0,0 +1,19 @@
<?php
namespace jrosset\CliProgram\Validation\Validators;
use Arrayy\Collection\AbstractCollection;
/**
* A list of options of a filesystem based validator
*
* @extends AbstractCollection<FilesystemValidationOption>
*/
class FilesystemValidationOptionsList extends AbstractCollection {
/**
* @inheritDoc
*/
public function getType (): string {
return FilesystemValidationOption::class;
}
}

@ -2,8 +2,7 @@
namespace jrosset\CliProgram\Validation\Validators; namespace jrosset\CliProgram\Validation\Validators;
use jrosset\Collections\Collection; use Arrayy\Type\StringCollection;
use jrosset\Collections\ICollection;
/** /**
* An argument/option value validator based on a list of value * An argument/option value validator based on a list of value
@ -17,17 +16,17 @@ class ListValidator implements IValidator {
use TInternalValueValidator; 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 * 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) { public function __construct (?StringCollection $allowedValues = null) {
$this->setAllowedValues($allowedValues ?? new Collection()); $this->setAllowedValues($allowedValues ?? new StringCollection());
} }
/** /**
@ -44,19 +43,19 @@ class ListValidator implements IValidator {
/** /**
* The list of allowed values * 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; return $this->allowedValues;
} }
/** /**
* Set the list of allowed values * Set the list of allowed values
* *
* @param ICollection $allowedValues The list of allowed values * @param StringCollection $allowedValues The list of allowed values
* *
* @return $this * @return $this
*/ */
public function setAllowedValues (ICollection $allowedValues): self { public function setAllowedValues (StringCollection $allowedValues): self {
$this->allowedValues = $allowedValues; $this->allowedValues = $allowedValues;
return $this; return $this;
} }

Loading…
Cancel
Save