Replace jrosset/collections with voku/arrayy

2.x
Julien Rosset 2 years ago
parent 56e05cdc2e
commit 38c1a583dc

@ -16,11 +16,12 @@
"minimum-stability": "stable", "minimum-stability": "stable",
"require": { "require": {
"php": "^7.4 || ^8.0.0", "php": "^7.4 || ^8.0.0",
"symfony/console": "^5.4",
"jrosset/betterphptoken": "^1.0", "jrosset/betterphptoken": "^1.0",
"jrosset/collections": "^2.3", "jrosset/collections": "^2.3",
"jrosset/extendedmonolog": "^1.1", "jrosset/extendedmonolog": "^1.1",
"psr/log": "^1.1" "psr/log": "^1.1",
"symfony/console": "^5.4",
"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;
} }

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

@ -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,14 +12,14 @@ class DirectoryValidator implements IValidator {
use TInternalValueValidator; use TInternalValueValidator;
/** /**
* @var ICollection<int> The options * @var FilesystemValidationOptionsList The options
*/ */
private ICollection $options; private FilesystemValidationOptionsList $options;
/** /**
* Initialization * Initialization
* *
* @param ICollection<int>|int[]|int|null $options The options * @param FilesystemValidationOptionsList|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options
*/ */
public function __construct ($options = null) { public function __construct ($options = null) {
$this->setOptions($options); $this->setOptions($options);
@ -82,30 +80,30 @@ 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<int>|int[]|int|null $options The options * @param FilesystemValidationOptionsList|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options
* *
* @return $this * @return $this
*/ */
public function setOptions ($options = null): self { public function setOptions ($options = null): self {
if ($options instanceof ICollection) { if ($options instanceof FilesystemValidationOptionsList) {
$this->options = $options; $this->options = $options;
} }
elseif (is_int($options)) { elseif (is_int($options)) {
$this->options = new Collection([$options]); $this->options = new FilesystemValidationOptionsList([$options]);
} }
elseif (is_array($options)) { elseif (is_array($options)) {
$this->options = new Collection($options); $this->options = new FilesystemValidationOptionsList($options);
} }
elseif ($options === null) { elseif ($options === null) {
$this->options = new Collection(); $this->options = new FilesystemValidationOptionsList();
} }
else { else {
throw new InvalidArgumentException(); throw new InvalidArgumentException();

@ -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
@ -18,7 +17,7 @@ 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<int>|int[]|int|null $options The options * @param FilesystemValidationOptionsList|FilesystemValidationOption[]|FilesystemValidationOption|null $options The options
*/ */
public function __construct (?string $extensionsPattern = null, $options = null) { public function __construct (?string $extensionsPattern = null, $options = null) {
parent::__construct($options); parent::__construct($options);

@ -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 'int';
}
}

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