Skip to content

Commit

Permalink
Activate Renovatebot (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Oct 20, 2023
1 parent 6616c1b commit 1df5ece
Show file tree
Hide file tree
Showing 32 changed files with 80 additions and 132 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Makefile export-ignore
phpstan.neon export-ignore
phpstan-baseline.neon export-ignore
phpunit.xml export-ignore
renovate.json export-ignore
13 changes: 0 additions & 13 deletions .github/dependabot.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- "master"
- "renovate/*"

jobs:
composer-json-lint:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Latest Stable Version](https://img.shields.io/packagist/v/slam/phpstan-laminas-framework.svg)](https://packagist.org/packages/slam/phpstan-laminas-framework)
[![Downloads](https://img.shields.io/packagist/dt/slam/phpstan-laminas-framework.svg)](https://packagist.org/packages/slam/phpstan-laminas-framework)
[![Integrate](https://github.com/Slamdunk/phpstan-laminas-framework/workflows/Integrate/badge.svg?branch=master)](https://github.com/Slamdunk/phpstan-laminas-framework/actions)
[![Integrate](https://github.com/Slamdunk/phpstan-laminas-framework/workflows/ci/badge.svg?branch=master)](https://github.com/Slamdunk/phpstan-laminas-framework/actions)
[![Code Coverage](https://codecov.io/gh/Slamdunk/phpstan-laminas-framework/coverage.svg?branch=master)](https://codecov.io/gh/Slamdunk/phpstan-laminas-framework?branch=master)

* [PHPStan](https://phpstan.org/)
Expand Down
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
],
"require": {
"php": "~8.1.0 || ~8.2.0",
"phpstan/phpstan": "^1.9.2"
"phpstan/phpstan": "^1.10.39"
},
"require-dev": {
"laminas/laminas-cache": "^3.9.0",
"laminas/laminas-cache-storage-adapter-memory": "^2.2.0",
"laminas/laminas-filter": "^2.29.0",
"laminas/laminas-form": "^3.8.0",
"laminas/laminas-hydrator": "^4.10.0",
"laminas/laminas-i18n": "^2.21.0",
"laminas/laminas-inputfilter": "^2.22.1",
"laminas/laminas-log": "^2.16.0",
"laminas/laminas-mail": "^2.21.0",
"laminas/laminas-mvc": "^3.6.0",
"laminas/laminas-cache": "^3.11.0",
"laminas/laminas-cache-storage-adapter-memory": "^2.3.0",
"laminas/laminas-filter": "^2.32.0",
"laminas/laminas-form": "^3.13.1",
"laminas/laminas-hydrator": "^4.14.0",
"laminas/laminas-i18n": "^2.23.1",
"laminas/laminas-inputfilter": "^2.27.0",
"laminas/laminas-log": "^2.16.1",
"laminas/laminas-mail": "^2.23.0",
"laminas/laminas-mvc": "^3.6.1",
"laminas/laminas-paginator": "^2.17.0",
"laminas/laminas-validator": "^2.28.0",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.3.0",
"phpunit/phpunit": "^9.5.27",
"laminas/laminas-validator": "^2.39.0",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-phpunit": "^1.3.15",
"phpunit/phpunit": "^9.6.13",
"slam/php-cs-fixer-extensions": "^v3.2.1",
"slam/php-debug-r": "^v1.7.0"
},
Expand Down
6 changes: 6 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>Slamdunk/.github:renovate-config"
]
}
28 changes: 14 additions & 14 deletions src/Rules/Laminas/ServiceManagerGetMethodCallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use ReflectionClass;

Expand All @@ -27,8 +27,7 @@ final class ServiceManagerGetMethodCallRule implements Rule
public function __construct(
private ReflectionProvider $reflectionProvider,
private ServiceManagerLoader $serviceManagerLoader
) {
}
) {}

public function getNodeType(): string
{
Expand All @@ -51,13 +50,14 @@ public function processNode(Node $node, Scope $scope): array
if (! $firstArg instanceof Arg) {
return [];
}
$argType = $scope->getType($firstArg->value);
if (! $argType instanceof ConstantStringType) {
$argType = $scope->getType($firstArg->value);
$constantStrings = $argType->getConstantStrings();
if (1 !== \count($constantStrings)) {
return [];
}

$calledOnType = $scope->getType($node->var);
if (! $calledOnType instanceof ObjectType || ! $this->isTypeInstanceOfContainer($calledOnType)) {
if (! $calledOnType->isObject()->yes() || ! $this->isTypeInstanceOfContainer($calledOnType)) {
return [];
}

Expand All @@ -71,7 +71,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$serviceName = $argType->getValue();
$serviceName = $constantStrings[0]->getValue();
$serviceManager = $this->serviceManagerLoader->getServiceLocator($calledOnType->getClassName());

if ($serviceManager->has($serviceName)) {
Expand All @@ -80,9 +80,8 @@ public function processNode(Node $node, Scope $scope): array

$classDoesNotExistNote = '';
if ($serviceManager instanceof AbstractPluginManager) {
$refClass = new ReflectionClass($serviceManager);
$refProperty = $refClass->getProperty('autoAddInvokableClass');
$refProperty->setAccessible(true);
$refClass = new ReflectionClass($serviceManager);
$refProperty = $refClass->getProperty('autoAddInvokableClass');
$autoAddInvokableClass = $refProperty->getValue($serviceManager);
if ($autoAddInvokableClass) {
if ($this->reflectionProvider->hasClass($serviceName)) {
Expand All @@ -102,10 +101,11 @@ public function processNode(Node $node, Scope $scope): array
)];
}

private function isTypeInstanceOfContainer(ObjectType $type): bool
/** @phpstan-assert-if-true ObjectType $type */
private function isTypeInstanceOfContainer(Type $type): bool
{
return $type->isInstanceOf(ServiceLocatorInterface::class)->yes()
|| $type->isInstanceOf(InteropContainerInterface::class)->yes()
|| $type->isInstanceOf(PsrContainerInterface::class)->yes();
return (new ObjectType(ServiceLocatorInterface::class))->isSuperTypeOf($type)->yes()
|| (new ObjectType(InteropContainerInterface::class))->isSuperTypeOf($type)->yes()
|| (new ObjectType(PsrContainerInterface::class))->isSuperTypeOf($type)->yes();
}
}
8 changes: 2 additions & 6 deletions src/ServiceManagerLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ final class ServiceManagerLoader
{
private ?UnmappedAliasServiceLocatorProxy $serviceLocator = null;

/**
* @var string[]
*/
/** @var string[] */
private array $knownModules = [
\Laminas\Cache\ConfigProvider::class,
\Laminas\Filter\ConfigProvider::class,
Expand All @@ -33,9 +31,7 @@ final class ServiceManagerLoader
\Laminas\Validator\ConfigProvider::class,
];

/**
* @var array<string, true>
*/
/** @var array<string, true> */
private array $serviceManagerNames = [
ServiceManager::class => true,
ServiceLocatorInterface::class => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
Expand All @@ -24,8 +23,7 @@ abstract class AbstractServiceLocatorGetDynamicReturnTypeExtension implements Dy
public function __construct(
private ReflectionProvider $reflectionProvider,
private ServiceManagerLoader $serviceManagerLoader
) {
}
) {}

final public function isMethodSupported(MethodReflection $methodReflection): bool
{
Expand All @@ -38,7 +36,7 @@ final public function getTypeFromMethodCall(
Scope $scope
): Type {
$calledOnType = $scope->getType($methodCall->var);
if (! $calledOnType instanceof ObjectType) {
if (! $calledOnType->isObject()->yes()) {
return new MixedType();
}

Expand All @@ -47,7 +45,7 @@ final public function getTypeFromMethodCall(
return new MixedType();
}

$serviceManager = $this->serviceManagerLoader->getServiceLocator($calledOnType->getClassName());
$serviceManager = $this->serviceManagerLoader->getServiceLocator($calledOnType->getObjectClassNames()[0]);

$firstArg = $args[0];
if (! $firstArg instanceof Arg) {
Expand All @@ -58,12 +56,12 @@ final public function getTypeFromMethodCall(
$firstArg->getType()
));
}
$argType = $scope->getType($firstArg->value);
if (! $argType instanceof ConstantStringType) {
$argType = $scope->getType($firstArg->value);
$constantStringTypes = $argType->getConstantStrings();
if (1 !== \count($constantStringTypes)) {
if ($serviceManager instanceof AbstractPluginManager) {
$refClass = new ReflectionClass($serviceManager);
$refProperty = $refClass->getProperty('instanceOf');
$refProperty->setAccessible(true);
$refClass = new ReflectionClass($serviceManager);
$refProperty = $refClass->getProperty('instanceOf');
$returnedInstance = $refProperty->getValue($serviceManager);
\assert(null === $returnedInstance || \is_string($returnedInstance));
if (null !== $returnedInstance && $this->reflectionProvider->hasClass($returnedInstance)) {
Expand All @@ -74,7 +72,7 @@ final public function getTypeFromMethodCall(
return new MixedType();
}

$serviceName = $argType->getValue();
$serviceName = $constantStringTypes[0]->getValue();
if (! $serviceManager->has($serviceName)) {
return new NeverType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ final class ControllerPluginClassReflectionExtension implements MethodsClassRefl
public function __construct(
private ReflectionProvider $reflectionProvider,
private ServiceManagerLoader $serviceManagerLoader
) {
}
) {}

public function hasMethod(ClassReflection $classReflection, string $methodName): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;
use PHPStan\Type\VerbosityLevel;

abstract class AbstractPluginMethodDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
Expand Down Expand Up @@ -46,7 +44,7 @@ final public function getTypeFromMethodCall(
));
}
$argType = $scope->getType($firstArg->value);
$strings = TypeUtils::getConstantStrings($argType);
$strings = $argType->getConstantStrings();
$plugin = 1 === \count($strings) ? $strings[0]->getValue() : null;

if (null !== $plugin) {
Expand All @@ -58,7 +56,7 @@ final public function getTypeFromMethodCall(
return new ObjectType($pluginInstance::class);
}

if ($argType instanceof StringType) {
if ($argType->isString()->yes()) {
return ParametersAcceptorSelector::selectFromArgs($scope, $methodCall->getArgs(), $methodReflection->getVariants())->getReturnType();
}

Expand Down
4 changes: 1 addition & 3 deletions src/Type/Laminas/PluginMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public function hasSideEffects(): TrinaryLogic
return TrinaryLogic::createNo();
}

/**
* @return \PHPStan\Reflection\ParametersAcceptor[]
*/
/** @return \PHPStan\Reflection\ParametersAcceptor[] */
public function getVariants(): array
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ abstract class AbstractServiceGetterDynamicReturnTypeExtension implements Dynami
{
private ServiceManagerLoader $serviceManagerLoader;

/**
* @var array<string, string>
*/
/** @var array<string, string> */
protected array $methodToServiceMap = [
'getApplication' => 'Application',
'getRenderer' => RendererInterface::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

final class ViewHelperGetterDynamicReturnTypeExtension extends AbstractServiceGetterDynamicReturnTypeExtension
{
/**
* @var array<string, string>
*/
/** @var array<string, string> */
protected array $methodToServiceMap = [
'getView' => RendererInterface::class,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function __construct(
private ClassReflection $classReflection,
private string $propertyName,
private string $setterName
) {
}
) {}

public function getDeclaringClass(): ClassReflection
{
Expand Down
4 changes: 1 addition & 3 deletions src/UnmappedAliasServiceLocatorProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ final class UnmappedAliasServiceLocatorProxy implements ServiceLocatorInterface
{
private ServiceLocatorInterface $serviceLocator;

/**
* @var array<string, string>
*/
/** @var array<string, string> */
private array $knownUnmappedAliasToClassServices = [
ControllerManager::class => 'ControllerManager',
HelperPluginManager::class => 'ViewHelperManager',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
},
{
"message": "Call to an undefined method Laminas\\Http\\PhpEnvironment\\Request::getBasePattt().",
"line": 57,
"line": 58,
"ignorable": true
},
{
"message": "Call to an undefined method Laminas\\Http\\PhpEnvironment\\Response::headersSenttt().",
"line": 58,
"line": 59,
"ignorable": true
},
{
"message": "Call to an undefined method Laminas\\View\\Renderer\\PhpRenderer::getEngineee().",
"line": 59,
"line": 60,
"ignorable": true
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
{
"message": "Method LaminasPhpStan\\Tests\\LaminasIntegration\\data\\controllerRequestResponseDynamicReturn::baz() is unused.",
"line": 55,
"line": 56,
"ignorable": true
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ private function bar(View $view): void
$view->getResponse()->getStatusCode();
}

/** @param ViewEvent<string> $viewEvent */
private function baz(ViewEvent $viewEvent): void
{
$viewEvent->getRequest()->getBasePattt();
Expand Down
2 changes: 1 addition & 1 deletion tests/LaminasIntegration/data/routePluginMethod-0.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"message": "The service \"foobar123\" was not configured in Laminas\\Router\\RoutePluginManager nor the class \"foobar123\" exists.",
"line": 27,
"line": 25,
"ignorable": true
}
]
2 changes: 1 addition & 1 deletion tests/LaminasIntegration/data/routePluginMethod-2.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"message": "Call to an undefined method Laminas\\Router\\RouteInterface::foobar456().",
"line": 30,
"line": 28,
"ignorable": true
}
]
Loading

0 comments on commit 1df5ece

Please sign in to comment.