Skip to content

Commit

Permalink
Merge pull request #21 from kynx/psalm-type-ignore
Browse files Browse the repository at this point in the history
Added PsalmTypeIgnore attribute, marking forms that cannot be processed
  • Loading branch information
kynx authored Feb 24, 2024
2 parents 207ad58 + c794332 commit b1fbce9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/Attribute/PsalmTypeIgnore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Kynx\Laminas\FormShape\Attribute;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
final class PsalmTypeIgnore
{
}
14 changes: 10 additions & 4 deletions src/Locator/RecursiveReflectionIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kynx\Laminas\FormShape\Locator;

use Kynx\Laminas\FormShape\Attribute\PsalmTypeIgnore;
use RecursiveIterator;
use ReflectionClass;
use SplFileInfo;
Expand Down Expand Up @@ -31,15 +32,20 @@ public function __construct(

public function current(): ?ReflectionClass
{
$current = $this->iterator->current();
$current = $this->iterator->current();
$reflection = null;
if ($current instanceof SplFileInfo) {
return $this->reflectionProvider->getReflection($current->getPathname());
$reflection = $this->reflectionProvider->getReflection($current->getPathname());
}
if (is_string($current)) {
return $this->reflectionProvider->getReflection($current);
$reflection = $this->reflectionProvider->getReflection($current);
}

return null;
if ($reflection !== null && $reflection->getAttributes(PsalmTypeIgnore::class) !== []) {
return null;
}

return $reflection;
}

public function next(): void
Expand Down
13 changes: 13 additions & 0 deletions test/Locator/Asset/IgnoredForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace KynxTest\Laminas\FormShape\Locator\Asset;

use Kynx\Laminas\FormShape\Attribute\PsalmTypeIgnore;
use Laminas\Form\Form;

#[PsalmTypeIgnore]
final class IgnoredForm extends Form
{
}

0 comments on commit b1fbce9

Please sign in to comment.