From ba632bf6f7d4c284f9ee0e40dc35e464a6b1027e Mon Sep 17 00:00:00 2001 From: othillo Date: Mon, 30 Mar 2020 16:25:28 +0200 Subject: [PATCH] PHPStan level max --- app/bootstrap.php | 6 ++---- composer.json | 4 +++- .../Application/Toggle/TogglesEndpointTest.php | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/bootstrap.php b/app/bootstrap.php index 16bbd72..0743c3b 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -34,7 +34,7 @@ $app['debug'] = getenv('TOGGLE__DEBUG'); $app['redis_dsn'] = getenv('TOGGLE__REDIS_DSN'); $app['toggle.manager.prefix'] = getenv('TOGGLE__PREFIX'); -$app['allowed_origins'] = json_decode(getenv('TOGGLE__ALLOWED_ORIGINS')); +$app['allowed_origins'] = getenv('TOGGLE__ALLOWED_ORIGINS') ? json_decode((string) getenv('TOGGLE__ALLOWED_ORIGINS'), true) : []; if (JSON_ERROR_NONE !== json_last_error()) { throw new RuntimeException('Failed to json_decode TOGGLE__ALLOWED_ORIGINS'); @@ -79,9 +79,7 @@ }); $app['request_to_toggle'] = $app->protect(function (Request $request) use ($app) { - $serialized = $request->getContent(); - - $data = json_decode($serialized, true); + $data = json_decode((string) $request->getContent(), true); if (JSON_ERROR_NONE != json_last_error()) { return null; diff --git a/composer.json b/composer.json index 8ac831c..f7c1eee 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ ], "require": { "php": ">=7.2", + "ext-json": "*", "silex/silex": "^1.0", "qandidate/toggle": "^0.2@dev", "predis/service-provider": "^0.4@dev", @@ -32,7 +33,8 @@ "require-dev": { "symfony/browser-kit": "^3.4||^4.0||^5.0", "phpunit/phpunit": "~4.8", - "broadway/coding-standard": "^1.0" + "broadway/coding-standard": "^1.0", + "phpstan/phpstan": "@stable" }, "prefer-stable": true, "autoload-dev": { diff --git a/test/Qandidate/Application/Toggle/TogglesEndpointTest.php b/test/Qandidate/Application/Toggle/TogglesEndpointTest.php index 5b864c2..afd0cbf 100644 --- a/test/Qandidate/Application/Toggle/TogglesEndpointTest.php +++ b/test/Qandidate/Application/Toggle/TogglesEndpointTest.php @@ -20,7 +20,7 @@ class TogglesEndpointTest extends WebTestCase { - public function setUp() + public function setUp(): void { parent::setUp(); @@ -30,7 +30,7 @@ public function setUp() /** * @test */ - public function it_exposes_all_toggle_names() + public function it_exposes_all_toggle_names(): void { $client = $this->createClient(); $crawler = $client->request('GET', '/toggles'); @@ -59,7 +59,7 @@ public function it_exposes_all_toggle_names() /** * @test */ - public function it_can_delete_a_toggle() + public function it_can_delete_a_toggle(): void { $client = $this->createClient(); $crawler = $client->request('DELETE', '/toggles/toggling'); @@ -76,7 +76,7 @@ public function it_can_delete_a_toggle() /** * @test */ - public function it_returns_400_on_deleting_non_existing_toggle() + public function it_returns_400_on_deleting_non_existing_toggle(): void { $client = $this->createClient(); $crawler = $client->request('DELETE', '/toggles/nothere'); @@ -87,7 +87,7 @@ public function it_returns_400_on_deleting_non_existing_toggle() /** * @test */ - public function it_updates_a_toggle_on_put() + public function it_updates_a_toggle_on_put(): void { $toggleData = [ 'name' => 'toggling', @@ -122,7 +122,7 @@ public function it_updates_a_toggle_on_put() /** * @test */ - public function it_does_not_accept_a_new_name_on_put() + public function it_does_not_accept_a_new_name_on_put(): void { $toggleData = ['name' => 'new-name', 'conditions' => []]; $toggle = json_encode($toggleData); @@ -144,7 +144,7 @@ public function tearDown() } } - private function loadToggleFixtures(ToggleManager $manager) + private function loadToggleFixtures(ToggleManager $manager): void { // A toggle that will be active is the user id is less than 42 $operator = new LessThan(42);