forked from syntro-opensource/silverstripe-phpstan
-
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 remote-tracking branch 'remotes/upstream/5'
- Loading branch information
Showing
16 changed files
with
178 additions
and
188 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
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 was deleted.
Oops, something went wrong.
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,8 @@ | ||
<?php | ||
|
||
namespace { | ||
|
||
use SilverStripe\CMS\Model\SiteTree; | ||
|
||
class Page extends SiteTree {} | ||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace { | ||
|
||
use SilverStripe\CMS\Controllers\ContentController; | ||
|
||
class PageController extends ContentController {} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace Syntro\SilverstripePHPStan\Tests\Reflection; | ||
|
||
use MethodClassReflectionReturnTypesNamespace\Team; | ||
use PHPStan\Testing\TypeInferenceTestCase; | ||
use SilverStripe\Core\Config\Config; | ||
|
||
class MethodClassReflectionExtensionTest extends TypeInferenceTestCase | ||
{ | ||
/** | ||
* @return iterable<mixed> | ||
*/ | ||
public function dataFileAsserts(): iterable | ||
{ | ||
// path to a file with actual asserts of expected types: | ||
require_once(__DIR__ . '/data/method-class-reflection.php'); | ||
yield from $this->gatherAssertTypes(__DIR__ . '/data/method-class-reflection.php'); | ||
} | ||
|
||
/** | ||
* @dataProvider dataFileAsserts | ||
*/ | ||
public function testFileAsserts( | ||
string $assertType, | ||
string $file, | ||
...$args | ||
): void { | ||
$this->assertFileAsserts($assertType, $file, ...$args); | ||
} | ||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
// path to your project's phpstan.neon, or extension.neon in case of custom extension packages | ||
return [ | ||
__DIR__ . '/../../phpstan.neon' | ||
]; | ||
} | ||
} |
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,73 @@ | ||
<?php | ||
// @codingStandardsIgnoreStart | ||
namespace MethodClassReflectionReturnTypesNamespace; | ||
|
||
// SilverStripe | ||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\ORM\DataObject; | ||
use Syntro\SilverstripePHPStan\ClassHelper; | ||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* setting up relations in the Classes doesn't get picked up | ||
* Need to add to the config manually | ||
* @return void | ||
*/ | ||
function initDbRelations() { | ||
Config::modify()->merge(Team::class, 'has_many', [ | ||
'Players' => Player::class, | ||
'WinningPlayers' => Player::class . '.WinningTeam' | ||
]); | ||
|
||
Config::modify()->merge(Player::class, 'has_one', [ | ||
'Team' => Team::class, | ||
'WinningTeam' => Team::class . '.WinningPlayers' | ||
]); | ||
|
||
Config::modify()->merge(Coach::class, 'belongs_to', [ | ||
'Team' => Team::class, | ||
'WinningTeam' => Team::class . '.WinningCoach', | ||
]); | ||
} | ||
|
||
initDbRelations(); | ||
|
||
class Foo | ||
{ | ||
public function doFoo(): void | ||
{ | ||
|
||
|
||
$player = new Player; | ||
// Standard has_one | ||
assertType(Team::class, $player->Team()); | ||
// Has one with a custom relation name | ||
assertType(Team::class, $player->WinningTeam()); | ||
|
||
$team = new Team(); | ||
// Standard has_one | ||
assertType( sprintf('%s<%s>', ClassHelper::HasManyList, Player::class), $team->Players()); | ||
// Has one with a custom relation name | ||
assertType( sprintf('%s<%s>', ClassHelper::HasManyList, Player::class), $team->WinningPlayers()); | ||
|
||
$coach = new Coach(); | ||
assertType(Team::class, $coach->Team()); | ||
// Has one with a custom relation name | ||
assertType(Team::class, $coach->WinningTeam()); | ||
die(); | ||
} | ||
} | ||
|
||
class Team extends DataObject | ||
{ | ||
|
||
} | ||
|
||
class Player extends DataObject | ||
{ | ||
} | ||
|
||
class Coach extends DataObject | ||
{ | ||
} | ||
// @codingStandardsIgnoreEnd |
Oops, something went wrong.