-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extensions for yii request object
- Loading branch information
Showing
4 changed files
with
111 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
services: | ||
- | ||
class: Proget\PHPStan\Yii2\Type\ContainerDynamicMethodReturnTypeExtension | ||
tags: [phpstan.broker.dynamicMethodReturnTypeExtension] | ||
- | ||
class: Proget\PHPStan\Yii2\Type\ContainerDynamicMethodReturnTypeExtension | ||
tags: [phpstan.broker.dynamicMethodReturnTypeExtension] | ||
- | ||
class: Proget\PHPStan\Yii2\Reflection\RequestMethodsClassReflectionExtension | ||
tags: [phpstan.broker.methodsClassReflectionExtension] | ||
- | ||
class: Proget\PHPStan\Yii2\Reflection\RequestPropertiesClassReflectionExtension | ||
tags: [phpstan.broker.propertiesClassReflectionExtension] | ||
|
||
- Proget\PHPStan\Yii2\ServiceMap(%yii2.config_path%) | ||
- Proget\PHPStan\Yii2\ServiceMap(%yii2.config_path%) | ||
parameters: | ||
ignoreErrors: | ||
- '#Access to an undefined property yii\\db\\ActiveRecord#' | ||
- '#Call to an undefined method yii\\db\\ActiveRecord#' | ||
- '#Call to an undefined method yii\\console\\Request#' | ||
- '#Access to an undefined property yii\\console\\Request#' | ||
- '#Call to an undefined method yii\\console\\Response#' | ||
- '#Access to an undefined property yii\\console\\Response#' | ||
- '#Method yii\\db\\ActiveQuery\:\:with\(\) invoked with#' |
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,45 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
|
||
namespace Proget\PHPStan\Yii2\Reflection; | ||
|
||
|
||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Broker\Broker; | ||
use PHPStan\Reflection\BrokerAwareExtension; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Reflection\MethodsClassReflectionExtension; | ||
|
||
final class RequestMethodsClassReflectionExtension implements MethodsClassReflectionExtension, BrokerAwareExtension | ||
{ | ||
/** | ||
* @var Broker | ||
*/ | ||
private $broker; | ||
|
||
public function setBroker(Broker $broker) | ||
{ | ||
$this->broker = $broker; | ||
} | ||
|
||
public function hasMethod(ClassReflection $classReflection, string $methodName): bool | ||
{ | ||
if($classReflection->getName()!=='yii\console\Request') { | ||
return false; | ||
} | ||
|
||
$webRequest = $this->broker->getClass('yii\web\Request'); | ||
|
||
return $webRequest->hasMethod($methodName); | ||
} | ||
|
||
public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection | ||
{ | ||
$webRequest = $this->broker->getClass('yii\web\Request'); | ||
|
||
return $webRequest->getNativeMethod($methodName); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/Reflection/RequestPropertiesClassReflectionExtension.php
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,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
|
||
namespace Proget\PHPStan\Yii2\Reflection; | ||
|
||
|
||
use PhpParser\PrettyPrinter\Standard; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Analyser\TypeSpecifier; | ||
use PHPStan\Broker\Broker; | ||
use PHPStan\Reflection\BrokerAwareExtension; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\PropertiesClassReflectionExtension; | ||
use PHPStan\Reflection\PropertyReflection; | ||
|
||
final class RequestPropertiesClassReflectionExtension implements PropertiesClassReflectionExtension, BrokerAwareExtension | ||
{ | ||
/** | ||
* @var Broker | ||
*/ | ||
private $broker; | ||
|
||
public function setBroker(Broker $broker) | ||
{ | ||
$this->broker = $broker; | ||
} | ||
|
||
public function hasProperty(ClassReflection $classReflection, string $propertyName): bool | ||
{ | ||
if($classReflection->getName()!=='yii\console\Request') { | ||
return false; | ||
} | ||
|
||
$webRequest = $this->broker->getClass('yii\web\Request'); | ||
|
||
return $webRequest->hasProperty($propertyName); | ||
} | ||
|
||
public function getProperty(ClassReflection $classReflection, string $propertyName): PropertyReflection | ||
{ | ||
$webRequest = $this->broker->getClass('yii\web\Request'); | ||
|
||
$printer = new Standard(); | ||
|
||
return $webRequest->getProperty($propertyName, new Scope( | ||
$this->broker, | ||
$printer, | ||
new TypeSpecifier($printer), | ||
(string) $classReflection->getFileName() | ||
)); | ||
} | ||
|
||
} |