Skip to content

Commit

Permalink
Update namespaces. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored Oct 9, 2023
1 parent 4f0d69c commit ef049c6
Show file tree
Hide file tree
Showing 21 changed files with 312 additions and 215 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
},
"autoload": {
"psr-4": {
"yii\\phpstan\\": "src"
"Yii\\PHPStan\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"yii\\phpstan\\tests\\": "tests"
"Yii\\PHPStan\\Tests\\": "tests"
}
},
"extra": {
Expand Down
22 changes: 11 additions & 11 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ parametersSchema:

services:
-
class: yii\phpstan\Reflection\ApplicationPropertiesClassReflectionExtension
class: Yii\PHPStan\Reflection\ApplicationPropertiesClassReflectionExtension
tags: [phpstan.broker.propertiesClassReflectionExtension]
-
class: yii\phpstan\Reflection\RequestMethodsClassReflectionExtension
class: Yii\PHPStan\Reflection\RequestMethodsClassReflectionExtension
tags: [phpstan.broker.methodsClassReflectionExtension]
-
class: yii\phpstan\Reflection\RequestPropertiesClassReflectionExtension
class: Yii\PHPStan\Reflection\RequestPropertiesClassReflectionExtension
tags: [phpstan.broker.propertiesClassReflectionExtension]
-
class: yii\phpstan\Reflection\ResponsePropertiesClassReflectionExtension
class: Yii\PHPStan\Reflection\ResponsePropertiesClassReflectionExtension
tags: [phpstan.broker.propertiesClassReflectionExtension]
-
class: yii\phpstan\Reflection\UserPropertiesClassReflectionExtension
class: Yii\PHPStan\Reflection\UserPropertiesClassReflectionExtension
tags: [phpstan.broker.propertiesClassReflectionExtension]
-
class: yii\phpstan\Type\ActiveQueryDynamicMethodReturnTypeExtension
class: Yii\PHPStan\Type\ActiveQueryDynamicMethodReturnTypeExtension
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
class: yii\phpstan\Type\ActiveRecordDynamicMethodReturnTypeExtension
class: Yii\PHPStan\Type\ActiveRecordDynamicMethodReturnTypeExtension
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
class: yii\phpstan\Type\HeaderCollectionDynamicMethodReturnTypeExtension
class: Yii\PHPStan\Type\HeaderCollectionDynamicMethodReturnTypeExtension
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
-
class: yii\phpstan\Type\ActiveRecordDynamicStaticMethodReturnTypeExtension
class: Yii\PHPStan\Type\ActiveRecordDynamicStaticMethodReturnTypeExtension
tags: [phpstan.broker.dynamicStaticMethodReturnTypeExtension]
-
class: yii\phpstan\Type\ContainerDynamicMethodReturnTypeExtension
class: Yii\PHPStan\Type\ContainerDynamicMethodReturnTypeExtension
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]

- yii\phpstan\ServiceMap(%yii2.config_path%)
- Yii\PHPStan\ServiceMap(%yii2.config_path%)
32 changes: 9 additions & 23 deletions src/Reflection/ApplicationPropertiesClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,27 @@

declare(strict_types=1);

namespace yii\phpstan\Reflection;
namespace Yii\PHPStan\Reflection;

use PHPStan\Reflection\Annotations\AnnotationsPropertiesClassReflectionExtension;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Dummy\DummyPropertyReflection;
use PHPStan\Reflection\MissingPropertyFromReflectionException;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ObjectType;
use yii\base\Application as BaseApplication;
use yii\phpstan\ServiceMap;
use Yii\PHPStan\ServiceMap;
use yii\web\Application as WebApplication;

final class ApplicationPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{
/**
* @var AnnotationsPropertiesClassReflectionExtension
*/
private $annotationsProperties;

/**
* @var ServiceMap
*/
private $serviceMap;

/**
* @var \PHPStan\Reflection\ReflectionProvider
*/
private $reflectionProvider;

public function __construct(
AnnotationsPropertiesClassReflectionExtension $annotationsProperties,
ReflectionProvider $reflectionProvider,
ServiceMap $serviceMap
private readonly AnnotationsPropertiesClassReflectionExtension $annotationsProperties,
private readonly ReflectionProvider $reflectionProvider,
private readonly ServiceMap $serviceMap
) {
$this->annotationsProperties = $annotationsProperties;
$this->serviceMap = $serviceMap;
$this->reflectionProvider = $reflectionProvider;
}

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
Expand All @@ -57,6 +40,9 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
|| $this->serviceMap->getComponentClassById($propertyName);
}

/**
* @throws MissingPropertyFromReflectionException
*/
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
{
if ($classReflection->getName() !== WebApplication::class) {
Expand Down
21 changes: 5 additions & 16 deletions src/Reflection/ComponentPropertyReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,17 @@

declare(strict_types=1);

namespace yii\phpstan\Reflection;
namespace Yii\PHPStan\Reflection;

use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Type;

final class ComponentPropertyReflection implements PropertyReflection
{
/**
* @var PropertyReflection
*/
private $fallbackProperty;

/**
* @var Type
*/
private $type;

public function __construct(PropertyReflection $fallbackProperty, Type $type)
public function __construct(private readonly PropertyReflection $fallbackProperty, private readonly Type $type)
{
$this->fallbackProperty = $fallbackProperty;
$this->type = $type;
}

public function getType(): Type
Expand Down Expand Up @@ -76,7 +65,7 @@ public function canChangeTypeAfterAssignment(): bool
return $this->fallbackProperty->canChangeTypeAfterAssignment();
}

public function isDeprecated(): \PHPStan\TrinaryLogic
public function isDeprecated(): TrinaryLogic
{
return $this->fallbackProperty->isDeprecated();
}
Expand All @@ -86,7 +75,7 @@ public function getDeprecatedDescription(): ?string
return $this->fallbackProperty->getDeprecatedDescription();
}

public function isInternal(): \PHPStan\TrinaryLogic
public function isInternal(): TrinaryLogic
{
return $this->fallbackProperty->isInternal();
}
Expand Down
14 changes: 6 additions & 8 deletions src/Reflection/RequestMethodsClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@

declare(strict_types=1);

namespace yii\phpstan\Reflection;
namespace Yii\PHPStan\Reflection;

use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\Reflection\MissingMethodFromReflectionException;
use PHPStan\Reflection\ReflectionProvider;
use yii\console\Request as ConsoleRequest;
use yii\web\Request as WebRequest;

final class RequestMethodsClassReflectionExtension implements MethodsClassReflectionExtension
{
/**
* @var ReflectionProvider
*/
private $reflectionProvider;

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

public function hasMethod(ClassReflection $classReflection, string $methodName): bool
Expand All @@ -32,6 +27,9 @@ public function hasMethod(ClassReflection $classReflection, string $methodName):
return $this->reflectionProvider->getClass(WebRequest::class)->hasMethod($methodName);
}

/**
* @throws MissingMethodFromReflectionException
*/
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection
{
return $this->reflectionProvider->getClass(WebRequest::class)->getNativeMethod($methodName);
Expand Down
18 changes: 9 additions & 9 deletions src/Reflection/RequestPropertiesClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

declare(strict_types=1);

namespace yii\phpstan\Reflection;
namespace Yii\PHPStan\Reflection;

use PHPStan\Analyser\OutOfClassScope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MissingPropertyFromReflectionException;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
Expand All @@ -14,14 +15,8 @@

final class RequestPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{
/**
* @var ReflectionProvider
*/
private $reflectionProvider;

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

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
Expand All @@ -33,8 +28,13 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
return $this->reflectionProvider->getClass(WebRequest::class)->hasProperty($propertyName);
}

/**
* @throws MissingPropertyFromReflectionException
*/
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
{
return $this->reflectionProvider->getClass(WebRequest::class)->getProperty($propertyName, new OutOfClassScope());
return $this->reflectionProvider
->getClass(WebRequest::class)
->getProperty($propertyName, new OutOfClassScope());
}
}
18 changes: 9 additions & 9 deletions src/Reflection/ResponsePropertiesClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

declare(strict_types=1);

namespace yii\phpstan\Reflection;
namespace Yii\PHPStan\Reflection;

use PHPStan\Analyser\OutOfClassScope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MissingPropertyFromReflectionException;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
Expand All @@ -14,14 +15,8 @@

final class ResponsePropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{
/**
* @var ReflectionProvider
*/
private $reflectionProvider;

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

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
Expand All @@ -33,8 +28,13 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
return $this->reflectionProvider->getClass(WebResponse::class)->hasProperty($propertyName);
}

/**
* @throws MissingPropertyFromReflectionException
*/
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
{
return $this->reflectionProvider->getClass(WebResponse::class)->getProperty($propertyName, new OutOfClassScope());
return $this->reflectionProvider
->getClass(WebResponse::class)
->getProperty($propertyName, new OutOfClassScope());
}
}
14 changes: 6 additions & 8 deletions src/Reflection/UserPropertiesClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@

declare(strict_types=1);

namespace yii\phpstan\Reflection;
namespace Yii\PHPStan\Reflection;

use PHPStan\Reflection\Annotations\AnnotationsPropertiesClassReflectionExtension;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Dummy\DummyPropertyReflection;
use PHPStan\Reflection\MissingPropertyFromReflectionException;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Type\MixedType;
use yii\web\User;

final class UserPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension
{
/**
* @var AnnotationsPropertiesClassReflectionExtension
*/
private $annotationsProperties;

public function __construct(AnnotationsPropertiesClassReflectionExtension $annotationsProperties)
public function __construct(private readonly AnnotationsPropertiesClassReflectionExtension $annotationsProperties)
{
$this->annotationsProperties = $annotationsProperties;
}

public function hasProperty(ClassReflection $classReflection, string $propertyName): bool
Expand All @@ -34,6 +29,9 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
|| $this->annotationsProperties->hasProperty($classReflection, $propertyName);
}

/**
* @throws MissingPropertyFromReflectionException
*/
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection
{
if ($propertyName === 'identity') {
Expand Down
Loading

0 comments on commit ef049c6

Please sign in to comment.