From d1ade28bdd1e43fdc5de92f998b3c213a435cc1e Mon Sep 17 00:00:00 2001 From: Gavin Staniforth Date: Wed, 4 Sep 2019 13:55:53 +0100 Subject: [PATCH] feat: prevent request stack in the constructor --- .../PreventRequestStackInConstructorSniff.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Markup/Sniffs/Symfony/PreventRequestStackInConstructorSniff.php diff --git a/Markup/Sniffs/Symfony/PreventRequestStackInConstructorSniff.php b/Markup/Sniffs/Symfony/PreventRequestStackInConstructorSniff.php new file mode 100644 index 0000000..0f7b26e --- /dev/null +++ b/Markup/Sniffs/Symfony/PreventRequestStackInConstructorSniff.php @@ -0,0 +1,50 @@ +getMethodParameters($openTagPointer) as $parameter) { + if (isset($parameter['type_hint']) && $parameter['type_hint'] === 'RequestStack') { + $phpcsFile->addError( + sprintf( + 'Using RequestStack as a constructor argument ties the implementation to Reqest only which is not useful, see alteratives or context pass the Request from the HTTP Transport Layer', + $name + ), + $openTagPointer, + 'PreventRequestStackInConstructor' + ); + } + } + } + +}