Skip to content

Commit

Permalink
Merge pull request #38 from gsteel/psalm-hack
Browse files Browse the repository at this point in the history
Refine types, reduce psalm baseline
  • Loading branch information
Ocramius committed Jan 12, 2023
2 parents a80fb92 + 89e4d29 commit a30bb05
Show file tree
Hide file tree
Showing 32 changed files with 225 additions and 494 deletions.
2 changes: 0 additions & 2 deletions .coveralls.yml

This file was deleted.

7 changes: 5 additions & 2 deletions .gitattributes
@@ -1,9 +1,12 @@
/.coveralls.yml export-ignore
/.docheader export-ignore
/.gitattributes export-ignore
/.github/ export-ignore
/.gitignore export-ignore
/docs/ export-ignore
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/psalm.xml export-ignore
/psalm-baseline.xml export-ignore
/test/ export-ignore
.psr-container.php.stub export-ignore
composer.lock export-ignore
renovate.json export-ignore
24 changes: 24 additions & 0 deletions .psr-container.php.stub
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Psr\Container {
/**
* Provides automatic type inference for Psalm when retrieving a service from a container using a FQCN
*/
interface ContainerInterface
{
/**
* @param string|class-string $id
* @return bool
*/
public function has(string $id);

/**
* @template T
* @psalm-param string|class-string<T> $id
* @psalm-return ($id is class-string ? T : mixed)
*/
public function get(string $id);
}
}
15 changes: 8 additions & 7 deletions README.md
@@ -1,21 +1,22 @@
# mezzio-router

[![Build Status](https://github.com/mezzio/mezzio-router/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/mezzio/mezzio-router/actions/workflows/continuous-integration.yml)
[![Type Coverage](https://shepherd.dev/github/mezzio/mezzio-router/coverage.svg)](https://shepherd.dev/github/mezzio/mezzio-router)

> ## 🇷🇺 Русским гражданам
>
>
> Мы, участники Laminas, родились и живем в разных странах. У многих из нас есть друзья, родственники и коллеги как в России, так и в Украине. Некоторые из нас родились в России. Некоторые из нас живут в России. У некоторых бабушки и дедушки сражались с фашистами во Второй мировой войне. Здесь никто не поддерживает фашизм.
>
>
> У одного из нас есть украинская родственница, которая спаслась из дома вместе с сыном. Поезд задержался из-за бомбежки на дороге впереди. У нас есть друзья, которые прячутся в бомбоубежищах. Мы с тревогой ждем весточки от них после воздушных налетов, которые беспорядочно наносят удары и попадают по больницам, школам, детским садам и домам. Мы не берем это из каких-либо СМИ. Мы наблюдаем это напрямую.
>
>
> Вы доверяете нам достаточно, чтоб использовать наши программы, и мы просим вас довериться нам вновь. Мы нуждаемся в помощи. Выходите и протестуйте против этой бесполезной войны. Остановите кровопролитие. Скажите "Нет войне!"
>
>
> ## 🇺🇸 To Citizens of Russia
>
>
> We at Laminas come from all over the world. Many of us have friends, family and colleagues in both Russia and Ukraine. Some of us were born in Russia. Some of us currently live in Russia. Some have grandparents who fought Nazis in World War II. Nobody here supports fascism.
>
>
> One team member has a Ukrainian relative who fled her home with her son. The train was delayed due to bombing on the road ahead. We have friends who are hiding in bomb shelters. We anxiously follow up on them after the air raids, which indiscriminately fire at hospitals, schools, kindergartens and houses. We're not taking this from any media. These are our actual experiences.
>
>
> You trust us enough to use our software. We ask that you trust us to say the truth on this. We need your help. Go out and protest this unnecessary war. Stop the bloodshed. Say "stop the war!"
Router subcomponent for [Mezzio](https://github.com/mezzio/mezzio).
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Expand Up @@ -49,11 +49,11 @@
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.5.0",
"laminas/laminas-diactoros": "^2.20.0",
"laminas/laminas-diactoros": "^2.24",
"laminas/laminas-stratigility": "^3.9.0",
"phpunit/phpunit": "^9.5.26",
"psalm/plugin-phpunit": "^0.18.0",
"vimeo/psalm": "^5.0.0"
"phpunit/phpunit": "^9.5.27",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.4"
},
"suggest": {
"mezzio/mezzio-aurarouter": "^3.0 to use the Aura.Router routing adapter",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

216 changes: 7 additions & 209 deletions psalm-baseline.xml
@@ -1,220 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.28.0@52e96bea381e6cb07a672aefec791a5817694a26">
<file src="src/ConfigProvider.php">
<MixedArrayOffset occurrences="1"/>
<UndefinedClass occurrences="6">
<code>\Zend\Expressive\Router\Middleware\DispatchMiddleware</code>
<code>\Zend\Expressive\Router\Middleware\ImplicitHeadMiddleware</code>
<code>\Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware</code>
<code>\Zend\Expressive\Router\Middleware\MethodNotAllowedMiddleware</code>
<code>\Zend\Expressive\Router\Middleware\RouteMiddleware</code>
<code>\Zend\Expressive\Router\RouteCollector</code>
</UndefinedClass>
</file>
<file src="src/Middleware/DispatchMiddleware.php">
<MixedAssignment occurrences="1">
<code>$routeResult</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="1">
<code>ResponseInterface</code>
</MixedInferredReturnType>
<MixedMethodCall occurrences="1">
<code>process</code>
</MixedMethodCall>
<MixedReturnStatement occurrences="1">
<code>$routeResult-&gt;process($request, $handler)</code>
</MixedReturnStatement>
</file>
<file src="src/Middleware/ImplicitHeadMiddleware.php">
<MixedArgument occurrences="1">
<code>ZendExpressiveRouteResult::class</code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="1">
<code>$param</code>
</MixedArgumentTypeCoercion>
<MixedAssignment occurrences="2">
<code>$result</code>
<code>$value</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="1">
<code>StreamInterface</code>
</MixedInferredReturnType>
<MixedMethodCall occurrences="1">
<code>getMatchedRoute</code>
</MixedMethodCall>
<MixedReturnStatement occurrences="1">
<code>$streamFactory()</code>
</MixedReturnStatement>
<UndefinedClass occurrences="1">
<code>ZendExpressiveRouteResult</code>
</UndefinedClass>
</file>
<files psalm-version="5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863">
<file src="src/Middleware/ImplicitHeadMiddlewareFactory.php">
<MixedArgument occurrences="4">
<InvalidArgument occurrences="1">
<code>$container-&gt;get(StreamInterface::class)</code>
<code>ZendExpressiveRouterInterface::class</code>
<code>ZendExpressiveRouterInterface::class</code>
</MixedArgument>
<UndefinedClass occurrences="2">
<code>ZendExpressiveRouterInterface</code>
<code>ZendExpressiveRouterInterface</code>
</UndefinedClass>
</file>
<file src="src/Middleware/ImplicitOptionsMiddleware.php">
<MixedArgument occurrences="1">
<code>$allowedMethods</code>
</MixedArgument>
<MixedAssignment occurrences="2">
<code>$allowedMethods</code>
<code>$result</code>
</MixedAssignment>
<MixedMethodCall occurrences="4">
<code>getAllowedMethods</code>
<code>getMatchedRoute</code>
<code>isFailure</code>
<code>isMethodFailure</code>
</MixedMethodCall>
</file>
<file src="src/Middleware/MethodNotAllowedMiddleware.php">
<MixedArgument occurrences="1">
<code>$routeResult-&gt;getAllowedMethods()</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$routeResult</code>
</MixedAssignment>
<MixedMethodCall occurrences="2">
<code>getAllowedMethods</code>
<code>isMethodFailure</code>
</MixedMethodCall>
</file>
<file src="src/Middleware/RouteMiddleware.php">
<MixedArgument occurrences="1">
<code>ZendExpressiveRouteResult::class</code>
</MixedArgument>
<MixedArgumentTypeCoercion occurrences="1">
<code>$param</code>
</MixedArgumentTypeCoercion>
<MixedAssignment occurrences="1">
<code>$value</code>
</MixedAssignment>
<UndefinedClass occurrences="1">
<code>ZendExpressiveRouteResult</code>
</UndefinedClass>
</file>
<file src="src/Middleware/RouteMiddlewareFactory.php">
<MixedArgument occurrences="2">
<code>$container-&gt;get($this-&gt;routerServiceName)</code>
<code>$data['routerServiceName'] ?? RouterInterface::class</code>
</MixedArgument>
</file>
<file src="src/Route.php">
<PossiblyNullArgument occurrences="1">
<code>$this-&gt;methods</code>
</PossiblyNullArgument>
</file>
<file src="src/RouteCollector.php">
<MixedArgumentTypeCoercion occurrences="1">
<code>$methods</code>
</MixedArgumentTypeCoercion>
</InvalidArgument>
</file>
<file src="src/RouteCollectorFactory.php">
<MixedArgument occurrences="3">
<code>ZendExpressiveRouterInterface::class</code>
<code>ZendExpressiveRouterInterface::class</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$config</code>
</MixedAssignment>
<UndefinedClass occurrences="2">
<code>ZendExpressiveRouterInterface</code>
<code>ZendExpressiveRouterInterface</code>
</UndefinedClass>
</file>
<file src="src/RouteResult.php">
<MixedPropertyTypeCoercion occurrences="1">
<code>$methods</code>
</MixedPropertyTypeCoercion>
<PossiblyFalseReference occurrences="1">
<code>process</code>
</PossiblyFalseReference>
<PossiblyNullReference occurrences="1">
<code>process</code>
</PossiblyNullReference>
<PropertyNotSetInConstructor occurrences="2">
<code>$matchedRouteName</code>
<code>$success</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Test/AbstractImplicitMethodsIntegrationTest.php">
<MixedAssignment occurrences="1">
<code>$value</code>
</MixedAssignment>
</file>
<file src="test/ConfigProviderTest.php">
<MixedArrayOffset occurrences="1"/>
<UndefinedClass occurrences="6">
<code>\Zend\Expressive\Router\Middleware\DispatchMiddleware</code>
<code>\Zend\Expressive\Router\Middleware\ImplicitHeadMiddleware</code>
<code>\Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware</code>
<code>\Zend\Expressive\Router\Middleware\MethodNotAllowedMiddleware</code>
<code>\Zend\Expressive\Router\Middleware\RouteMiddleware</code>
<code>\Zend\Expressive\Router\RouteCollector</code>
</UndefinedClass>
</file>
<file src="test/Middleware/ImplicitHeadMiddlewareFactoryTest.php">
<UndefinedClass occurrences="1">
<code>ZendExpressiveRouterInterface</code>
</UndefinedClass>
</file>
<file src="test/Middleware/ImplicitHeadMiddlewareTest.php">
<UndefinedClass occurrences="2">
<code>ZendExpressiveRouteResult</code>
<code>ZendExpressiveRouteResult</code>
</UndefinedClass>
</file>
<file src="test/Middleware/RouteMiddlewareFactoryTest.php">
<MixedArgument occurrences="1">
<code>Router::class</code>
</MixedArgument>
<UndefinedClass occurrences="5">
<code>Router</code>
<code>Router</code>
<code>Router</code>
<code>Router</code>
<code>Router</code>
</UndefinedClass>
</file>
<file src="test/Middleware/RouteMiddlewareTest.php">
<UndefinedClass occurrences="3">
<code>ZendExpressiveRouteResult</code>
<code>ZendExpressiveRouteResult</code>
<code>ZendExpressiveRouteResult</code>
</UndefinedClass>
<file src="test/InMemoryContainer.php">
<MixedReturnStatement occurrences="1">
<code>$this-&gt;services[$id]</code>
</MixedReturnStatement>
</file>
<file src="test/Response/CallableResponseFactoryDecoratorTest.php">
<InternalMethod occurrences="1">
<code>new CallableResponseFactoryDecorator(fn (): ResponseInterface =&gt; $this-&gt;response)</code>
</InternalMethod>
</file>
<file src="test/RouteCollectorFactoryTest.php">
<UndefinedClass occurrences="1">
<code>ZendExpressiveRouterInterface</code>
</UndefinedClass>
</file>
<file src="test/RouteCollectorTest.php">
<MixedArgument occurrences="1">
<code>$path</code>
</MixedArgument>
<MixedInferredReturnType occurrences="1">
<code>mixed[]</code>
</MixedInferredReturnType>
</file>
<file src="test/RouteTest.php">
<MixedArgumentTypeCoercion occurrences="1">
<code>$invalidHttpMethods</code>
</MixedArgumentTypeCoercion>
<PossiblyInvalidArgument occurrences="1">
<code>testThrowsExceptionIfInvalidHttpMethodsAreProvided</code>
</PossiblyInvalidArgument>
</file>
</files>
8 changes: 3 additions & 5 deletions psalm.xml.dist → psalm.xml
Expand Up @@ -35,11 +35,6 @@
<referencedClass name="Mezzio\Router\Response\CallableResponseFactoryDecorator"/>
</errorLevel>
</DeprecatedClass>
<UndefinedClass>
<errorLevel type="suppress">
<referencedClass name="Mezzio\Container\ResponseFactoryFactory"/>
</errorLevel>
</UndefinedClass>
<DeprecatedTrait>
<errorLevel type="suppress">
<file name="src/Middleware/MethodNotAllowedMiddlewareFactory.php"/>
Expand All @@ -50,4 +45,7 @@
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
<stubs>
<file name=".psr-container.php.stub"/>
</stubs>
</psalm>
18 changes: 6 additions & 12 deletions src/ConfigProvider.php
Expand Up @@ -4,37 +4,31 @@

namespace Mezzio\Router;

/**
* @psalm-type DependencyConfig = array{factories: array<class-string, class-string>}
*/
class ConfigProvider
{
/** @return array{dependencies: DependencyConfig} */
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
];
}

/** @return DependencyConfig */
public function getDependencies(): array
{
// @codingStandardsIgnoreStart
return [
// Legacy Zend Framework aliases
'aliases' => [
\Zend\Expressive\Router\Middleware\DispatchMiddleware::class => Middleware\DispatchMiddleware::class,
\Zend\Expressive\Router\Middleware\ImplicitHeadMiddleware::class => Middleware\ImplicitHeadMiddleware::class,
\Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware::class => Middleware\ImplicitOptionsMiddleware::class,
\Zend\Expressive\Router\Middleware\MethodNotAllowedMiddleware::class => Middleware\MethodNotAllowedMiddleware::class,
\Zend\Expressive\Router\Middleware\RouteMiddleware::class => Middleware\RouteMiddleware::class,
\Zend\Expressive\Router\RouteCollector::class => RouteCollector::class,
],
'factories' => [
Middleware\DispatchMiddleware::class => Middleware\DispatchMiddlewareFactory::class,
Middleware\ImplicitHeadMiddleware::class => Middleware\ImplicitHeadMiddlewareFactory::class,
Middleware\ImplicitOptionsMiddleware::class => Middleware\ImplicitOptionsMiddlewareFactory::class,
Middleware\MethodNotAllowedMiddleware::class => Middleware\MethodNotAllowedMiddlewareFactory::class,
Middleware\RouteMiddleware::class => Middleware\RouteMiddlewareFactory::class,
RouteCollector::class => RouteCollectorFactory::class,
]
],
];
// @codingStandardsIgnoreEnd
}
}
2 changes: 1 addition & 1 deletion src/Middleware/DispatchMiddleware.php
Expand Up @@ -23,7 +23,7 @@ class DispatchMiddleware implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$routeResult = $request->getAttribute(RouteResult::class, false);
if (! $routeResult) {
if (! $routeResult instanceof RouteResult) {
return $handler->handle($request);
}

Expand Down

0 comments on commit a30bb05

Please sign in to comment.