Skip to content

Commit

Permalink
chore: add phpstan to CI (#622)
Browse files Browse the repository at this point in the history
* chore: add phpstan to CI & fix level-1 errors

* fix optional dependencies
  • Loading branch information
usu committed May 3, 2024
1 parent 31ae54c commit a850861
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 19 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/static.yml
@@ -0,0 +1,39 @@
name: Static analysis

on:
push:
branches:
- "*.x"
pull_request:

jobs:
phpstan-src:
name: PHPStan src
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Pull in optional dependencies
run: composer require --no-update jean-beru/fos-http-cache-cloudfront twig/twig symfony/console

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
with:
args: analyze --no-progress

phpstan-tests:
name: PHPStan tests
runs-on: ubuntu-latest
env:
REQUIRE_DEV: "true"

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: PHPStan
uses: docker://oskarstark/phpstan-ga
with:
args: analyze --no-progress -c phpstan.tests.neon.dist
26 changes: 19 additions & 7 deletions composer.json
Expand Up @@ -2,7 +2,14 @@
"name": "friendsofsymfony/http-cache-bundle",
"type": "symfony-bundle",
"description": "Set path based HTTP cache headers and send invalidation requests to your HTTP cache",
"keywords": [ "http", "caching", "purge", "invalidation", "varnish", "esi" ],
"keywords": [
"http",
"caching",
"purge",
"invalidation",
"varnish",
"esi"
],
"homepage": "https://github.com/FriendsOfSymfony/FOSHttpCacheBundle",
"license": "MIT",
"authors": [
Expand All @@ -23,9 +30,11 @@
"require": {
"php": "^8.1",
"friendsofsymfony/http-cache": "^2.15 || 3.x-dev",
"symfony/expression-language": "^6.4 || ^7.0",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0"
"symfony/http-kernel": "^6.4 || ^7.0",
"symfony/security-bundle": "^6.4 || ^7.0"
},
"require-dev": {
"php-http/guzzle7-adapter": "^0.1.1",
Expand All @@ -39,16 +48,18 @@
"symfony/console": "^6.4 || ^7.0",
"symfony/finder": "^6.4 || ^7.0",
"phpunit/phpunit": "^10.5",
"symfony/security-bundle": "^6.4 || ^7.0",
"symfony/twig-bundle": "^6.4 || ^7.0",
"twig/twig": "^v3.8",
"symfony/yaml": "^6.4 || ^7.0",
"symfony/css-selector": "^6.4 || ^7.0",
"symfony/expression-language": "^6.4 || ^7.0",
"symfony/monolog-bundle": "^3.0",
"symfony/routing": "^6.4 || ^7.0",
"matthiasnoback/symfony-config-test": "^4.3.0 || ^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0"
"matthiasnoback/symfony-dependency-injection-test": "^4.3.1 || ^5.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-symfony": "^1.3",
"phpstan/extension-installer": "^1.3",
"jean-beru/fos-http-cache-cloudfront": "^1.1"
},
"suggest": {
"jean-beru/fos-http-cache-cloudfront": "To use CloudFront proxy",
Expand All @@ -75,7 +86,8 @@
},
"config": {
"allow-plugins": {
"php-http/discovery": true
"php-http/discovery": true,
"phpstan/extension-installer": true
}
}
}
}
4 changes: 4 additions & 0 deletions phpstan.neon.dist
@@ -0,0 +1,4 @@
parameters:
level: 1
paths:
- src
6 changes: 6 additions & 0 deletions phpstan.tests.neon.dist
@@ -0,0 +1,6 @@
parameters:
level: 1
paths:
- tests
excludePaths:
- 'tests/Resources/Fixtures/config'
4 changes: 1 addition & 3 deletions src/EventListener/FlashMessageListener.php
Expand Up @@ -19,8 +19,6 @@
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

class_alias(ResponseEvent::class, 'FOS\HttpCacheBundle\EventListener\FlashMessageResponseEvent');

/**
* This event handler reads all flash messages and moves them into a cookie.
*
Expand Down Expand Up @@ -54,7 +52,7 @@ public static function getSubscribedEvents(): array
/**
* Moves flash messages from the session to a cookie inside a Response Kernel listener.
*/
public function onKernelResponse(FlashMessageResponseEvent $event): void
public function onKernelResponse(ResponseEvent $event): void
{
try {
$session = $event->getRequest()->getSession();
Expand Down
Expand Up @@ -12,10 +12,10 @@
namespace FOS\HttpCacheBundle\Security\Http\Logout;

use FOS\HttpCacheBundle\UserContextInvalidator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\EventListener\SessionLogoutListener;

final class ContextInvalidationSessionLogoutHandler extends SessionLogoutListener
final class ContextInvalidationSessionLogoutHandler implements EventSubscriberInterface
{
private UserContextInvalidator $invalidator;

Expand All @@ -28,8 +28,14 @@ public function onLogout(LogoutEvent $event): void
{
if ($event->getRequest()->hasSession()) {
$this->invalidator->invalidateContext($event->getRequest()->getSession()->getId());
$event->getRequest()->getSession()->invalidate();
}
}

parent::onLogout($event);
public static function getSubscribedEvents(): array
{
return [
LogoutEvent::class => 'onLogout',
];
}
}
8 changes: 2 additions & 6 deletions tests/Functional/SessionHelperTrait.php
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\KernelEvents;

/**
Expand All @@ -22,12 +21,9 @@ trait SessionHelperTrait
{
private function callInRequestContext(KernelBrowser $client, callable $callable)
{
$container = method_exists($this, 'getContainer') ? self::getContainer() : (property_exists($this, 'container') ? self::$container : $client->getContainer());
/** @var EventDispatcherInterface $eventDispatcher */
$eventDispatcher = Kernel::MAJOR_VERSION < 5
? $container->get(EventDispatcherInterface::class)
: self::$kernel->getContainer()->get('test.service_container')->get(EventDispatcherInterface::class)
;
$eventDispatcher = self::$kernel->getContainer()->get('test.service_container')->get(EventDispatcherInterface::class);

$wrappedCallable = function (RequestEvent $event) use (&$callable) {
try {
$callable($event);
Expand Down

0 comments on commit a850861

Please sign in to comment.