Skip to content

introduce phpstan #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
"symfony/browser-kit": "^6.4",
"symfony/framework-bundle": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/stopwatch": "^6.4"
"symfony/stopwatch": "^6.4",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-symfony": "^1.4",
"symfony/runtime": "^6.4"
},
"autoload": {
"psr-4": {
Expand All @@ -43,6 +46,8 @@
"ci": [
"composer validate",
"@check-cs",
"tests/Symfony/console ca:cl -e test",
"@phpstan",
"@phpunit"
],
"check-cs": [
Expand All @@ -53,11 +58,17 @@
],
"phpunit": [
"phpunit"
],
"phpstan": [
"phpstan analyse -c phpstan.neon"
]
},
"config": {
"platform": {
"php": "8.1"
},
"allow-plugins": {
"symfony/runtime": true
}
}
}
211 changes: 210 additions & 1 deletion composer.lock

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

13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-symfony/rules.neon

parameters:
phpVersion: 80100
level: max
paths:
- src
- tests
symfony:
containerXmlPath: var/cache/test/Chaos_Monkey_Symfony_Tests_Symfony_KernelTestDebugContainer.xml
27 changes: 26 additions & 1 deletion src/DependencyInjection/ChaosMonkeyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,42 @@
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

/**
* @phpstan-type ConfigArray array{
* enabled: bool,
* probability: int,
* assaults: array{
* latency: array{active: bool, minimum: int, maximum: int},
* memory: array{active: bool, fill_fraction: float},
* exception: array{active: bool, class: class-string<\Throwable>},
* kill_app: array{active: bool}
* },
* watchers: array{
* request: array{enabled: bool, priority: int}
* }
* }
*/
class ChaosMonkeyExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
/**
* @param array<array<mixed>> $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');

$configuration = new Configuration();
/** @var ConfigArray $config */
$config = $this->processConfiguration($configuration, $configs);

$this->setChaosMonkeySettings($container, $config);
$this->enableWatchers($container, $config);
}

/**
* @param ConfigArray $config
*/
private function setChaosMonkeySettings(ContainerBuilder $container, array $config): void
{
$definition = $container->getDefinition('chaos_monkey.settings');
Expand All @@ -42,6 +64,9 @@ private function setChaosMonkeySettings(ContainerBuilder $container, array $conf
$definition->addMethodCall('setKillAppActive', [$config['assaults']['kill_app']['active']]);
}

/**
* @param ConfigArray $config
*/
private function enableWatchers(ContainerBuilder $container, array $config): void
{
if ($config['watchers']['request']['enabled'] === true) {
Expand Down
Loading
Loading