Skip to content

Commit

Permalink
D'oh! Fix @extends tag
Browse files Browse the repository at this point in the history
  • Loading branch information
matt committed Feb 23, 2024
1 parent 549684d commit db77704
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 23 deletions.
12 changes: 7 additions & 5 deletions src/Writer/FileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use Kynx\Laminas\FormShape\Psalm\UseCollector;
use Kynx\Laminas\FormShape\TypeNamerInterface;
use Kynx\Laminas\FormShape\Writer\Tag\Method;
use Kynx\Laminas\FormShape\Writer\Tag\PsalmImplements;
use Kynx\Laminas\FormShape\Writer\Tag\PsalmImportType;
use Kynx\Laminas\FormShape\Writer\Tag\PsalmTemplateExtends;
use Kynx\Laminas\FormShape\Writer\Tag\PsalmExtends;

Check failure on line 15 in src/Writer/FileWriter.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Use statements should be sorted alphabetically. The first wrong one is Kynx\Laminas\FormShape\Writer\Tag\PsalmExtends.
use Kynx\Laminas\FormShape\Writer\Tag\PsalmType;
use Kynx\Laminas\FormShape\Writer\Tag\ReturnType;
use Laminas\Form\Form;

Check failure on line 18 in src/Writer/FileWriter.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Type Laminas\Form\Form is not used in this file.
use Laminas\Form\FormInterface;
use Nette\PhpGenerator\PhpFile;
use Nette\PhpGenerator\PhpNamespace;
Expand Down Expand Up @@ -97,10 +99,10 @@ public function write(
}

if ($reflection->implementsInterface(FormInterface::class)) {
$classDocBlock = $classDocBlock->withTag(new PsalmTemplateExtends(
$reflection->getParentClass()->getShortName(),
$typeName
));
$tag = $reflection->getParentClass() === false

Check failure on line 102 in src/Writer/FileWriter.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
? new PsalmImplements('FormInterface', $typeName)
: new PsalmExtends($reflection->getParentClass()->getShortName(), $typeName);
$classDocBlock = $classDocBlock->withTag($tag);
}

$class->setComment($classDocBlock->getContents());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* @psalm-internal Kynx\Laminas\FormShape
* @psalm-internal KynxTest\Laminas\FormShape
*/
final readonly class PsalmTemplateExtends implements TagInterface
final readonly class PsalmExtends implements TagInterface
{
public function __construct(private string $parent, private string $type)
{
}

public function __toString(): string
{
return sprintf('@psalm-template-extends %s<%s>', $this->parent, $this->type);
return sprintf('@extends %s<%s>', $this->parent, $this->type);
}

public function isBefore(TagInterface $tag): bool
Expand All @@ -32,6 +32,6 @@ public function isBefore(TagInterface $tag): bool

public function matches(TagInterface $tag): bool
{
return str_starts_with(trim((string) $tag), '@psalm-template-extends ');
return str_starts_with(trim((string) $tag), '@extends ');
}
}
30 changes: 30 additions & 0 deletions src/Writer/Tag/PsalmImplements.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Kynx\Laminas\FormShape\Writer\Tag;

use function sprintf;
use function trim;

final readonly class PsalmImplements implements TagInterface
{
public function __construct(private string $interface, private string $type)
{
}

public function __toString(): string
{
return sprintf('@implements %s<%s>', $this->interface, $this->type);
}

public function isBefore(TagInterface $tag): bool
{
return false;
}

public function matches(TagInterface $tag): bool
{
return str_starts_with(trim((string) $tag), '@implements ');

Check failure on line 28 in src/Writer/Tag/PsalmImplements.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Function str_starts_with() should not be referenced via a fallback global name, but via a use statement.
}
}

Check failure on line 30 in src/Writer/Tag/PsalmImplements.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Expected 1 newline at end of file; 0 found
14 changes: 7 additions & 7 deletions test/Writer/FileWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ final class NoClassDocBlock extends Form
* @psalm-type TNoClassDocBlockArray = array{
* foo: int,
* }
* @psalm-template-extends Form<TNoClassDocBlockArray>
* @extends Form<TNoClassDocBlockArray>
*/
final class NoClassDocBlock extends Form
{
Expand Down Expand Up @@ -200,7 +200,7 @@ final class NoClassDocBlockWithAttribute extends Form
* @psalm-type TNoClassDocBlockWithAttributeArray = array{
* foo: int,
* }
* @psalm-template-extends Form<TNoClassDocBlockWithAttributeArray>
* @extends Form<TNoClassDocBlockWithAttributeArray>
*/
#[TestAttribute]
final class NoClassDocBlockWithAttribute extends Form
Expand Down Expand Up @@ -241,7 +241,7 @@ final class ExistingClassDocBlock extends Form
* @psalm-type TExistingClassDocBlockArray = array{
* foo: int,
* }
* @psalm-template-extends Form<TExistingClassDocBlockArray>
* @extends Form<TExistingClassDocBlockArray>
*/
final class ExistingClassDocBlock extends Form
{
Expand Down Expand Up @@ -282,7 +282,7 @@ final class ExistingClassDocBlockWithAttribute extends Form
* @psalm-type TExistingClassDocBlockWithAttributeArray = array{
* foo: int,
* }
* @psalm-template-extends Form<TExistingClassDocBlockWithAttributeArray>
* @extends Form<TExistingClassDocBlockWithAttributeArray>
*/
#[TestAttribute]
final class ExistingClassDocBlockWithAttribute extends Form
Expand Down Expand Up @@ -315,7 +315,7 @@ final class GetDataNotOverridden extends Form
* @psalm-type TGetDataNotOverriddenArray = array{
* foo: int,
* }
* @psalm-template-extends Form<TGetDataNotOverriddenArray>
* @extends Form<TGetDataNotOverriddenArray>
*/
final class GetDataNotOverridden extends Form
{
Expand Down Expand Up @@ -355,7 +355,7 @@ public function getData(int \$flag = FormInterface::VALUES_NORMALIZED)
* @psalm-type TGetDataReturnTypeArray = array{
* foo: int,
* }
* @psalm-template-extends Form<TGetDataReturnTypeArray>
* @extends Form<TGetDataReturnTypeArray>
*/
final class GetDataReturnType extends Form
{
Expand Down Expand Up @@ -395,7 +395,7 @@ final class GetDataMethod extends Form
* @psalm-type TGetDataMethodArray = array{
* foo: int,
* }
* @psalm-template-extends Form<TGetDataMethodArray>
* @extends Form<TGetDataMethodArray>
*/
final class GetDataMethod extends Form
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
namespace KynxTest\Laminas\FormShape\Writer\Tag;

use Kynx\Laminas\FormShape\Writer\Tag\GenericTag;
use Kynx\Laminas\FormShape\Writer\Tag\PsalmTemplateExtends;
use Kynx\Laminas\FormShape\Writer\Tag\PsalmExtends;
use Kynx\Laminas\FormShape\Writer\Tag\TagInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[CoversClass(PsalmTemplateExtends::class)]
final class PsalmTemplateExtendsTest extends TestCase
#[CoversClass(PsalmExtends::class)]
final class PsalmExtendsTest extends TestCase
{
public function testToStringReturnsTag(): void
{
$expected = '@psalm-template-extends Form<TFormArray>';
$tag = new PsalmTemplateExtends('Form', 'TFormArray');
$expected = '@extends Form<TFormArray>';
$tag = new PsalmExtends('Form', 'TFormArray');
$actual = (string) $tag;
self::assertSame($expected, $actual);
}

#[DataProvider('isBeforeProvider')]
public function testIsBefore(TagInterface $match, bool $expected): void
{
$tag = new PsalmTemplateExtends('Form', 'TFormArray');
$tag = new PsalmExtends('Form', 'TFormArray');
$actual = $tag->isBefore($match);
self::assertSame($expected, $actual);
}
Expand All @@ -41,15 +41,15 @@ public static function isBeforeProvider(): array
#[DataProvider('matchProvider')]
public function testMatches(TagInterface $match, bool $expected): void
{
$tag = new PsalmTemplateExtends('Form', 'TFormArray');
$tag = new PsalmExtends('Form', 'TFormArray');
$actual = $tag->matches($match);
self::assertSame($expected, $actual);
}

public static function matchProvider(): array

Check failure on line 49 in test/Writer/Tag/PsalmExtendsTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

PossiblyUnusedMethod

test/Writer/Tag/PsalmExtendsTest.php:49:28: PossiblyUnusedMethod: Cannot find any calls to method KynxTest\Laminas\FormShape\Writer\Tag\PsalmExtendsTest::matchProvider (see https://psalm.dev/087)
{
return [
'psalm-template-extends' => [new GenericTag('@psalm-template-extends Foo<Bar>'), true],
'extends' => [new GenericTag('@extends Foo<Bar>'), true],

Check failure on line 52 in test/Writer/Tag/PsalmExtendsTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Expected 4 spaces before double arrow; 1 found
'psalm-type' => [new GenericTag('@psalm-type TFoo = array<int>'), false],

Check failure on line 53 in test/Writer/Tag/PsalmExtendsTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Expected 1 space before double arrow; 13 found
];
}
Expand Down
56 changes: 56 additions & 0 deletions test/Writer/Tag/PsalmImplementsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace KynxTest\Laminas\FormShape\Writer\Tag;

use Kynx\Laminas\FormShape\Writer\Tag\GenericTag;
use Kynx\Laminas\FormShape\Writer\Tag\PsalmImplements;
use Kynx\Laminas\FormShape\Writer\Tag\TagInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[CoversClass(PsalmImplements::class)]
final class PsalmImplementsTest extends TestCase
{
public function testToStringReturnsTag(): void
{
$expected = '@implements FormInterface<TFormArray>';
$tag = new PsalmImplements('FormInterface', 'TFormArray');
$actual = (string) $tag;
self::assertSame($expected, $actual);
}

#[DataProvider('isBeforeProvider')]
public function testIsBefore(TagInterface $match, bool $expected): void
{
$tag = new PsalmImplements('FormInterface', 'TFormArray');
$actual = $tag->isBefore($match);
self::assertSame($expected, $actual);
}

public static function isBeforeProvider(): array

Check failure on line 33 in test/Writer/Tag/PsalmImplementsTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

PossiblyUnusedMethod

test/Writer/Tag/PsalmImplementsTest.php:33:28: PossiblyUnusedMethod: Cannot find any calls to method KynxTest\Laminas\FormShape\Writer\Tag\PsalmImplementsTest::isBeforeProvider (see https://psalm.dev/087)
{
return [
'internal' => [new GenericTag('@internal'), false],
'psalm-type' => [new GenericTag('@psalm-type TFoo = array<int>'), false],
];
}

#[DataProvider('matchProvider')]
public function testMatches(TagInterface $match, bool $expected): void
{
$tag = new PsalmImplements('FormInterface', 'TFormArray');
$actual = $tag->matches($match);
self::assertSame($expected, $actual);
}

public static function matchProvider(): array

Check failure on line 49 in test/Writer/Tag/PsalmImplementsTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (Psalm [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

PossiblyUnusedMethod

test/Writer/Tag/PsalmImplementsTest.php:49:28: PossiblyUnusedMethod: Cannot find any calls to method KynxTest\Laminas\FormShape\Writer\Tag\PsalmImplementsTest::matchProvider (see https://psalm.dev/087)
{
return [
'extends' => [new GenericTag('@implements Foo<Bar>'), true],

Check failure on line 52 in test/Writer/Tag/PsalmImplementsTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Expected 4 spaces before double arrow; 1 found
'psalm-type' => [new GenericTag('@psalm-type TFoo = array<int>'), false],

Check failure on line 53 in test/Writer/Tag/PsalmImplementsTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.2, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Expected 1 space before double arrow; 13 found
];
}
}

0 comments on commit db77704

Please sign in to comment.