diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 639afcb..1d765c0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,3 +35,11 @@ phpstan: script: - composer install --no-scripts - php vendor/bin/phpstan --dry-run + +easy-coding-standard: + stage: static-analysis + image: $CI_REGISTRY_IMAGE/pipeline-runner:$CI_COMMIT_REF_SLUG + script: + - composer install --no-scripts + - php vendor/bin/ecs + diff --git a/composer.json b/composer.json index 8499cf5..3564a2b 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "require-dev": { "phpstan/phpstan": "^1.10", "rector/rector": "^0.17.2", - "phpunit/phpunit": "~9.6" + "phpunit/phpunit": "~9.6", + "symplify/easy-coding-standard": "^11.5" }, "config": { "allow-plugins": { diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..0061ea7 --- /dev/null +++ b/ecs.php @@ -0,0 +1,19 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $ecsConfig->sets([ + SetList::PSR_12, + SetList::STRICT, + SetList::CLEAN_CODE, + SetList::COMMON, + ]); +}; diff --git a/src/Controller/Mamo/MetricsController.php b/src/Controller/Mamo/MetricsController.php index 699a993..abb184c 100644 --- a/src/Controller/Mamo/MetricsController.php +++ b/src/Controller/Mamo/MetricsController.php @@ -1,5 +1,7 @@ systemConfigService->get(MobiMamoConnector::PLUGIN_IDENTIFIER . ".config.secret"); - if (!is_string($secret)) { + $secret = $this->systemConfigService->get(MobiMamoConnector::PLUGIN_IDENTIFIER . '.config.secret'); + if (! is_string($secret)) { // Can only happen, when we change our config template or Shopware itself screws up. - $this->logger->error("Configuration Secret is not a string.", [ - "receivedType" => gettype($secret), + $this->logger->error('Configuration Secret is not a string.', [ + 'receivedType' => gettype($secret), ]); throw new HttpException(500); } - if (!$this->requestAuthorizationService->isAuthorized($request, $secret)) { - $this->logger->info("Request is not authorized to access the metrics endpoint."); + if (! $this->requestAuthorizationService->isAuthorized($request, $secret)) { + $this->logger->info('Request is not authorized to access the metrics endpoint.'); throw new HttpException(403); } diff --git a/src/MobiMamoConnector.php b/src/MobiMamoConnector.php index 126190d..737d6f5 100644 --- a/src/MobiMamoConnector.php +++ b/src/MobiMamoConnector.php @@ -1,4 +1,6 @@ -query->get("secret"); - if (!is_string($requestSecret)) { + $requestSecret = $request->query->get('secret'); + if (! is_string($requestSecret)) { return false; } return $requestSecret === $secret; } -} \ No newline at end of file +} diff --git a/tests/RequestAuthorizationServiceTest.php b/tests/RequestAuthorizationServiceTest.php index f26d92e..867f6ab 100644 --- a/tests/RequestAuthorizationServiceTest.php +++ b/tests/RequestAuthorizationServiceTest.php @@ -1,5 +1,7 @@ self::TESTING_SECRET, + 'secret' => self::TESTING_SECRET, ]); $service = new RequestAuthorizationService(); @@ -24,7 +26,7 @@ public function testAuthorizedRequestWhenSecretMatches(): void public function testRequestIsUnauthorizedWhenSecretDoesNotMatch(): void { $request = new Request([ - "secret" => self::TESTING_SECRET. "-differs", + 'secret' => self::TESTING_SECRET . '-differs', ]); $service = new RequestAuthorizationService();