Skip to content

Commit 39894fc

Browse files
bullderMichael Garifullin
andauthored
add php stan (#86)
* fix: use phpstan + fix M6WebStatsdBundle for Symfony 6 Co-authored-by: Michael Garifullin <michael.garifullin@smartbox.com>
1 parent 5d009fe commit 39894fc

24 files changed

Lines changed: 85 additions & 40 deletions

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ jobs:
3939
run: composer update --prefer-dist --no-interaction
4040
- name: Code style check
4141
run: bin/php-cs-fixer fix --dry-run --using-cache=no --verbose
42+
- name: Static analysis
43+
run: bin/phpstan analyse
4244
- name: Unit tests
4345
run: bin/atoum

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"require-dev": {
3131
"atoum/atoum": "^3.4 || ^4.0",
3232
"m6web/php-cs-fixer-config": "^2.0",
33+
"phpstan/phpstan": "^1.3",
3334
"symfony/console": "^4.4 || ^5.0 || ^6.0",
3435
"symfony/http-foundation": "^4.4 || ^5.0 || ^6.0"
3536
},

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 5
3+
paths:
4+
- src
5+
excludePaths:
6+
- src/Tests
7+
treatPhpDocTypesAsCertain: false

src/Client/Client.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace M6Web\Bundle\StatsdBundle\Client;
46

57
use M6Web\Bundle\StatsdBundle\Statsd\MonitorableEventInterface;
68
use M6Web\Component\Statsd\Client as BaseClient;
7-
use Symfony\Component\PropertyAccess;
9+
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
10+
use Symfony\Contracts\EventDispatcher\Event;
811

912
/**
1013
* Class that extends base statsd client, to handle auto-increment from event dispatcher notifications
@@ -14,7 +17,7 @@ class Client extends BaseClient
1417
/** @var array */
1518
protected $listenedEvents = [];
1619

17-
/** @var PropertyAccess\PropertyAccessorInterface */
20+
/** @var PropertyAccessorInterface */
1821
protected $propertyAccessor;
1922

2023
/** @var int|null */
@@ -60,7 +63,7 @@ public function setToSendLimit($toSendLimit)
6063
*
6164
* @return $this
6265
*/
63-
public function setPropertyAccessor(PropertyAccess\PropertyAccessorInterface $propertyAccessor)
66+
public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor)
6467
{
6568
$this->propertyAccessor = $propertyAccessor;
6669

@@ -70,20 +73,15 @@ public function setPropertyAccessor(PropertyAccess\PropertyAccessorInterface $pr
7073
/**
7174
* Handle an event
7275
*
73-
* @param EventInterface $event an event
74-
* @param string $name the event name
76+
* @param Event $event an event
77+
* @param string $name the event name
7578
*
7679
* @throws Exception
7780
*
7881
* @return void
7982
*/
8083
public function handleEvent($event, $name = null)
8184
{
82-
// this is used to stay compatible with Symfony 2.3
83-
if (is_null($name)) {
84-
$name = $event->getName();
85-
}
86-
8785
if (!isset($this->listenedEvents[$name])) {
8886
return;
8987
}
@@ -125,7 +123,7 @@ public function handleEvent($event, $name = null)
125123
}
126124
}
127125

128-
if (null !== $this->toSendLimit && $this->getToSend()->count() >= $this->toSendLimit) {
126+
if (null !== $this->toSendLimit && count($this->getToSend()) >= $this->toSendLimit) {
129127
$immediateSend = true;
130128
}
131129

@@ -175,9 +173,9 @@ private function addTiming($event, $timingMethod, $node, $tags = [])
175173
/**
176174
* Replaces a string with a method name
177175
*
178-
* @param EventInterface $event An event
179-
* @param string $eventName The name of the event
180-
* @param string $string The node in which the replacing will happen
176+
* @param Event $event An event
177+
* @param string $eventName The name of the event
178+
* @param string $string The node in which the replacing will happen
181179
*
182180
* @return string
183181
*/

src/Client/Exception.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace M6Web\Bundle\StatsdBundle\Client;
46

57
/**

src/DataCollector/StatsdDataCollector.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace M6Web\Bundle\StatsdBundle\DataCollector;
46

57
use Symfony\Component\HttpFoundation\Request;
68
use Symfony\Component\HttpFoundation\Response;
79
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
10+
use Symfony\Component\HttpKernel\Event\KernelEvent;
811
use Symfony\Component\HttpKernel\HttpKernelInterface;
12+
use Symfony\Contracts\EventDispatcher\Event;
913

1014
/**
1115
* Handle datacollector for statsd
@@ -37,11 +41,11 @@ public function reset()
3741
/**
3842
* Kernel event
3943
*
40-
* @param EventInterface $event The received event
44+
* @param Event $event The received event
4145
*/
4246
public function onKernelResponse($event)
4347
{
44-
if (HttpKernelInterface::MASTER_REQUEST == $event->getRequestType()) {
48+
if ($event instanceof KernelEvent && HttpKernelInterface::MASTER_REQUEST == $event->getRequestType()) {
4549
foreach ($this->statsdClients as $clientName => $client) {
4650
$clientInfo = [
4751
'name' => $clientName,

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace M6Web\Bundle\StatsdBundle\DependencyInjection;
46

57
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

src/DependencyInjection/M6WebStatsdExtension.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace M6Web\Bundle\StatsdBundle\DependencyInjection;
46

57
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
68
use Symfony\Component\Config\FileLocator;
79
use Symfony\Component\DependencyInjection\ContainerBuilder;
8-
use Symfony\Component\DependencyInjection\ContainerInterface;
910
use Symfony\Component\DependencyInjection\Definition;
1011
use Symfony\Component\DependencyInjection\Loader;
1112
use Symfony\Component\DependencyInjection\Reference;
@@ -94,11 +95,11 @@ public function load(array $configs, ContainerBuilder $container)
9495
/**
9596
* Load a client configuration as a service in the container. A client can use multiple servers
9697
*
97-
* @param ContainerInterface $container The container
98-
* @param string $alias Alias of the client
99-
* @param array $config Base config of the client
100-
* @param array $servers List of available servers as describe in the config file
101-
* @param bool $baseEvents Register base events
98+
* @param ContainerBuilder $container The container
99+
* @param string $alias Alias of the client
100+
* @param array $config Base config of the client
101+
* @param array $servers List of available servers as describe in the config file
102+
* @param bool $baseEvents Register base events
102103
*
103104
* @throws InvalidConfigurationException
104105
*

src/Event/ConsoleCommandEvent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace M6Web\Bundle\StatsdBundle\Event;
46

57
use Symfony\Component\Console\Event\ConsoleCommandEvent as BaseEvent;

src/Event/ConsoleErrorEvent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace M6Web\Bundle\StatsdBundle\Event;
46

57
use Symfony\Component\Console\Event\ConsoleErrorEvent as BaseEvent;

0 commit comments

Comments
 (0)