Skip to content

Commit 9ff44ce

Browse files
authored
Merge pull request #468 from yguedidi/add-phpstan
Add PHPStan
2 parents 299d533 + 252bd9b commit 9ff44ce

File tree

13 files changed

+107
-41
lines changed

13 files changed

+107
-41
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ jobs:
1515
- name: Validate composer.json
1616
run: composer validate --strict --no-check-lock
1717

18+
static_analysis:
19+
name: Static analysis
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: shivammathur/setup-php@v2
25+
with:
26+
coverage: none
27+
php-version: '8.2'
28+
29+
- name: Install dependencies
30+
run: composer update --ansi --no-progress --prefer-dist --no-interaction
31+
32+
- name: Install PHPUnit
33+
run: vendor/bin/simple-phpunit install
34+
35+
- run: vendor/bin/phpstan analyze
36+
1837
tests:
1938
name: "Tests on PHP ${{ matrix.php }}${{ matrix.name_suffix }}"
2039
runs-on: ubuntu-latest

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
"gedmo/doctrine-extensions": "^3.5.0"
2222
},
2323
"require-dev": {
24+
"phpstan/phpstan": "^1.10",
25+
"phpstan/phpstan-deprecation-rules": "^1.1",
26+
"phpstan/phpstan-phpunit": "^1.3",
27+
"phpstan/phpstan-strict-rules": "^1.5",
28+
"phpstan/phpstan-symfony": "^1.3",
2429
"symfony/mime": "^5.4 || ^6.0 || ^7.0",
2530
"symfony/phpunit-bridge": "^v6.4.1 || ^7.0.1",
2631
"symfony/security-core": "^5.4 || ^6.0 || ^7.0"
@@ -40,5 +45,8 @@
4045
"branch-alias": {
4146
"dev-main": "1.x-dev"
4247
}
48+
},
49+
"config": {
50+
"sort-packages": true
4351
}
4452
}

phpstan.neon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- src/
5+
- tests/
6+
7+
includes:
8+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
9+
- vendor/phpstan/phpstan-phpunit/extension.neon
10+
- vendor/phpstan/phpstan-phpunit/rules.neon
11+
- vendor/phpstan/phpstan-strict-rules/rules.neon
12+
- vendor/phpstan/phpstan-symfony/extension.neon
13+
- vendor/phpstan/phpstan-symfony/rules.neon

src/DependencyInjection/Compiler/ValidateExtensionConfigurationPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Stof\DoctrineExtensionsBundle\DependencyInjection\Compiler;
44

5+
use Stof\DoctrineExtensionsBundle\DependencyInjection\StofDoctrineExtensionsExtension;
56
use Symfony\Component\DependencyInjection\ContainerBuilder;
67
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
78

@@ -23,6 +24,9 @@ class ValidateExtensionConfigurationPass implements CompilerPassInterface
2324
*/
2425
public function process(ContainerBuilder $container)
2526
{
26-
$container->getExtension('stof_doctrine_extensions')->configValidate($container);
27+
$extension = $container->getExtension('stof_doctrine_extensions');
28+
\assert($extension instanceof StofDoctrineExtensionsExtension);
29+
30+
$extension->configValidate($container);
2731
}
2832
}

src/DependencyInjection/StofDoctrineExtensionsExtension.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ class StofDoctrineExtensionsExtension extends Extension
8181
),
8282
);
8383

84+
/** @var list<string> */
8485
private $entityManagers = array();
86+
/** @var list<string> */
8587
private $documentManagers = array();
8688

8789
/**
@@ -150,7 +152,7 @@ public function load(array $configs, ContainerBuilder $container)
150152
/**
151153
* @internal
152154
*/
153-
public function configValidate(ContainerBuilder $container)
155+
public function configValidate(ContainerBuilder $container): void
154156
{
155157
foreach ($this->entityManagers as $name) {
156158
if (!$container->hasDefinition(sprintf('doctrine.dbal.%s_connection', $name))) {
@@ -166,13 +168,13 @@ public function configValidate(ContainerBuilder $container)
166168
}
167169

168170
/**
169-
* @param array $configs
170-
* @param ContainerBuilder $container
171-
* @param LoaderInterface $loader
172-
* @param array $loaded
173-
* @param string $doctrineListenerTag
171+
* @param array<string, array<string, bool>> $configs
172+
* @param ContainerBuilder $container
173+
* @param LoaderInterface $loader
174+
* @param array<string, true> $loaded
175+
* @param string $doctrineListenerTag
174176
*
175-
* @return array
177+
* @return list<string>
176178
*/
177179
private function processObjectManagerConfigurations(array $configs, ContainerBuilder $container, LoaderInterface $loader, array &$loaded, string $doctrineListenerTag)
178180
{

src/EventListener/BlameListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
*/
1919
class BlameListener implements EventSubscriberInterface
2020
{
21+
/** @var AuthorizationCheckerInterface|null */
2122
private $authorizationChecker;
23+
/** @var TokenStorageInterface|null */
2224
private $tokenStorage;
25+
/** @var BlameableListener */
2326
private $blameableListener;
2427

2528
public function __construct(BlameableListener $blameableListener, TokenStorageInterface $tokenStorage = null, AuthorizationCheckerInterface $authorizationChecker = null)
@@ -32,7 +35,7 @@ public function __construct(BlameableListener $blameableListener, TokenStorageIn
3235
/**
3336
* @internal
3437
*/
35-
public function onKernelRequest(RequestEvent $event)
38+
public function onKernelRequest(RequestEvent $event): void
3639
{
3740
if (!$event->isMainRequest()) {
3841
return;
@@ -48,9 +51,6 @@ public function onKernelRequest(RequestEvent $event)
4851
}
4952
}
5053

51-
/**
52-
* @return string[]
53-
*/
5454
public static function getSubscribedEvents()
5555
{
5656
return array(

src/EventListener/IpTraceListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
*/
1414
final class IpTraceListener implements EventSubscriberInterface
1515
{
16+
/** @var IpTraceableListener */
1617
private $ipTraceableListener;
1718

1819
public function __construct(IpTraceableListener $ipTraceableListener)
1920
{
2021
$this->ipTraceableListener = $ipTraceableListener;
2122
}
2223

23-
public function onKernelRequest(RequestEvent $event)
24+
public function onKernelRequest(RequestEvent $event): void
2425
{
2526
if (!$event->isMainRequest()) {
2627
return;

src/EventListener/LocaleListener.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
class LocaleListener implements EventSubscriberInterface
1616
{
17+
/** @var TranslatableListener */
1718
private $translatableListener;
1819

1920
public function __construct(TranslatableListener $translatableListener)
@@ -24,14 +25,11 @@ public function __construct(TranslatableListener $translatableListener)
2425
/**
2526
* @internal
2627
*/
27-
public function onKernelRequest(RequestEvent $event)
28+
public function onKernelRequest(RequestEvent $event): void
2829
{
2930
$this->translatableListener->setTranslatableLocale($event->getRequest()->getLocale());
3031
}
3132

32-
/**
33-
* @return string[]
34-
*/
3533
public static function getSubscribedEvents()
3634
{
3735
return array(

src/EventListener/LoggerListener.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Stof\DoctrineExtensionsBundle\EventListener;
44

5+
use Gedmo\Loggable\Loggable;
56
use Gedmo\Loggable\LoggableListener;
67
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
78
use Symfony\Component\HttpKernel\Event\RequestEvent;
@@ -14,13 +15,21 @@
1415
* Sets the username from the security context by listening on kernel.request
1516
*
1617
* @author Christophe Coevoet <[email protected]>
18+
*
19+
* @phpstan-template T of Loggable|object
1720
*/
1821
class LoggerListener implements EventSubscriberInterface
1922
{
23+
/** @var AuthorizationCheckerInterface|null */
2024
private $authorizationChecker;
25+
/** @var TokenStorageInterface|null */
2126
private $tokenStorage;
27+
/** @var LoggableListener<T> */
2228
private $loggableListener;
2329

30+
/**
31+
* @param LoggableListener<T> $loggableListener
32+
*/
2433
public function __construct(LoggableListener $loggableListener, TokenStorageInterface $tokenStorage = null, AuthorizationCheckerInterface $authorizationChecker = null)
2534
{
2635
$this->loggableListener = $loggableListener;
@@ -31,7 +40,7 @@ public function __construct(LoggableListener $loggableListener, TokenStorageInte
3140
/**
3241
* @internal
3342
*/
34-
public function onKernelRequest(RequestEvent $event)
43+
public function onKernelRequest(RequestEvent $event): void
3544
{
3645
if (!$event->isMainRequest()) {
3746
return;
@@ -48,9 +57,6 @@ public function onKernelRequest(RequestEvent $event)
4857
}
4958
}
5059

51-
/**
52-
* @return string[]
53-
*/
5460
public static function getSubscribedEvents()
5561
{
5662
return array(

src/Uploadable/UploadableManager.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
namespace Stof\DoctrineExtensionsBundle\Uploadable;
44

55
use Symfony\Component\HttpFoundation\File\UploadedFile;
6+
use Gedmo\Uploadable\FileInfo\FileInfoInterface;
67
use Gedmo\Uploadable\UploadableListener;
78

89
class UploadableManager
910
{
1011
/** @var \Gedmo\Uploadable\UploadableListener */
1112
private $listener;
13+
/** @var class-string<FileInfoInterface> */
1214
private $fileInfoClass;
1315

16+
/**
17+
* @param UploadableListener $listener
18+
* @param class-string<FileInfoInterface> $fileInfoClass
19+
*/
1420
public function __construct(UploadableListener $listener, $fileInfoClass)
1521
{
1622
$this->listener = $listener;
@@ -24,6 +30,8 @@ public function __construct(UploadableListener $listener, $fileInfoClass)
2430
*
2531
* @param object $entity - The entity you are marking to "Upload" as soon as you call "flush".
2632
* @param mixed $fileInfo - The file info object or array. In Symfony, this will be typically an UploadedFile instance.
33+
*
34+
* @return void
2735
*/
2836
public function markEntityToUpload($entity, $fileInfo)
2937
{

0 commit comments

Comments
 (0)