diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ebd76de..52bc8d5 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,6 +3,7 @@ on: push: branches: - "master" + - "tac" pull_request: ~ workflow_dispatch: ~ @@ -15,7 +16,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.1" dependencies: - "highest" @@ -53,8 +54,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - - "8.0" - "8.1" dependencies: @@ -62,13 +61,8 @@ jobs: - "highest" symfony: - - "^4.4" - - "^5.4" - - "^6.0" - - exclude: - - php-version: "7.4" - symfony: "^6.0" + - "^6.4" + - "^7.1" steps: - name: "Checkout" @@ -103,21 +97,18 @@ jobs: strategy: matrix: php-version: - - "7.4" - - "8.0" - "8.1" + - "8.2" + - "8.3" + - "8.4" dependencies: - "highest" symfony: - - "^4.4" - - "^5.4" - - "^6.0" - - exclude: - - php-version: "7.4" - symfony: "^6.0" + - "~6.4.0" + - "~7.1.0" + - "~7.2.0" steps: - name: "Checkout" @@ -160,11 +151,11 @@ jobs: symfony: - "^4.4" - "^5.4" - - "^6.0" + - "^6.4 || ^7.1" exclude: - php-version: "7.4" - symfony: "^6.0" + symfony: "^6.4 || ^7.1" steps: - name: "Checkout" diff --git a/composer.json b/composer.json index 60fa873..27dd584 100644 --- a/composer.json +++ b/composer.json @@ -10,28 +10,28 @@ } ], "require": { - "php": ">=7.4", - "setono/symfony-main-request-trait": "^1.0", - "symfony/config": "^4.4 || ^5.4 || ^6.0", - "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0", - "symfony/http-foundation": "^4.4 || ^5.4 || ^6.0", - "symfony/http-kernel": "^4.4 || ^5.4 || ^6.0", - "twig/twig": "^2.14 || ^3.4" + "php": "^8.2", + "symfony/config": "^6.4 || ^7.1", + "symfony/dependency-injection": "^6.4 || ^7.1", + "symfony/http-foundation": "^6.4 || ^7.1", + "symfony/http-kernel": "^6.4 || ^7.1", + "twig/twig": "^3.4" }, "require-dev": { "infection/infection": "^0.26", "matomo/device-detector": "^5.0 || ^6.0", "matthiasnoback/symfony-dependency-injection-test": "^4.3", - "nette/php-generator": "^3.6", + "nette/php-generator": "^4.1", "phpbench/phpbench": "^1.2", "phpspec/prophecy-phpunit": "^2.0", + "phpstan/phpstan": "^1.12", "phpunit/phpunit": "^9.5", "psalm/plugin-phpunit": "^0.18", "psalm/plugin-symfony": "^4.0", "roave/security-advisories": "dev-latest", "setono/code-quality-pack": "^2.2", - "symfony/console": "^4.4 || ^5.4 || ^6.0", - "symfony/yaml": "^4.4 || ^5.4 || ^6.0", + "symfony/console": "^6.4 || ^7.1", + "symfony/yaml": "^6.4 || ^7.1", "webmozart/assert": "^1.11" }, "prefer-stable": true, diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..6d71221 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,38 @@ +parameters: + level: 9 + inferPrivatePropertyTypeFromConstructor: true + paths: + - ./src/ + + excludePaths: +# - 'src/Resources/skeleton' +# - */cache/* + analyse: + - ./vendor + + reportUnmatchedIgnoredErrors: false +# checkMissingIterableValueType: false +# checkGenericClassInNonGenericObjectType: false + ignoreErrors: + - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\)\.#' + - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::scalarNode\(\).#' + # Only available in ArrayNodeDefinition which is given + # False positive: clients are not dependencies of this project. +# - +# message: '#Call to an undefined method Symfony\Component\Config\Definition\Builder\NodeDefinition::children#' +# path: ./src/Client/Provider +# - +# message: '#Return typehint of method KnpU\\OAuth2ClientBundle\\Client\\Provider\\[a-zA-Z0-9\\_]+::fetchUser\(\) has invalid type [a-zA-Z0-9\\_]#' +# path: ./src/Client/Provider + # False positive: using `::class` is not an error for those providers `::getProviderClass()` method. +# - +# message: '#Class [a-zA-Z0-9\\_]+ not found#' +# path: ./src/DependencyInjection/Providers + + # The DependencyInjection returns are very complex to deal with +# - +# message: '#.*NodeParentInterface\|null.*#' +# path: ./src/DependencyInjection/Providers +# - +# message: '#.*NodeDefinition::children.*#' +# path: ./src/DependencyInjection diff --git a/src/BotDetector/BotDetector.php b/src/BotDetector/BotDetector.php index 8765a3e..3fa26a2 100644 --- a/src/BotDetector/BotDetector.php +++ b/src/BotDetector/BotDetector.php @@ -10,20 +10,16 @@ final class BotDetector implements BotDetectorInterface { - use MainRequestTrait; - /** @var array */ private array $cache = []; - private RequestStack $requestStack; - /** @var list */ private array $popular; /** * @param list|null $popular */ - public function __construct(RequestStack $requestStack, array $popular = null) + public function __construct(private readonly RequestStack $requestStack, array $popular = null) { $this->requestStack = $requestStack; if (null === $popular) { @@ -56,13 +52,11 @@ public function isBot(string $userAgent): bool public function isBotRequest(Request $request = null): bool { + $request = $request ?? $this->requestStack->getCurrentRequest(); if (null === $request) { - $request = $this->getMainRequestFromRequestStack($this->requestStack); - if (null === $request) { - return false; - } + return false; } - + assert($request instanceof Request); $userAgent = $request->headers->get('user-agent'); if (null === $userAgent) { return false; diff --git a/tests/BotDetector/BotDetectorTest.php b/tests/BotDetector/BotDetectorTest.php index d9f25e8..f0ef464 100644 --- a/tests/BotDetector/BotDetectorTest.php +++ b/tests/BotDetector/BotDetectorTest.php @@ -41,6 +41,7 @@ public function it_returns_false_if_no_request_is_provided_and_the_request_does_ { $requestStack = new RequestStack(); $requestStack->push(new Request()); + assert($requestStack->getCurrentRequest()); $botDetector = new BotDetector($requestStack); self::assertFalse($botDetector->isBotRequest());