Skip to content

Commit

Permalink
[CHORE] Change phpstan level to 6 and cleanup phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
garbast committed Nov 17, 2024
1 parent ad9a72c commit a84c687
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 16 deletions.
8 changes: 2 additions & 6 deletions Build/Scripts/additionalTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ cleanRenderedDocumentationFiles() {

getPhpImageVersion() {
case ${1} in
8.1)
echo -n "2.12"
;;
8.2)
echo -n "1.12"
;;
Expand Down Expand Up @@ -297,9 +294,8 @@ Options:
Hack functional or acceptance tests into #numberOfChunks pieces and run tests of #chunk.
Example -c 3/13
-p <8.1|8.2|8.3|8.4>
-p <8.2|8.3|8.4>
Specifies the PHP minor version to be used
- 8.1: use PHP 8.1
- 8.2 (default): use PHP 8.2
- 8.3: use PHP 8.3
- 8.4: use PHP 8.4
Expand Down Expand Up @@ -519,7 +515,7 @@ while getopts ":s:p:q:r:xy:hv" OPT; do
;;
p)
PHP_VERSION=${OPTARG}
if ! [[ ${PHP_VERSION} =~ ^(8.1|8.2|8.3|8.4)$ ]]; then
if ! [[ ${PHP_VERSION} =~ ^(8.1|8.2|8.3)$ ]]; then
INVALID_OPTIONS+=("${OPTARG}")
fi
;;
Expand Down
13 changes: 13 additions & 0 deletions Build/Scripts/phpstan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

THIS_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
cd "$THIS_SCRIPT_DIR" || exit 1
cd ../../ || exit 1
CORE_ROOT="${PWD}"

Build/Scripts/runTests.sh -s composerInstall

Build/Scripts/runTests.sh -s phpstan

Build/Scripts/runTests.sh -s clean
Build/Scripts/additionalTests.sh -s clean
8 changes: 2 additions & 6 deletions Build/Scripts/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ cleanRenderedDocumentationFiles() {

getPhpImageVersion() {
case ${1} in
8.1)
echo -n "2.12"
;;
8.2)
echo -n "1.12"
;;
Expand Down Expand Up @@ -297,9 +294,8 @@ Options:
Hack functional or acceptance tests into #numberOfChunks pieces and run tests of #chunk.
Example -c 3/13
-p <8.1|8.2|8.3|8.4>
-p <8.2|8.3|8.4>
Specifies the PHP minor version to be used
- 8.1: use PHP 8.1
- 8.2 (default): use PHP 8.2
- 8.3: use PHP 8.3
- 8.4: use PHP 8.4
Expand Down Expand Up @@ -457,7 +453,7 @@ while getopts ":a:b:s:c:d:i:t:p:xy:nhug" OPT; do
;;
p)
PHP_VERSION=${OPTARG}
if ! [[ ${PHP_VERSION} =~ ^(8.1|8.2|8.3|8.4)$ ]]; then
if ! [[ ${PHP_VERSION} =~ ^(8.2|8.3|8.4)$ ]]; then
INVALID_OPTIONS+=("${OPTARG}")
fi
;;
Expand Down
2 changes: 2 additions & 0 deletions Build/phpstan/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors:
4 changes: 4 additions & 0 deletions Build/phpstan/phpstan-constants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

// testing-framework defines this, used in various tests.
define('ORIGINAL_ROOT', dirname(__FILE__, 2) . '/');
2 changes: 2 additions & 0 deletions Build/phpstan/phpstan.local.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- phpstan.neon
21 changes: 21 additions & 0 deletions Build/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
includes:
- phpstan-baseline.neon
- ../vendor/friendsoftypo3/phpstan-typo3/extension.neon

parameters:
# Use local .cache dir instead of /tmp
tmpDir: ../.cache/phpstan

level: 6

bootstrapFiles:
- phpstan-constants.php

paths:
- ../../

excludePaths:
# we do not check required extensions
- ../../Build/*
# ext_emconf.php get the $_EXTKEY set from outside. We'll ignore all of them
- ../ext_emconf.php
1 change: 0 additions & 1 deletion Classes/Adapter/SfRegisterAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function __construct(protected CaptchaService $captchaService, protected
*/
public function render(): array|string
{
$this->session->initializeUserSessionManager();
$this->session->remove('captchaWasValid');
return $this->captchaService->getReCaptcha();
}
Expand Down
11 changes: 9 additions & 2 deletions Classes/Services/CaptchaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

class CaptchaService
{
/**
* @var array<string, mixed>
*/
protected array $configuration = [];

public function __construct(
Expand Down Expand Up @@ -80,6 +83,9 @@ protected function initialize(): void
$this->configuration = $configuration;
}

/**
* @return array<string, mixed>
*/
public function getConfiguration(): array
{
return $this->configuration;
Expand Down Expand Up @@ -145,7 +151,7 @@ public function getReCaptcha(): string
/**
* Validate reCAPTCHA challenge/response
*
* @return array Array with verified- (boolean) and error-code (string)
* @return array<string, string|bool> Array with verified- (boolean) and error-code (string)
*/
public function validateReCaptcha(string $value = ''): array
{
Expand Down Expand Up @@ -198,7 +204,8 @@ public function validateReCaptcha(string $value = ''): array
/**
* Query reCAPTCHA server for captcha-verification
*
* @return array Array with verified- (boolean) and error-code (string)
* @param array<string, string> $data
* @return array<string, string|bool|array<string>> Array with verified- (boolean) and error-code (string)
*/
protected function queryVerificationServer(array $data): array
{
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@
"psr/http-message": "^1.1 || ^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.57.1"
"friendsofphp/php-cs-fixer": "^3.64.0",
"friendsoftypo3/phpstan-typo3": "^0.9.0",
"phpstan/phpdoc-parser": "^1.30.0",
"phpstan/phpstan": "^1.12.5",
"phpunit/phpunit": "^11.0.3",
"typo3/testing-framework": "dev-main",
"evoweb/sf-register": "dev-develop"
},
"suggest": {
"typo3/cms-form": "*"
Expand Down

0 comments on commit a84c687

Please sign in to comment.