Replace jrosset/collections with voku/arrayy

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

@ -17,10 +17,10 @@
"require": {
"php": "^8.1",
"jrosset/betterphptoken": "^1.0",
"jrosset/collections": "^3.0",
"jrosset/extendedmonolog": "^2.0",
"psr/log": "^2.0",
"symfony/console": "^6.1"
"symfony/console": "^6.1",
"voku/arrayy": "^7.9"
},
"autoload": {
"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;
use jrosset\Collections\Collection;
use jrosset\Collections\ICollection;
/**
* An application with command auto discovery
*/
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
*
* @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)) {
$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);

@ -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;
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<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
*
* @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)) {
$this->autoPrefixManagers = new Collection();
$this->autoPrefixManagers = new AutoPrefixManagersList();
}
return $this->autoPrefixManagers;
}

@ -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;

@ -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<FilesystemValidationOption> The options
* @var FilesystemValidationOptionsList The options
*/
private ICollection $options;
private FilesystemValidationOptionsList $options;
/**
* 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);
}
@ -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<FilesystemValidationOption> The options
* @return FilesystemValidationOptionsList The options
*/
public function getOptions (): ICollection {
public function getOptions (): FilesystemValidationOptionsList {
return $this->options;
}
/**
* Replace the options
*
* @param ICollection<FilesystemValidationOption>|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;
}

@ -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) {

@ -3,7 +3,6 @@
namespace jrosset\CliProgram\Validation\Validators;
use InvalidArgumentException;
use jrosset\Collections\ICollection;
/**
* An argument/option value validator for a file path
@ -18,9 +17,9 @@ class FileValidator extends DirectoryValidator {
* Initialization
*
* @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);
$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;
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;
}

Loading…
Cancel
Save