Skip to content

Commit

Permalink
order ClassComponentPRoeprtyExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 18, 2024
1 parent a17818c commit 986fdef
Show file tree
Hide file tree
Showing 31 changed files with 205 additions and 186 deletions.
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:8":7,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:11":7,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:14":7,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:17":7,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:21":7,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:23":7},"times":{"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:8":0.003,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:11":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:14":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:17":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:21":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions#\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:23":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions with data set \"\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:8\"":0.002,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions with data set \"\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:11\"":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions with data set \"\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:14\"":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions with data set \"\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:17\"":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions with data set \"\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:21\"":0,"PHPStanCakePHP2\\Test\\Feature\\ClassRegistryInitTest::testControllerExtensions with data set \"\/var\/www\/phpstan-cakephp-2\/tests\/Feature\/data\/class_registry_init.php:23\"":0}}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^10.5",
"phpstan/extension-installer": "^1.3",
"tracy/tracy": "^2.10"
"tracy/tracy": "^2.10",
"symplify/easy-coding-standard": "^12.1"
},
"autoload": {
"psr-4": {
Expand Down
62 changes: 31 additions & 31 deletions config/extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,42 @@ parameters:
- ../stubs/Utility.stub

services:
# -
# class: PHPStanCakePHP2\ClassComponentsExtension
# tags:
# - phpstan.broker.propertiesClassReflectionExtension
#
# -
# class: PHPStanCakePHP2\ClassModelsExtension
# tags:
# - phpstan.broker.propertiesClassReflectionExtension
#
# # checked
# -
# class: PHPStanCakePHP2\ReturnTypeExtension\ClassRegistryInitExtension
# tags:
# - phpstan.broker.dynamicStaticMethodReturnTypeExtension
-
class: PHPStanCakePHP2\ClassPropertyExtension\ClassComponentPropertyExtension
tags:
- phpstan.broker.propertiesClassReflectionExtension

-
class: PHPStanCakePHP2\ClassPropertyExtension\ClassModelsPropertyExtension
tags:
- phpstan.broker.propertiesClassReflectionExtension

# checked
-
class: PHPStanCakePHP2\ReturnTypeExtension\ClassRegistryInitExtension
tags:
- phpstan.broker.dynamicStaticMethodReturnTypeExtension

# checked
-
class: PHPStanCakePHP2\ClassPropertyExtension\ShellClassPropertyExtension
tags:
- phpstan.broker.propertiesClassReflectionExtension

# -
# class: PHPStanCakePHP2\ModelBehaviorsExtension
# arguments:
# behaviorPaths: %behaviorPaths%
# tags:
# - phpstan.broker.methodsClassReflectionExtension

# -
# class: PHPStanCakePHP2\Service\SchemaService
# arguments:
# schemaPaths: %schemaPaths%
#
# -
# class: PHPStanCakePHP2\LoadComponentOnFlyMethodReturnTypeExtension
# tags:
# - phpstan.broker.dynamicMethodReturnTypeExtension
-
class: PHPStanCakePHP2\ModelBehaviorsExtension
arguments:
behaviorPaths: %behaviorPaths%
tags:
- phpstan.broker.methodsClassReflectionExtension

-
class: PHPStanCakePHP2\Service\SchemaService
arguments:
schemaPaths: %schemaPaths%

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

28 changes: 28 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])

// add a single rule
->withRules([
NoUnusedImportsFixer::class,
])

// add sets - group of rules
// ->withPreparedSets(
// arrays: true,
// namespaces: true,
// spaces: true,
// docblocks: true,
// comments: true,
// )

;
10 changes: 0 additions & 10 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,7 @@ parameters:
- */Fixture/*
# ported from cacke
- src/CakePHP/PortedInflector.php
<<<<<<< HEAD
<<<<<<< HEAD
=======

ignoreErrors:
# not practical as mixed
- '#Method (.*?)::test(.*?)\(\) has parameter \$args with no type specified#'
>>>>>>> 514d1ac (fixup! mics)
=======

ignoreErrors:
# not practical as mixed
- '#Method PHPStanCakePHP2\\Tests\\(.*?)::test(.*?)\(\) has parameter \$args with no type specified#'
>>>>>>> 9d38081 (misc)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStanCakePHP2\PublicReadOnlyPropertyReflection;
use PHPStanCakePHP2\Reflection\PublicReadOnlyPropertyReflection;

abstract class AbstractClassPropertyExtension implements PropertiesClassReflectionExtension
{
Expand Down Expand Up @@ -45,18 +45,21 @@ public function getProperty(
}

/**
* @todo use constract instead to separate
* Get the class name of the type of property.
*/
abstract protected function getPropertyParentClassName(): string;

/**
* @todo use constract instead to separate
* Get the class names which can contain the property.
*
* @return array<string>
*/
abstract protected function getContainingClassNames(): array;

/**
* @todo use constract instead to separate
* Return the class name from the property name.
*/
abstract protected function getClassNameFromPropertyName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPStanCakePHP2;
namespace PHPStanCakePHP2\ClassPropertyExtension;

use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ClassConstFetch;
Expand All @@ -12,8 +12,12 @@
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStanCakePHP2\Reflection\PublicReadOnlyPropertyReflection;

final class ClassComponentsExtension implements PropertiesClassReflectionExtension
/**
* @see \ClassPropertyExtension\ClassComponentPropertyExtension\ClassComponentPropertyExtensionTest
*/
final class ClassComponentPropertyExtension implements PropertiesClassReflectionExtension
{
private ReflectionProvider $reflectionProvider;

Expand All @@ -28,6 +32,8 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
return false;
}



$isDefinedInComponentsProperty = (bool) array_filter(
$this->getDefinedComponentsAsList($classReflection),
static fn (string $componentName): bool => $componentName === $propertyName
Expand Down Expand Up @@ -76,7 +82,7 @@ private function getDefinedComponentsAsList(ClassReflection $classReflection): a
$definedComponents = [];

foreach (array_merge([$classReflection], $classReflection->getParents()) as $class) {
if (!$class->hasProperty('components')) {
if (! $class->hasProperty('components')) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

declare(strict_types=1);

namespace PHPStanCakePHP2;

use PHPStanCakePHP2\ClassPropertyExtension\AbstractClassPropertyExtension;
namespace PHPStanCakePHP2\ClassPropertyExtension;

/**
* Adds {@link Model}s as properties to {@link Shell}s
*/
final class ClassModelsExtension extends AbstractClassPropertyExtension
final class ClassModelsPropertyExtension extends AbstractClassPropertyExtension
{
protected function getPropertyParentClassName(): string
{
Expand Down
18 changes: 1 addition & 17 deletions src/ClassPropertyExtension/ShellClassPropertyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

namespace PHPStanCakePHP2\ClassPropertyExtension;

use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension;

/**
* Adds {@link Model}s as properties to {@link Shell}s.
*
* @see \PHPStanCakePHP2\Tests\ClassPropertyExtension\ShellClassPropertyExtension\ShellClassPropertyExtensionTest
*/
final class ShellClassPropertyExtension implements PropertiesClassReflectionExtension
final class ShellClassPropertyExtension extends AbstractClassPropertyExtension
{
protected function getPropertyParentClassName(): string
{
Expand All @@ -32,18 +30,4 @@ protected function getClassNameFromPropertyName(
): string {
return $propertyName . 'Task';
}

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
{
dump(1);
die;
// TODO: Implement hasProperty() method.
}

public function getProperty(ClassReflection $classReflection, string $propertyName): \PHPStan\Reflection\PropertyReflection
{
dump(2);
die;
// TODO: Implement getProperty() method.
}
}
1 change: 1 addition & 0 deletions src/ModelBehaviorsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\Reflection\ReflectionProvider;
use PHPStanCakePHP2\Reflection\ClassReflectionFinder;

/**
* Adds methods to {@link Model}s from {@link ModelBehavior} classes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPStanCakePHP2;
namespace PHPStanCakePHP2\Reflection;

use Exception;
use PHPStan\Reflection\ClassReflection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PHPStanCakePHP2;
namespace PHPStanCakePHP2\Reflection;

use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertyReflection;
Expand Down
15 changes: 1 addition & 14 deletions src/ReturnTypeExtension/ClassRegistryInitExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
/**
* @see \PHPStanCakePHP2\Tests\ReturnTypeExtension\ClassRegistryInitExtension\ClassRegistryInitExtensionTest
*/
final class
ClassRegistryInitExtension implements DynamicStaticMethodReturnTypeExtension
final class ClassRegistryInitExtension implements DynamicStaticMethodReturnTypeExtension
{
private ReflectionProvider $reflectionProvider;

Expand Down Expand Up @@ -60,20 +59,8 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
return new ObjectType($value);
}

<<<<<<< HEAD
<<<<<<< HEAD:src/ClassRegistryInitExtension.php
if ($this->schemaService->hasTable(PortedInflector::tableize($value))) {
=======
$tableName = PortedInflector::tableize($value);
if ($this->schemaService->hasTable($tableName)) {
>>>>>>> e0614d1 (fixup! misc):src/ReturnTypeExtension/ClassRegistryInitExtension.php
=======
$tableName = PortedInflector::tableize($value);

var_dump($tableName);

if ($this->schemaService->hasTable($tableName)) {
>>>>>>> 7e16f7f (tidy up)
return new ObjectType('Model');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Service/SchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace PHPStanCakePHP2\Service;

use PHPStanCakePHP2\ClassReflectionFinder;
use Exception;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionProperty;
use PHPStan\Reflection\ReflectionProvider;
use PHPStanCakePHP2\Reflection\ClassReflectionFinder;
use ReflectionProperty as CoreReflectionProperty;

/**
Expand Down
13 changes: 13 additions & 0 deletions stubs/CakePHP/Component.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<?php

/**
* Slim copy of
* https://github.com/cakephp/cakephp/blob/2.10.24/lib/Cake/Controller/Component.php
*/
class Component
{
public $components = [];

public function __get(string $name)
{
if (isset($this->{$name})) {
return $this->{$name};
}

return 'some value';
}
}
4 changes: 3 additions & 1 deletion stubs/CakePHP/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

class Model
{

public function __get(string $name)
{
}
}
11 changes: 11 additions & 0 deletions stubs/CakePHP/Shell.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?php

/**
* Slim copy of
* https://github.com/cakephp/cakephp/blob/2.10.24/lib/Cake/Console/Shell.php
*/
class Shell
{
public function __get(string $name)
{
if (isset($this->{$name})) {
return $this->{$name};
}

return 'some value';
}
}
Loading

0 comments on commit 986fdef

Please sign in to comment.