Skip to content

Commit

Permalink
chore: v12 only, code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
aoekrz committed Jul 3, 2024
1 parent 16f027c commit 8cdf3c2
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 182 deletions.
24 changes: 4 additions & 20 deletions .code-quality/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,6 @@ parameters:
message: "#^Method Aoe\\\\Restler\\\\System\\\\Restler\\\\RestlerExtended\\:\\:postCall\\(\\) has no return type specified\\.$#"
count: 1
path: ../Classes/System/Restler/RestlerExtended.php
-
message: "#^Dead catch \\- Error is never thrown in the try block\\.$#"
count: 1
path: ../Classes/System/Restler/Builder.php
-
message: "#^Anonymous variable in a `\\$request\\-\\>getAttribute\\('site'\\)\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 1
path: ../Classes/System/Dispatcher.php
-
message: "#^Anonymous variable in a `\\$request\\-\\>getAttribute\\('site'\\)\\-\\>getBase\\(\\)\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 1
path: ../Classes/System/Dispatcher.php
-
message: "#^Anonymous variable in a `\\$this\\-\\>request\\-\\>getAttribute\\('site'\\)\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 1
path: ../Classes/System/Restler/RestlerExtended.php
-
message: "#^Anonymous variable in a `\\$this\\-\\>request\\-\\>getAttribute\\('site'\\)\\-\\>getBase\\(\\)\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 1
path: ../Classes/System/Restler/RestlerExtended.php
-
message: "#^Method Aoe\\\\Restler\\\\System\\\\RestApi\\\\RestApiRequest\\:\\:composeHeaders\\(\\) has no return type specified\\.$#"
count: 1
Expand All @@ -64,3 +44,7 @@ parameters:
message: "#^Comparison operation \"\\>\" between int\\<1, max\\> and 0 is always true\\.$#"
count: 1
path: ../Classes/System/Restler/Format/HalJsonFormat.php
-
message: "#^Interface (.*) has only single implementer. Consider using the class directly as there is no point in using the interface.$#"
count: 1
path: ../Classes/System/Restler/ConfigurationInterface.php
5 changes: 3 additions & 2 deletions .code-quality/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ parameters:
paths:
- "../Classes/"

ignoreErrors:
- identifier: missingType.iterableValue

inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
checkAlwaysTrueCheckTypeFunctionCall: false
checkAlwaysTrueStrictComparison: false

Expand Down
30 changes: 0 additions & 30 deletions .code-quality/rector-8_0.php

This file was deleted.

4 changes: 0 additions & 4 deletions .code-quality/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector;
use Rector\Set\ValueObject\SetList;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector;

Expand All @@ -35,8 +33,6 @@
PHPUnitSetList::PHPUNIT_CODE_QUALITY
])
->withSkip([
FinalizeClassesWithoutChildrenRector::class,
ChangeAndIfToEarlyReturnRector::class,
TypedPropertyFromStrictSetUpRector::class,
AddMethodCallBasedStrictParamTypeRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
Expand Down
22 changes: 4 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
name: Tests

on:
push:
branches:
- '**'
- '!TYPO3_V10'
- '!TYPO3V8'
- '!TYPO3V9'
pull_request:
branches:
- '**'
- '!TYPO3_V10'
- '!TYPO3V8'
- '!TYPO3V9'
on: [ push, pull_request ]

jobs:
build:
Expand All @@ -22,12 +10,10 @@ jobs:
strategy:
fail-fast: false
matrix:
typo3: [ ^11.5, ^12.4 ]
php: [ '8.0', '8.1', '8.2', '8.3' ]
typo3: [ ^12.4 ]
php: [ '8.1', '8.2', '8.3' ]
experimental: [false]
exclude:
- typo3: ^12.4
php: '8.0'


continue-on-error: ${{ matrix.experimental }}

Expand Down
3 changes: 3 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
build:
nodes:
analysis:
image: default-bionic
environment:
php: 8.3.0
tests:
override:
- php-scrutinizer-run
Expand Down
8 changes: 3 additions & 5 deletions Classes/Controller/BeUserAuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ class BeUserAuthenticationController implements iAuthenticate
*/
public $restler;

private Loader $typo3Loader;

public function __construct(Loader $typo3Loader)
{
$this->typo3Loader = $typo3Loader;
public function __construct(
private readonly Loader $typo3Loader
) {
$this->restler = Scope::get('Restler');
}

Expand Down
8 changes: 3 additions & 5 deletions Classes/Controller/FeUserAuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ class FeUserAuthenticationController implements iAuthenticate
*/
public $restler;

private Loader $typo3Loader;

public function __construct(Loader $typo3Loader)
{
$this->typo3Loader = $typo3Loader;
public function __construct(
private readonly Loader $typo3Loader
) {
$this->restler = Scope::get('Restler');
}

Expand Down
10 changes: 9 additions & 1 deletion Classes/System/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,15 @@ protected function extractSiteUrl(ServerRequestInterface $request): string
}

if ($siteBasePath) {
return '/' . rtrim(preg_replace('%^' . preg_quote($siteBasePath, '%') . '%', '', $request->getUri()->getPath()), '/');
return '/' . rtrim(
(string) preg_replace(
'%^' . preg_quote((string) $siteBasePath, '%') . '%',
'',
$request->getUri()
->getPath()
),
'/'
);
}

return $request->getUri()
Expand Down
15 changes: 3 additions & 12 deletions Classes/System/RestApi/RestApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,15 @@

class RestApiClient implements SingletonInterface
{
private Cache $typo3Cache;

private ExtensionConfiguration $extensionConfiguration;

private bool $isExecutingRequest = false;

private bool $isRequestPrepared = false;

private RestApiRequestScope $restApiRequestScope;

public function __construct(
ExtensionConfiguration $extensionConfiguration,
RestApiRequestScope $restApiRequestScope,
Cache $typo3Cache
private readonly ExtensionConfiguration $extensionConfiguration,
private readonly RestApiRequestScope $restApiRequestScope,
private readonly Cache $typo3Cache
) {
$this->extensionConfiguration = $extensionConfiguration;
$this->restApiRequestScope = $restApiRequestScope;
$this->typo3Cache = $typo3Cache;
}

public function isExecutingRequest(): bool
Expand Down
4 changes: 2 additions & 2 deletions Classes/System/RestApi/RestApiJsonFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public function decode($data)
}

try {
$decoded = json_decode($data, false, 512, $options);
$decoded = json_decode((string) $data, false, 512, $options);
$this->handleJsonError();
} catch (\RuntimeException $runtimeException) {
throw new RestException('400', $runtimeException->getMessage());
}

if (strlen($data) && $decoded === null || $decoded === $data) {
if (strlen((string) $data) && $decoded === null || $decoded === $data) {
throw new RestException('400', 'Error parsing JSON');
}

Expand Down
14 changes: 5 additions & 9 deletions Classes/System/RestApi/RestApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ class RestApiRequest extends Restler
*/
private string $restApiRequestMethod;

private RestApiRequestScope $restApiRequestScope;

private Cache $typo3Cache;

/***************************************************************************************************************************/
/***************************************************************************************************************************/
/* Block of methods, which MUST be overridden from parent-class (otherwise this class can not work) *************************/
Expand All @@ -101,10 +97,10 @@ class RestApiRequest extends Restler
* Override parent method...because we don't want to call it!
* The original method would set some properties (e.g. set this object into static properties of global classes)
*/
public function __construct(RestApiRequestScope $restApiRequestScope, Cache $typo3Cache)
{
$this->restApiRequestScope = $restApiRequestScope;
$this->typo3Cache = $typo3Cache;
public function __construct(
private readonly RestApiRequestScope $restApiRequestScope,
private readonly Cache $typo3Cache
) {
}

/**
Expand Down Expand Up @@ -235,7 +231,7 @@ protected function postCall()
$_GET,
$this->apiMethodInfo->metadata,
$this->responseData,
get_class($this->responseFormat),
$this->responseFormat::class,
[] // we don't know which headers would be 'normally' send - because this is an internal REST-API-call
);
}
Expand Down
8 changes: 0 additions & 8 deletions Classes/System/Restler/AbstractExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use Aoe\Restler\Configuration\ExtensionConfiguration;
use Luracast\Restler\RestException;
use Luracast\Restler\Restler;
use Luracast\Restler\Scope;
Expand All @@ -37,13 +36,6 @@
*/
abstract class AbstractExceptionHandler
{
protected ExtensionConfiguration $extensionConfiguration;

public function __construct(ExtensionConfiguration $extensionConfiguration)
{
$this->extensionConfiguration = $extensionConfiguration;
}

/**
* handle HTTP-Status-Codes of type 1xx
*/
Expand Down
12 changes: 4 additions & 8 deletions Classes/System/Restler/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@

class Builder implements SingletonInterface
{
private ExtensionConfiguration $extensionConfiguration;

private CacheManager $cacheManager;

public function __construct(ExtensionConfiguration $extensionConfiguration, CacheManager $cacheManager)
{
$this->extensionConfiguration = $extensionConfiguration;
$this->cacheManager = $cacheManager;
public function __construct(
private readonly ExtensionConfiguration $extensionConfiguration,
private readonly CacheManager $cacheManager,
) {
}

/**
Expand Down
8 changes: 3 additions & 5 deletions Classes/System/Restler/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@
*/
class Configuration implements ConfigurationInterface
{
private ExtensionConfiguration $extensionConfiguration;

public function __construct(ExtensionConfiguration $extensionConfiguration)
{
$this->extensionConfiguration = $extensionConfiguration;
public function __construct(
private readonly ExtensionConfiguration $extensionConfiguration
) {
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Classes/System/Restler/Format/HalJsonFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function encode($data, $humanReadable = false)
if (self::$unEscapedUnicode) {
$result = preg_replace_callback(
'/\\\u(\w\w\w\w)/',
static function (array $matches) {
static function (array $matches): string|false {
if (function_exists('mb_convert_encoding')) {
return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16BE');
}
Expand Down Expand Up @@ -154,13 +154,13 @@ public function decode($data): ?array
}

try {
$decoded = json_decode($data, false, 512, $options);
$decoded = json_decode((string) $data, false, 512, $options);
$this->handleJsonError();
} catch (\RuntimeException $runtimeException) {
throw new RestException('400', $runtimeException->getMessage());
}

if (strlen($data) && $decoded === null || $decoded === $data) {
if (strlen((string) $data) && $decoded === null || $decoded === $data) {
throw new RestException('400', 'Error parsing JSON');
}

Expand Down
Loading

0 comments on commit 8cdf3c2

Please sign in to comment.