Skip to content

Commit

Permalink
bump phpstan level up to 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Garifullin committed Dec 7, 2023
1 parent 658a73e commit 1dd0b3b
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 49 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ jobs:
- 8.1
symfony-version:
- 4.4.*
- 5.3.*
- 5.4.*
include:
- php-version: 7.1
symfony-version: 4.4.*
- php-version: 8.1
symfony-version: 6.0.*
- php-version: 8.2
symfony-version: 5.4.*
- php-version: 8.2
symfony-version: 6.0.*

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ vendor/
bin/
.php-cs-fixer.cache
composer.lock
phpstan.neon
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"require-dev": {
"atoum/atoum": "^3.4 || ^4.0",
"m6web/php-cs-fixer-config": "2.1.0",
"phpstan/phpstan": "1.4.10",
"phpstan/phpstan": "^1.4.10",
"symfony/console": "^4.4 || ^5.0 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.0 || ^6.0"
},
Expand Down
102 changes: 102 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
parameters:
ignoreErrors:
-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Client\\\\Client\\:\\:addEventToListen\\(\\) has parameter \\$eventConfig with no value type specified in iterable type array\\.$#"
count: 1
path: src/Client/Client.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Client\\\\Client\\:\\:addTiming\\(\\) has parameter \\$tags with no value type specified in iterable type array\\.$#"
count: 1
path: src/Client/Client.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Client\\\\Client\\:\\:getEventValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/Client/Client.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Client\\\\Client\\:\\:getListenedEvents\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Client/Client.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Client\\\\Client\\:\\:mergeTags\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/Client/Client.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Client\\\\Client\\:\\:mergeTags\\(\\) has parameter \\$event with no type specified\\.$#"
count: 1
path: src/Client/Client.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Client\\\\Client\\:\\:mergeTags\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Client/Client.php

-
message: "#^Property M6Web\\\\Bundle\\\\StatsdBundle\\\\Client\\\\Client\\:\\:\\$listenedEvents type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Client/Client.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\DataCollector\\\\StatsdDataCollector\\:\\:getClients\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/DataCollector/StatsdDataCollector.php

-
message: "#^Property M6Web\\\\Bundle\\\\StatsdBundle\\\\DataCollector\\\\StatsdDataCollector\\:\\:\\$statsdClients type has no value type specified in iterable type array\\.$#"
count: 1
path: src/DataCollector/StatsdDataCollector.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
count: 2
path: src/DependencyInjection/Configuration.php

-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeParentInterface\\:\\:booleanNode\\(\\)\\.$#"
count: 1
path: src/DependencyInjection/Configuration.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\DependencyInjection\\\\M6WebStatsdExtension\\:\\:load\\(\\) has parameter \\$configs with no value type specified in iterable type array\\.$#"
count: 1
path: src/DependencyInjection/M6WebStatsdExtension.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\DependencyInjection\\\\M6WebStatsdExtension\\:\\:loadClient\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#"
count: 1
path: src/DependencyInjection/M6WebStatsdExtension.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\DependencyInjection\\\\M6WebStatsdExtension\\:\\:loadClient\\(\\) has parameter \\$servers with no value type specified in iterable type array\\.$#"
count: 1
path: src/DependencyInjection/M6WebStatsdExtension.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Event\\\\ConsoleEvent\\:\\:__call\\(\\) has no return type specified\\.$#"
count: 1
path: src/Event/ConsoleEvent.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Event\\\\ConsoleEvent\\:\\:__call\\(\\) has parameter \\$parameters with no value type specified in iterable type array\\.$#"
count: 1
path: src/Event/ConsoleEvent.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Statsd\\\\MonitorableEventInterface\\:\\:getValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/Statsd/MonitorableEventInterface.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Statsd\\\\StatsdEvent\\:\\:getTiming\\(\\) has no return type specified\\.$#"
count: 1
path: src/Statsd/StatsdEvent.php

-
message: "#^Method M6Web\\\\Bundle\\\\StatsdBundle\\\\Statsd\\\\StatsdEvent\\:\\:getValue\\(\\) has no return type specified\\.$#"
count: 1
path: src/Statsd/StatsdEvent.php

4 changes: 3 additions & 1 deletion phpstan.neon → phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
includes:
- phpstan-baseline.neon
parameters:
level: 5
level: 6
paths:
- src
excludePaths:
Expand Down
6 changes: 3 additions & 3 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getListenedEvents()
* @param string $eventName The event name to listen
* @param array $eventConfig The event handler configuration
*/
public function addEventToListen($eventName, $eventConfig)
public function addEventToListen($eventName, $eventConfig): void
{
$this->listenedEvents[$eventName] = $eventConfig;
}
Expand Down Expand Up @@ -160,7 +160,7 @@ private function getEventValue($event, $method)
*
* @throws Exception
*/
private function addTiming($event, $timingMethod, $node, $tags = [])
private function addTiming($event, $timingMethod, $node, $tags = []): void
{
$timing = $this->getEventValue($event, $timingMethod);
if ($timing > 0) {
Expand Down Expand Up @@ -200,7 +200,7 @@ private function replaceConfigPlaceholder($event, $eventName, $string)
*
* @return array of tags
*/
private function mergeTags($event, $config)
private function mergeTags($event, $config): array
{
$configTags = isset($config['tags']) ? $config['tags'] : [];

Expand Down
17 changes: 10 additions & 7 deletions src/DataCollector/StatsdDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
class StatsdDataCollector extends DataCollector
{
/** @var array */
private $statsdClients;

/**
Expand All @@ -29,7 +30,7 @@ public function __construct()
/**
* Reset the data collector to initial state
*/
public function reset()
public function reset(): void
{
$this->statsdClients = [];
$this->data = [
Expand All @@ -43,7 +44,7 @@ public function reset()
*
* @param Event $event The received event
*/
public function onKernelResponse($event)
public function onKernelResponse($event): void
{
if ($event instanceof KernelEvent && HttpKernelInterface::MASTER_REQUEST == $event->getRequestType()) {
foreach ($this->statsdClients as $clientName => $client) {
Expand Down Expand Up @@ -76,17 +77,19 @@ public function onKernelResponse($event)
* @param string $clientAlias The client alias
* @param object $statsdClient A statsd client instance
*/
public function addStatsdClient($clientAlias, $statsdClient)
public function addStatsdClient($clientAlias, $statsdClient): void
{
$this->statsdClients[$clientAlias] = $statsdClient;
}

/**
* Collect the data
*
* @param Request $request The request object
* @param Response $response The response object
* @param \Throwable $exception An exception
* @param Request $request The request object
* @param Response $response The response object
* @param \Throwable|null $exception An exception
*
* @return void
*/
public function collect(Request $request, Response $response, \Throwable $exception = null)
{
Expand All @@ -97,7 +100,7 @@ public function collect(Request $request, Response $response, \Throwable $except
*
* @return array operations list
*/
public function getClients()
public function getClients(): array
{
return $this->data['clients'];
}
Expand Down
19 changes: 16 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace M6Web\Bundle\StatsdBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -15,9 +16,13 @@
*/
class Configuration implements ConfigurationInterface
{
/**
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('m6_statsd');
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

$this->addServersSection($rootNode);
Expand All @@ -27,7 +32,10 @@ public function getConfigTreeBuilder()
return $treeBuilder;
}

private function addServersSection($rootNode)
/**
* @param ArrayNodeDefinition $rootNode
*/
private function addServersSection($rootNode): void
{
$rootNode
->children()
Expand All @@ -53,7 +61,10 @@ function ($v) {
->end();
}

private function addClientsSection($rootNode)
/**
* @param ArrayNodeDefinition $rootNode
*/
private function addClientsSection($rootNode): void
{
$rootNode
->children()
Expand Down Expand Up @@ -97,8 +108,10 @@ private function addClientsSection($rootNode)

/**
* addDefaultEventSection
*
* @param ArrayNodeDefinition $rootNode
*/
private function addDefaultEventSection($rootNode)
private function addDefaultEventSection($rootNode): void
{
$rootNode
->children()
Expand Down
5 changes: 5 additions & 0 deletions src/DependencyInjection/M6WebStatsdExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
*/
class M6WebStatsdExtension extends Extension
{
/**
* @return void
*
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
Expand Down
8 changes: 4 additions & 4 deletions src/Listener/ConsoleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public function __construct()
/**
* Define event dispatch
*/
public function setEventDispatcher(EventDispatcherInterface $ev)
public function setEventDispatcher(EventDispatcherInterface $ev): void
{
$this->eventDispatcher = $ev;
}

public function onCommand(BaseConsoleEvent $e)
public function onCommand(BaseConsoleEvent $e): void
{
$this->startTime = microtime(true);

$this->dispatch($e, ConsoleEvent::COMMAND);
}

public function onTerminate(ConsoleTerminateEvent $e)
public function onTerminate(ConsoleTerminateEvent $e): void
{
// For non-0 exit command, fire an ERROR event
if ($e->getExitCode() != 0) {
Expand All @@ -56,7 +56,7 @@ public function onTerminate(ConsoleTerminateEvent $e)
$this->dispatch($e, ConsoleEvent::TERMINATE);
}

public function onException(BaseConsoleEvent $e)
public function onException(BaseConsoleEvent $e): void
{
$this->dispatch($e, ConsoleEvent::EXCEPTION);
}
Expand Down
Loading

0 comments on commit 1dd0b3b

Please sign in to comment.