-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from sitegeist/task/useDeepObjectForAllNonTriv…
…ialParameters TASK: Use `deepObject` for all non trivial parameters and remove `[]` from collection names
- Loading branch information
Showing
16 changed files
with
472 additions
and
26 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\SchemeOnYou\Domain\Schema; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Proxy(false)] | ||
final class IsSingleValueDataTransferObject | ||
{ | ||
/** | ||
* @var array<class-string,bool> | ||
*/ | ||
private static array $evaluationRuntimeCache = []; | ||
|
||
/** | ||
* @param class-string $className | ||
*/ | ||
public static function isSatisfiedByClassName(string $className): bool | ||
{ | ||
if (!array_key_exists($className, self::$evaluationRuntimeCache)) { | ||
self::$evaluationRuntimeCache[$className] = self::evaluateReflectionClass(new \ReflectionClass($className)); | ||
} | ||
|
||
return self::$evaluationRuntimeCache[$className]; | ||
} | ||
|
||
/** | ||
* @param \ReflectionClass<object> $reflectionClass | ||
*/ | ||
public static function isSatisfiedByReflectionClass(\ReflectionClass $reflectionClass): bool | ||
{ | ||
if (!array_key_exists($reflectionClass->name, self::$evaluationRuntimeCache)) { | ||
self::$evaluationRuntimeCache[$reflectionClass->name] = self::evaluateReflectionClass($reflectionClass); | ||
} | ||
|
||
return self::$evaluationRuntimeCache[$reflectionClass->name]; | ||
} | ||
|
||
/** | ||
* @param \ReflectionClass<object> $reflectionClass | ||
*/ | ||
private static function evaluateReflectionClass(\ReflectionClass $reflectionClass): bool | ||
{ | ||
if ($reflectionClass->isEnum()) { | ||
/** @phpstan-ignore-next-line */ | ||
return (new \ReflectionEnum($reflectionClass->getName()))->isBacked(); | ||
} | ||
if (IsDataTransferObject::isSatisfiedByReflectionClass($reflectionClass)) { | ||
$parameters = $reflectionClass->getConstructor()?->getParameters() ?: []; | ||
if (count($parameters) === 1 && $parameters[0]->name === 'value') { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Tests/Fixtures/InvalidObjects/CollectionThatIsNotReadonly.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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\SchemeOnYou\Tests\Fixtures\InvalidObjects; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Sitegeist\SchemeOnYou\Tests\Fixtures; | ||
|
||
#[Flow\Proxy(false)] | ||
final class CollectionThatIsNotReadonly | ||
{ | ||
/** | ||
* @var Fixtures\Identifier[] | ||
*/ | ||
public array $items; | ||
public function __construct( | ||
Fixtures\Identifier ...$items | ||
) { | ||
$this->items = $items; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Tests/Fixtures/InvalidObjects/CollectionWithMoreThanOneProperty.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 Sitegeist\SchemeOnYou\Tests\Fixtures\InvalidObjects; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Sitegeist\SchemeOnYou\Tests\Fixtures; | ||
|
||
#[Flow\Proxy(false)] | ||
final readonly class CollectionWithMoreThanOneProperty | ||
{ | ||
/** | ||
* @var Fixtures\Identifier[] | ||
*/ | ||
public array $items; | ||
|
||
public int $count; | ||
|
||
public function __construct( | ||
Fixtures\Identifier ...$items | ||
) { | ||
$this->items = $items; | ||
$this->count = count($items); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Tests/Fixtures/InvalidObjects/CollectionWithTooManyConstructorArguments.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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\SchemeOnYou\Tests\Fixtures\InvalidObjects; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Sitegeist\SchemeOnYou\Tests\Fixtures; | ||
|
||
#[Flow\Proxy(false)] | ||
final readonly class CollectionWithTooManyConstructorArguments | ||
{ | ||
/** | ||
* @var Fixtures\Identifier[] | ||
*/ | ||
public array $items; | ||
public function __construct( | ||
string $other, | ||
Fixtures\Identifier ...$items | ||
) { | ||
if ($other === 'whatever') { | ||
$this->items = [...$items]; | ||
} else { | ||
$this->items = $items; | ||
} | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\SchemeOnYou\Tests\Fixtures\InvalidObjects; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Proxy(false)] | ||
enum NonBackedEnum | ||
{ | ||
case Foo; | ||
case Bar; | ||
} |
27 changes: 27 additions & 0 deletions
27
Tests/Fixtures/InvalidObjects/ObjectThatHasNonPromotedConstructorArguments.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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\SchemeOnYou\Tests\Fixtures\InvalidObjects; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Sitegeist\SchemeOnYou\Domain\Metadata as OpenApi; | ||
|
||
#[Flow\Proxy(false)] | ||
final readonly class ObjectThatHasNonPromotedConstructorArguments | ||
{ | ||
public string $text; | ||
public int $num; | ||
public bool $switch; | ||
|
||
public function __construct( | ||
string $text, | ||
int $num, | ||
bool $switch | ||
) { | ||
|
||
$this->text = $text; | ||
$this->num = $num; | ||
$this->switch = $switch; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Tests/Fixtures/InvalidObjects/ObjectThatHasNotSupportedProperties.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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\SchemeOnYou\Tests\Fixtures\InvalidObjects; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Proxy(false)] | ||
final readonly class ObjectThatHasNotSupportedProperties | ||
{ | ||
public function __construct( | ||
public \Psr\Http\Message\RequestInterface $text | ||
) { | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\SchemeOnYou\Tests\Fixtures\InvalidObjects; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Proxy(false)] | ||
final class ObjectThatIsNotReadonly | ||
{ | ||
public function __construct( | ||
public string $text, | ||
public int $num, | ||
public bool $switch | ||
) { | ||
} | ||
} |
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.