diff --git a/composer.json b/composer.json index 1f1d5303..d58a88aa 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "require-dev": { "filp/whoops": "^2.0", "phpunit/phpunit": "^6.0", + "slevomat/coding-standard": "^4.0", "squizlabs/php_codesniffer": "^3.1", "symfony/var-dumper": "^3.0", "vlucas/phpdotenv": "^2.2", diff --git a/config/autoload/app_options.global.php b/config/autoload/app_options.global.php index fd7147a1..0f8163bf 100644 --- a/config/autoload/app_options.global.php +++ b/config/autoload/app_options.global.php @@ -1,4 +1,6 @@ [ diff --git a/config/autoload/preview-generation.global.php b/config/autoload/preview-generation.global.php index b4f14da3..4a4fa9d1 100644 --- a/config/autoload/preview-generation.global.php +++ b/config/autoload/preview-generation.global.php @@ -1,4 +1,6 @@ [ diff --git a/config/autoload/router.global.php b/config/autoload/router.global.php index fb026248..deb875f3 100644 --- a/config/autoload/router.global.php +++ b/config/autoload/router.global.php @@ -1,4 +1,6 @@ [ Service\ShortUrlService::class, PreviewGenerator::class, - 'translator' + 'translator', ], Command\Visit\ProcessVisitsCommand::class => [ Service\VisitService::class, IpLocationResolver::class, - 'translator' + 'translator', ], Command\Config\GenerateCharsetCommand::class => ['translator'], Command\Config\GenerateSecretCommand::class => ['translator'], diff --git a/module/CLI/config/translator.config.php b/module/CLI/config/translator.config.php index ae120db3..659d4cae 100644 --- a/module/CLI/config/translator.config.php +++ b/module/CLI/config/translator.config.php @@ -1,4 +1,6 @@ [ diff --git a/module/CLI/src/Command/Api/DisableKeyCommand.php b/module/CLI/src/Command/Api/DisableKeyCommand.php index fbf02992..e4390203 100644 --- a/module/CLI/src/Command/Api/DisableKeyCommand.php +++ b/module/CLI/src/Command/Api/DisableKeyCommand.php @@ -1,4 +1,6 @@ previewGenerator->generatePreview('http://baz.com/something')->shouldBeCalledTimes(1); $this->commandTester->execute([ - 'command' => 'shortcode:process-previews' + 'command' => 'shortcode:process-previews', ]); } @@ -83,7 +85,7 @@ class GeneratePreviewCommandTest extends TestCase ->shouldBeCalledTimes(count($items)); $this->commandTester->execute([ - 'command' => 'shortcode:process-previews' + 'command' => 'shortcode:process-previews', ]); $output = $this->commandTester->getDisplay(); $this->assertEquals(count($items), substr_count($output, 'Error')); diff --git a/module/CLI/test/Command/Shortcode/GenerateShortcodeCommandTest.php b/module/CLI/test/Command/Shortcode/GenerateShortcodeCommandTest.php index 11a1385d..e1dc5229 100644 --- a/module/CLI/test/Command/Shortcode/GenerateShortcodeCommandTest.php +++ b/module/CLI/test/Command/Shortcode/GenerateShortcodeCommandTest.php @@ -1,4 +1,6 @@ urlShortener = $this->prophesize(UrlShortener::class); $command = new GenerateShortcodeCommand($this->urlShortener->reveal(), Translator::factory([]), [ 'schema' => 'http', - 'hostname' => 'foo.com' + 'hostname' => 'foo.com', ]); $app = new Application(); $app->add($command); @@ -44,7 +46,7 @@ class GenerateShortcodeCommandTest extends TestCase $this->commandTester->execute([ 'command' => 'shortcode:generate', - 'longUrl' => 'http://domain.com/foo/bar' + 'longUrl' => 'http://domain.com/foo/bar', ]); $output = $this->commandTester->getDisplay(); $this->assertTrue(strpos($output, 'http://foo.com/abc123') > 0); @@ -60,7 +62,7 @@ class GenerateShortcodeCommandTest extends TestCase $this->commandTester->execute([ 'command' => 'shortcode:generate', - 'longUrl' => 'http://domain.com/invalid' + 'longUrl' => 'http://domain.com/invalid', ]); $output = $this->commandTester->getDisplay(); $this->assertTrue( diff --git a/module/CLI/test/Command/Shortcode/GetVisitsCommandTest.php b/module/CLI/test/Command/Shortcode/GetVisitsCommandTest.php index 4ec77e71..d80d6d4f 100644 --- a/module/CLI/test/Command/Shortcode/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/Shortcode/GetVisitsCommandTest.php @@ -1,4 +1,6 @@ paginableRepository = $paginableRepository; - $this->searchTerm = trim(strip_tags($searchTerm)); + $this->searchTerm = $searchTerm !== null ? trim(strip_tags($searchTerm)) : null; $this->orderBy = $orderBy; $this->tags = $tags; } diff --git a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php index a1e0ec5c..167de806 100644 --- a/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php +++ b/module/Common/src/Paginator/Util/PaginatorUtilsTrait.php @@ -1,4 +1,6 @@ httpClient->get(sprintf(self::SERVICE_PATTERN, $ipAddress)); - return json_decode($response->getBody(), true); + return json_decode((string) $response->getBody(), true); } catch (GuzzleException $e) { throw WrongIpException::fromIpAddress($ipAddress, $e); } diff --git a/module/Common/src/Service/IpLocationResolverInterface.php b/module/Common/src/Service/IpLocationResolverInterface.php index 350c2b9c..4f4279a2 100644 --- a/module/Common/src/Service/IpLocationResolverInterface.php +++ b/module/Common/src/Service/IpLocationResolverInterface.php @@ -1,4 +1,6 @@ '1.2.3.4', - 'port' => 123 + 'port' => 123, ], [ 'host' => '4.3.2.1', - 'port' => 321 + 'port' => 321, ], ]; /** @var MemcachedCache $instance */ diff --git a/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php b/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php index aca35f62..dd4b6301 100644 --- a/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php +++ b/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php @@ -1,4 +1,6 @@ function () { return $this->image->reveal(); }, - ] + ], ]), $this->filesystem->reveal(), 'dir'); } diff --git a/module/Common/test/Template/Extension/TranslatorExtensionTest.php b/module/Common/test/Template/Extension/TranslatorExtensionTest.php index e39e2b24..04d36188 100644 --- a/module/Common/test/Template/Extension/TranslatorExtensionTest.php +++ b/module/Common/test/Template/Extension/TranslatorExtensionTest.php @@ -1,4 +1,6 @@ [], diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index a25c82fb..a21a92b8 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -1,4 +1,5 @@ [ diff --git a/module/Core/config/routes.config.php b/module/Core/config/routes.config.php index a3c70aeb..e18cb448 100644 --- a/module/Core/config/routes.config.php +++ b/module/Core/config/routes.config.php @@ -1,4 +1,6 @@ [ diff --git a/module/Core/config/zend-expressive.config.php b/module/Core/config/zend-expressive.config.php index 3dfd091f..81f6676f 100644 --- a/module/Core/config/zend-expressive.config.php +++ b/module/Core/config/zend-expressive.config.php @@ -1,4 +1,5 @@ chars . "]+|", $shortCode)) { + if (! preg_match('|[' . $this->chars . ']+|', $shortCode)) { throw InvalidShortCodeException::fromCharset($shortCode, $this->chars); } diff --git a/module/Core/src/Service/UrlShortenerInterface.php b/module/Core/src/Service/UrlShortenerInterface.php index 4ddf4b7b..c677ec4e 100644 --- a/module/Core/src/Service/UrlShortenerInterface.php +++ b/module/Core/src/Service/UrlShortenerInterface.php @@ -1,4 +1,6 @@ [Service\UrlShortener::class, 'translator'], Action\GetVisitsAction::class => [Service\VisitsTracker::class, 'translator', 'Logger_Shlink'], diff --git a/module/Rest/config/entity-manager.config.php b/module/Rest/config/entity-manager.config.php index e9359519..e5008568 100644 --- a/module/Rest/config/entity-manager.config.php +++ b/module/Rest/config/entity-manager.config.php @@ -1,4 +1,6 @@ [ diff --git a/module/Rest/config/error-handler.config.php b/module/Rest/config/error-handler.config.php index cb06f6bf..b3df3f7c 100644 --- a/module/Rest/config/error-handler.config.php +++ b/module/Rest/config/error-handler.config.php @@ -1,4 +1,6 @@ [ diff --git a/module/Rest/src/Action/AbstractRestAction.php b/module/Rest/src/Action/AbstractRestAction.php index 01b8c13d..9ba1e650 100644 --- a/module/Rest/src/Action/AbstractRestAction.php +++ b/module/Rest/src/Action/AbstractRestAction.php @@ -1,4 +1,6 @@ [ 'data' => $visits, - ] + ], ]); } catch (InvalidArgumentException $e) { - $this->logger->warning('Provided nonexistent shortcode'. PHP_EOL . $e); + $this->logger->warning('Provided nonexistent shortcode' . PHP_EOL . $e); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => sprintf( @@ -63,7 +65,7 @@ class GetVisitsAction extends AbstractRestAction ), ], self::STATUS_NOT_FOUND); } catch (\Exception $e) { - $this->logger->error('Unexpected error while parsing short code'. PHP_EOL . $e); + $this->logger->error('Unexpected error while parsing short code' . PHP_EOL . $e); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, 'message' => $this->translator->translate('Unexpected error occurred'), diff --git a/module/Rest/src/Action/ListShortcodesAction.php b/module/Rest/src/Action/ListShortcodesAction.php index aa941375..83007e29 100644 --- a/module/Rest/src/Action/ListShortcodesAction.php +++ b/module/Rest/src/Action/ListShortcodesAction.php @@ -1,4 +1,6 @@ process($request); } diff --git a/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php b/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php index 93537d35..b5823f4f 100644 --- a/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php +++ b/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php @@ -1,4 +1,6 @@ Coding standard + @@ -9,11 +10,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + bin