Skip to content

Commit f34ae55

Browse files
committed
100% Psalm type coverage and 99% Infection MSI
1 parent 2043646 commit f34ae55

8 files changed

Lines changed: 58 additions & 31 deletions

File tree

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
continue-on-error: '${{ matrix.failure }}'
3636
- name: 'Psalm'
3737
run: 'php vendor/bin/psalm --no-cache --shepherd'
38-
continue-on-error: '${{ matrix.failure }}'
38+
if: always()
3939
- name: 'Infection'
4040
run: 'php vendor/bin/infection -j2 --min-msi=95'
41-
continue-on-error: '${{ matrix.failure }}'
41+
if: always()

psalm.xml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
errorLevel="1"
44
resolveFromConfigFile="true"
55
findUnusedPsalmSuppress="false"
6+
findUnusedBaselineEntry="false"
7+
findUnusedCode="false"
68
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
79
xmlns="https://getpsalm.org/schema/config"
810
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
@@ -11,31 +13,9 @@
1113
<directory name="src" />
1214
<directory name="tests/Psalm" />
1315
<ignoreFiles>
16+
<file name="src/Doctrine/PlatenumDoctrineType.php" />
1417
<directory name="vendor" />
1518
</ignoreFiles>
1619
</projectFiles>
1720

18-
<issueHandlers>
19-
<UnusedClosureParam errorLevel="error">
20-
<errorLevel type="suppress">
21-
<file name="src/Doctrine/PlatenumDoctrineType.php" />
22-
</errorLevel>
23-
</UnusedClosureParam>
24-
<UnusedPsalmSuppress errorLevel="error">
25-
<errorLevel type="suppress">
26-
<file name="src/Enum/AttributeEnumTrait.php" />
27-
</errorLevel>
28-
</UnusedPsalmSuppress>
29-
<DeprecatedMethod errorLevel="error">
30-
<errorLevel type="suppress">
31-
<file name="src/Doctrine/PlatenumDoctrineType.php" />
32-
</errorLevel>
33-
</DeprecatedMethod>
34-
<DocblockTypeContradiction errorLevel="error">
35-
<errorLevel type="suppress">
36-
<file name="src/Enum/EnumTrait.php" /> <!-- PHP 7.2 only? -->
37-
</errorLevel>
38-
</DocblockTypeContradiction>
39-
</issueHandlers>
40-
4121
</psalm>

src/Doctrine/PlatenumDoctrineType.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\DBAL\Platforms\AbstractPlatform;
66
use Doctrine\DBAL\Types\Type;
7+
use Thunder\Platenum\Enum\AbstractConstantsEnum;
78
use Thunder\Platenum\Enum\EnumTrait;
89

910
/** @psalm-suppress PropertyNotSetInConstructor, MissingConstructor */
@@ -13,7 +14,7 @@ final class PlatenumDoctrineType extends Type
1314
private $platenumClass;
1415
/** @var string */
1516
private $platenumAlias;
16-
/** @var callable */
17+
/** @var callable(mixed):mixed */
1718
private $platenumCallback;
1819
/** @psalm-var callable(array,AbstractPlatform):string */
1920
private $platenumSql;
@@ -46,7 +47,9 @@ public static function registerString(string $alias, string $class): void
4647
return (string)$value;
4748
};
4849
$sql = function(array $declaration, AbstractPlatform $platform): string {
49-
return $platform->getVarcharTypeDeclarationSQL([]);
50+
return method_exists($platform, 'getStringTypeDeclarationSQL')
51+
? $platform->getStringTypeDeclarationSQL([])
52+
: $platform->getVarcharTypeDeclarationSQL([]);
5053
};
5154

5255
self::registerCallback($alias, $class, $toString, $sql);
@@ -55,7 +58,7 @@ public static function registerString(string $alias, string $class): void
5558
/**
5659
* @param string $alias
5760
* @psalm-param class-string $class
58-
* @param callable $callback
61+
* @param callable(int|string):mixed $callback
5962
* @psalm-param callable(array<mixed>,AbstractPlatform):string $sql
6063
*/
6164
private static function registerCallback(string $alias, string $class, callable $callback, callable $sql): void
@@ -120,8 +123,8 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
120123
throw new \LogicException(sprintf($message, self::class, gettype($value)));
121124
}
122125

123-
/** @psalm-suppress MixedMethodCall */
124-
return ($this->platenumCallback)($value->getValue());
126+
/** @var AbstractConstantsEnum $value */
127+
return call_user_func($this->platenumCallback, $value->getValue());
125128
}
126129

127130
public function convertToPHPValue($value, AbstractPlatform $platform)

tests/DoctrineTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
1111
use Thunder\Platenum\Doctrine\PlatenumDoctrineType;
1212
use Thunder\Platenum\Tests\Fake\DoctrineEntity;
13+
use Thunder\Platenum\Tests\Fake\DoctrineExtendsEnum;
1314
use Thunder\Platenum\Tests\Fake\DoctrineIntEnum;
1415
use Thunder\Platenum\Tests\Fake\DoctrineStringEnum;
1516
use Thunder\Platenum\Tests\Fake\NoTraitEnum;
@@ -101,4 +102,10 @@ public function testNoTrait(): void
101102
$this->expectExceptionMessage('PlatenumDoctrineType allows only Platenum enumerations, `'.NoTraitEnum::class.'` given.');
102103
PlatenumDoctrineType::registerString('noTraitEnum', NoTraitEnum::class);
103104
}
105+
106+
public function testInheritance(): void
107+
{
108+
PlatenumDoctrineType::registerString('doctrineExtendsEnum', DoctrineExtendsEnum::class);
109+
$this->assertTrue(true);
110+
}
104111
}

tests/EnumTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ public function testGetInstances(): void
6565
$first = $enum::fromMember('FIRST');
6666
$otherFirst = $enum::fromEnum($first);
6767

68-
$this->assertSame([$enum::FIRST(), $enum::SECOND()], $enum::getInstances());
68+
$this->assertSame([$first, $enum::SECOND()], $enum::getInstances());
69+
}
70+
71+
public function testGetInstancesCold(): void
72+
{
73+
$enum = $this->makeRawEnum(['FIRST' => 1, 'SECOND' => 2]);
74+
75+
$this->assertCount(2, $enum::getInstances());
6976
}
7077

7178
public function testExceptionNonScalarValue(): void
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace Thunder\Platenum\Tests\Fake;
4+
5+
abstract class DoctrineExtendsBaseEnum extends DoctrineExtendsCoreEnum
6+
{
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace Thunder\Platenum\Tests\Fake;
4+
5+
use Thunder\Platenum\Enum\ConstantsEnumTrait;
6+
7+
abstract class DoctrineExtendsCoreEnum
8+
{
9+
use ConstantsEnumTrait;
10+
}

tests/Fake/DoctrineExtendsEnum.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
declare(strict_types=1);
3+
namespace Thunder\Platenum\Tests\Fake;
4+
5+
/**
6+
* @method static static ONE()
7+
* @method static static TWO()
8+
*/
9+
final class DoctrineExtendsEnum extends DoctrineExtendsBaseEnum
10+
{
11+
private const ONE = 'one';
12+
private const TWO = 'two';
13+
}

0 commit comments

Comments
 (0)