-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #4 fix generics templates (bendavies)
This PR was squashed before being merged into the main branch. Discussion ---------- fix generics templates This PR fixes the templates for `MicroMapperInterface` and `MapperInterface`. regression tests have been added. as an aside, is the `$toClass` param in `MapperInterface::populate(...)` redundant? It seems we will only ever have concrete implementations here and will just new up a new class, which will match the class provided in the `AsMapper` attribute. Commits ------- 15781f2 fix generics templates
- Loading branch information
Showing
11 changed files
with
109 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,6 @@ | |
* | ||
* Also add #[AsMapper(from: Foo:class, to: Bar:class)] to each mapper class. | ||
* | ||
* @template TFrom of object | ||
* @template TTo of object | ||
* | ||
* @author Ryan Weaver <[email protected]> | ||
*/ | ||
interface MapperInterface | ||
|
@@ -27,7 +24,8 @@ interface MapperInterface | |
* This method should load (e.g. from the database) or instantiate the "to object". | ||
* Avoid populating any properties except for an identifier. | ||
* | ||
* @param TFrom $from | ||
* @template TTo of object | ||
* | ||
* @param class-string<TTo> $toClass | ||
* | ||
* @return TTo | ||
|
@@ -39,8 +37,9 @@ public function load(object $from, string $toClass, array $context): object; | |
* | ||
* Receives the "to object" returned from load(). | ||
* | ||
* @param TFrom $from | ||
* @param TTo $to | ||
* @template TTo of object | ||
* | ||
* @param TTo $to | ||
* | ||
* @return TTo | ||
*/ | ||
|
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the SymfonyCasts MicroMapper package. | ||
* Copyright (c) SymfonyCasts <https://symfonycasts.com/> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfonycasts\MicroMapper\Tests\PHPStan; | ||
|
||
use PHPStan\Testing\TypeInferenceTestCase; | ||
|
||
final class MicroMapperTest extends TypeInferenceTestCase | ||
{ | ||
/** @return array<string, mixed[]> */ | ||
public static function dataFileAsserts(): iterable | ||
{ | ||
yield from self::gatherAssertTypes(__DIR__.'/data/micro_mapper.php'); | ||
yield from self::gatherAssertTypes(__DIR__.'/data/mapper.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
mixed ...$args, | ||
): void { | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the SymfonyCasts MicroMapper package. | ||
* Copyright (c) SymfonyCasts <https://symfonycasts.com/> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfonycasts\MicroMapper\MapperInterface; | ||
use Symfonycasts\MicroMapper\Tests\fixtures\DinosaurDto; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function doMapperInterfaceLoad(MapperInterface $microMapper): void | ||
{ | ||
assertType(DinosaurDto::class, $microMapper->load(new \stdClass(), DinosaurDto::class)); | ||
} | ||
|
||
function doMapperInterfacePopulate(MapperInterface $microMapper, DinosaurDto $dto): void | ||
{ | ||
assertType(DinosaurDto::class, $microMapper->populate(new \stdClass(), $dto)); | ||
} |
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); | ||
|
||
/* | ||
* This file is part of the SymfonyCasts MicroMapper package. | ||
* Copyright (c) SymfonyCasts <https://symfonycasts.com/> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfonycasts\MicroMapper\MicroMapper; | ||
use Symfonycasts\MicroMapper\MicroMapperInterface; | ||
use Symfonycasts\MicroMapper\Tests\fixtures\DinosaurDto; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
function doMicroMapperInterfaceMap(MicroMapperInterface $microMapper): void | ||
{ | ||
assertType(DinosaurDto::class, $microMapper->map(new \stdClass(), DinosaurDto::class)); | ||
} | ||
|
||
function doMicroMapperImplementationMap(MicroMapper $microMapper): void | ||
{ | ||
assertType(DinosaurDto::class, $microMapper->map(new \stdClass(), DinosaurDto::class)); | ||
} |
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,11 @@ | ||
%_PHPStan_d5c599c96% | ||
%^Method "PhpParser\\NodeVisitor\:\:leaveNode\(\)" might add "int\|Node\|array\|null" as a native return type declaration in the future\. Do the same in implementation "PHPStan\\BetterReflection\\SourceLocator\\SourceStubber\\PhpStormStubs\\CachingVisitor" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "PhpParser\\NodeVisitor\:\:enterNode\(\)" might add "int\|Node\|null" as a native return type declaration in the future\. Do the same in implementation "PhpParser\\NodeVisitorAbstract@anonymous" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "PhpParser\\NodeVisitor\:\:leaveNode\(\)" might add "int\|Node\|array\|null" as a native return type declaration in the future\. Do the same in implementation "PhpParser\\NodeVisitorAbstract@anonymous" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "ReflectionFunction\:\:invokeArgs\(\)" might add "mixed" as a native return type declaration in the future\. Do the same in child class "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionFunction" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "ReflectionClass\:\:getFileName\(\)" might add "string\|false" as a native return type declaration in the future. Do the same in child class "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionClass" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "ReflectionClass\:\:getStartLine\(\)" might add "int\|false" as a native return type declaration in the future. Do the same in child class "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionClass" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "ReflectionClass\:\:getEndLine\(\)" might add "int\|false" as a native return type declaration in the future. Do the same in child class "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionClass" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "ReflectionClass\:\:getDocComment\(\)" might add "string\|false" as a native return type declaration in the future. Do the same in child class "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionClass" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "ReflectionClass\:\:getStaticPropertyValue\(\)" might add "mixed" as a native return type declaration in the future. Do the same in child class "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionClass" now to avoid errors or add an explicit @return annotation to suppress this message\.$% | ||
%^Method "ReflectionClass\:\:getExtensionName\(\)" might add "string\|false" as a native return type declaration in the future. Do the same in child class "PHPStan\\BetterReflection\\Reflection\\Adapter\\ReflectionClass" now to avoid errors or add an explicit @return annotation to suppress this message\.$% |