-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support non-empty-list and object collections (#53)
* Rename NonEmptyStringProvider to NonEmptyValueProvider Add support for non-empty-list type - combines ListProvider with NonEmptyValueProvider to generate non-empty lists (arrays with int keys) Add support for Collection objects using Object<A, B> syntax * Adjust type-resolver min version to support NonEmptyList type * Add support for hardcoded float/int/string values as typehint
- Loading branch information
Showing
26 changed files
with
329 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/Constraint/ValueProvider/Pseudo/DirectValueProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Constraint\ValueProvider\Pseudo; | ||
|
||
use DigitalRevolution\AccessorPairConstraint\Constraint\ValueProvider\ValueProvider; | ||
use phpDocumentor\Reflection\PseudoTypes\FloatValue; | ||
use phpDocumentor\Reflection\PseudoTypes\IntegerValue; | ||
use phpDocumentor\Reflection\PseudoTypes\StringValue; | ||
|
||
class DirectValueProvider implements ValueProvider | ||
{ | ||
/** @var FloatValue|IntegerValue|StringValue */ | ||
private $valueType; | ||
|
||
/** | ||
* @param FloatValue|IntegerValue|StringValue $valueType | ||
*/ | ||
public function __construct($valueType) | ||
{ | ||
$this->valueType = $valueType; | ||
} | ||
|
||
/** | ||
* @return float[]|int[]|string[] | ||
*/ | ||
public function getValues(): array | ||
{ | ||
return [$this->valueType->getValue()]; | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
src/Constraint/ValueProvider/Pseudo/NonEmptyStringProvider.php
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
src/Constraint/ValueProvider/Pseudo/NonEmptyValueProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Constraint\ValueProvider\Pseudo; | ||
|
||
use DigitalRevolution\AccessorPairConstraint\Constraint\ValueProvider\ValueProvider; | ||
use Exception; | ||
|
||
class NonEmptyValueProvider implements ValueProvider | ||
{ | ||
private ValueProvider $valueProvider; | ||
|
||
public function __construct(ValueProvider $valueProvider) | ||
{ | ||
$this->valueProvider = $valueProvider; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
* @throws Exception | ||
*/ | ||
public function getValues(): array | ||
{ | ||
return array_filter($this->valueProvider->getValues()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/Integration/data/success/Regular/Types/CompoundTypes/CollectionProperty.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Tests\Integration\data\success\Regular\Types\CompoundTypes; | ||
|
||
use ArrayIterator; | ||
use stdClass; | ||
|
||
class CollectionProperty | ||
{ | ||
/** @var ArrayIterator<stdClass> */ | ||
private $property = false; | ||
|
||
/** | ||
* @return ArrayIterator<stdClass> | ||
*/ | ||
public function getProperty(): ArrayIterator | ||
{ | ||
return $this->property; | ||
} | ||
|
||
/** | ||
* @param ArrayIterator<stdClass> $property | ||
*/ | ||
public function setProperty(ArrayIterator $property): self | ||
{ | ||
$this->property = $property; | ||
|
||
return $this; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Integration/data/success/Regular/Types/PseudoTypes/FloatValueProperty.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Tests\Integration\data\success\Regular\Types\PseudoTypes; | ||
|
||
class FloatValueProperty | ||
{ | ||
/** @var 1.0|2.0|3.0 */ | ||
private float $property; | ||
|
||
/** | ||
* @return 1.0|2.0|3.0 | ||
*/ | ||
public function getProperty(): float | ||
{ | ||
return $this->property; | ||
} | ||
|
||
/** | ||
* @param 1.0|2.0|3.0 $property | ||
*/ | ||
public function setProperty(float $property): self | ||
{ | ||
$this->property = $property; | ||
|
||
return $this; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Integration/data/success/Regular/Types/PseudoTypes/IntegerValueProperty.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Tests\Integration\data\success\Regular\Types\PseudoTypes; | ||
|
||
class IntegerValueProperty | ||
{ | ||
/** @var 1|2|3 */ | ||
private int $property; | ||
|
||
/** | ||
* @return 1|2|3 | ||
*/ | ||
public function getProperty(): int | ||
{ | ||
return $this->property; | ||
} | ||
|
||
/** | ||
* @param 1|2|3 $property | ||
*/ | ||
public function setProperty(int $property): self | ||
{ | ||
$this->property = $property; | ||
|
||
return $this; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/Integration/data/success/Regular/Types/PseudoTypes/NonEmptyListProperty.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Tests\Integration\data\success\Regular\Types\PseudoTypes; | ||
|
||
class NonEmptyListProperty | ||
{ | ||
/** @var non-empty-list */ | ||
private array $property; | ||
|
||
/** | ||
* @return non-empty-list | ||
*/ | ||
public function getProperty(): array | ||
{ | ||
return $this->property; | ||
} | ||
|
||
/** | ||
* @param non-empty-list $property | ||
*/ | ||
public function setProperty(array $property): self | ||
{ | ||
$this->property = $property; | ||
|
||
return $this; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
tests/Integration/data/success/Regular/Types/PseudoTypes/StringValueProperty.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalRevolution\AccessorPairConstraint\Tests\Integration\data\success\Regular\Types\PseudoTypes; | ||
|
||
class StringValueProperty | ||
{ | ||
/** @var 'foo'|'bar'*/ | ||
private string $property; | ||
|
||
/** | ||
* @return 'foo'|'bar' | ||
*/ | ||
public function getProperty(): string | ||
{ | ||
return $this->property; | ||
} | ||
|
||
/** | ||
* @param 'foo'|'bar' $property | ||
*/ | ||
public function setProperty(string $property): self | ||
{ | ||
$this->property = $property; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Unit/Constraint/ValueProvider/Pseudo/CallableStringProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/Unit/Constraint/ValueProvider/Pseudo/ClassStringProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.