Skip to content

Commit

Permalink
slip
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 18, 2024
1 parent 7832a44 commit 1a32570
Show file tree
Hide file tree
Showing 43 changed files with 153 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1

- name: Validate composer
run: composer validate
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
composer.lock

# tests
.phpunit.result
.phpunit.result.cache
1 change: 0 additions & 1 deletion .phpunit.result.cache

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"classmap": [
"stubs",
"tests/Feature/classes"
"tests/Source"
]
},
"extra": {
Expand Down
5 changes: 5 additions & 0 deletions config/extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ services:
tags:
- phpstan.broker.methodsClassReflectionExtension

-
class: PHPStanCakePHP2\ReturnTypeExtension\LoadComponentOnFlyMethodReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension

-
class: PHPStanCakePHP2\Service\SchemaService
arguments:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace PHPStanCakePHP2\ReturnTypeExtension;

use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;

final class LoadComponentOnFlyMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension
{
private ReflectionProvider $reflectionProvider;

public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}

public function getClass(): string
{
return 'ComponentCollection';
}

public function isMethodSupported(MethodReflection $methodReflection): bool
{
return $methodReflection->getName() === 'load';
}

public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type
{
$arg = $methodCall->getArgs()[0]->value;

if (!$arg instanceof String_) {
return null;
}

$componentName = $arg->value . 'Component';

if (!$this->reflectionProvider->hasClass($componentName)) {
return null;
}

if (!$this->reflectionProvider->getClass($componentName)->is('Component')) {
return null;
}

return new ObjectType($componentName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static function dataFileAsserts(): Iterator
{
yield from self::gatherAssertTypes(__DIR__ . '/Fixture/existing_component_component.php');
yield from self::gatherAssertTypes(__DIR__ . '/Fixture/invalid_component_property.php');

yield from self::gatherAssertTypes(__DIR__ . '/Fixture/existing_controller_component.php');
yield from self::gatherAssertTypes(__DIR__ . '/Fixture/existing_controller_component_from_parent_controller.php');
yield from self::gatherAssertTypes(__DIR__ . '/Fixture/existing_controller_component_with_same_method_name_as_model.php');
}

public static function getAdditionalConfigFiles(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Controller\Component\BasicComponent;
use function PHPStan\Testing\assertType;

/** @var BasicComponent $parentComponent */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Controller\BasicController;
use function PHPStan\Testing\assertType;

/** @var BasicController $controller */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Controller\SameAsModelController;
use function PHPStan\Testing\assertType;

/** @var SameAsModelController $controller */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Controller\SameAsModelController;
use function PHPStan\Testing\assertType;

/** @var SameAsModelController $controller */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Controller\Component\BasicComponent;
use function PHPStan\Testing\assertType;

/** @var BasicComponent $component */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public static function dataFileAsserts(): \Iterator
yield from self::gatherAssertTypes(__DIR__ . '/Fixture/custom_model_behavior.php');
yield from self::gatherAssertTypes(__DIR__ . '/Fixture/invalid_model_property.php');
yield from self::gatherAssertTypes(__DIR__ . '/Fixture/existing_model_model.php');

yield from self::gatherAssertTypes(__DIR__ . '/Fixture/existing_controller_model.php');
yield from self::gatherAssertTypes(__DIR__ . '/Fixture/invalid_controller_property.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Model\BasicModel;
use function PHPStan\Testing\assertType;

/** @var BasicModel $model */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Model\BasicModel;
use function PHPStan\Testing\assertType;

/** @var BasicModel $model */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Controller\BasicController;
use function PHPStan\Testing\assertType;

/** @var BasicController $controller */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Model\BasicModel;
use function PHPStan\Testing\assertType;

/** @var BasicModel $model */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Controller\BasicController;
use function PHPStan\Testing\assertType;

/** @var BasicController $controller */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Model\BasicModel;
use function PHPStan\Testing\assertType;

/** @var BasicModel $model */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Console\Command\BasicShell;
use function PHPStan\Testing\assertType;

$assign = function (BasicShell $shell) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Console\Command\BasicShell;
use function PHPStan\Testing\assertType;

/** @var BasicShell $shell */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types = 1);

use PHPStanCakePHP2\Tests\Source\Console\Command\BasicShell;
use function PHPStan\Testing\assertType;

/** @var BasicShell $shell */
Expand Down
34 changes: 0 additions & 34 deletions tests/Feature/ControllerExtensionsTest.php

This file was deleted.

5 changes: 0 additions & 5 deletions tests/Feature/classes/Console/Command/BasicShell.php

This file was deleted.

3 changes: 0 additions & 3 deletions tests/Feature/classes/Console/Command/Task/BasicTask.php

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions tests/Feature/classes/Model/BasicModel.php

This file was deleted.

3 changes: 0 additions & 3 deletions tests/Feature/classes/Model/SecondModel.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use PHPStanCakePHP2\Tests\Source\Model\BasicModel;
use function PHPStan\Testing\assertType;

$class = ClassRegistry::init(BasicModel::class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Config\Schema;
use CakeSchema;

class AppSchema extends CakeSchema
{
/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Source/Console/Command/BasicShell.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Console\Command;
use Shell;

class BasicShell extends Shell
{
}
8 changes: 8 additions & 0 deletions tests/Source/Console/Command/Task/BasicTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Console\Command\Task;
use Shell;

class BasicTask extends Shell
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

declare(strict_types=1);

namespace PHPStanCakePHP2\Tests\Source\Controller;
use Controller;

class BaseController extends Controller
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Controller;
use Controller;

class BasicController extends Controller
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Controller\Component;
use Component;

class BasicComponent extends Component
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Controller\Component;
use Component;

class SameAsModelComponent extends Component
{
public function sameMethod(): int
Expand Down
8 changes: 8 additions & 0 deletions tests/Source/Controller/Component/SecondComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Controller\Component;
use Component;

class SecondComponent extends Component
{
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Controller;

use PHPStanCakePHP2\Tests\Source\Controller\Component\BasicComponent;

class SameAsModelController extends BaseController
{
/**
Expand Down
8 changes: 8 additions & 0 deletions tests/Source/Model/BasicModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Model;
use Model;

class BasicModel extends Model
{
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

namespace PHPStanCakePHP2\Tests\Source\Model\Behavior;
use Model;
use ModelBehavior;

class BasicBehavior extends ModelBehavior
{
public function behaviorMethod(Model $model, string $string): string
Expand Down
Loading

0 comments on commit 1a32570

Please sign in to comment.