Skip to content

Commit

Permalink
Increase PHPStan level
Browse files Browse the repository at this point in the history
  • Loading branch information
lochmueller committed Oct 25, 2024
1 parent ea7c693 commit 71ee510
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 22 deletions.
10 changes: 5 additions & 5 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ email, or any other method with the owners of this repository before making a ch
## Making Changes

* Create a topic branch from where you want to base your work.
* This is usually the master branch.
* This is usually the main branch.
* Only target release branches if you are certain your fix must be on that
branch.
* To quickly create a topic branch based on master; `git checkout -b
fix/master/my_contribution master`. Please avoid working directly on the
`master` branch.
* To quickly create a topic branch based on main; `git checkout -b
fix/main/my_contribution main`. Please avoid working directly on the
`main` branch.
* Make commits of logical units.
* Make sure your commit messages are in the proper format. Use either `[TASK]`, `[FEATURE]`, `[BUGFIX]` or `[DOC]`

Expand All @@ -41,5 +41,5 @@ For changes of a trivial nature, it is not always necessary to create a new issu

## Additional resources

* [Documentation](https://github.com/lochmueller/staticfilecache/tree/master/Documentation)
* [Documentation](https://github.com/lochmueller/staticfilecache/tree/main/Documentation)
* [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/)
4 changes: 1 addition & 3 deletions Classes/Cache/StaticDatabaseBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ public function getTableDefinitions()

/**
* Get the real life time.
*
* @param int $lifetime
*/
protected function getRealLifetime($lifetime): int
protected function getRealLifetime(?int $lifetime): int
{
if (null === $lifetime) {
$lifetime = $this->defaultLifetime;
Expand Down
3 changes: 2 additions & 1 deletion Classes/Cache/StaticFileBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct($context, array $options = [])
* Saves data in the cache.
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param ResponseInterface $data The data to be stored
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry
* @param int $lifetime Lifetime of this cache entry in seconds
*
Expand All @@ -54,6 +54,7 @@ public function __construct($context, array $options = [])
*/
public function set($entryIdentifier, $data, array $tags = [], $lifetime = null): void
{
/** @var ResponseInterface $data */
$realLifetime = $this->getRealLifetime($lifetime);
$time = (new DateTimeService())->getCurrentTime();
$databaseData = [
Expand Down
7 changes: 5 additions & 2 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use SFC\Staticfilecache\Cache\UriFrontend;
use TYPO3\CMS\Backend\Template\Components\Menu\Menu;
use TYPO3\CMS\Backend\Template\Components\Menu\MenuItem;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
Expand Down Expand Up @@ -33,7 +34,8 @@ class BackendController extends ActionController implements LoggerAwareInterface
public function __construct(
readonly protected QueueService $queueService,
readonly protected ModuleTemplateFactory $moduleTemplateFactory,
readonly protected ConfigurationService $configurationService
readonly protected ConfigurationService $configurationService,
readonly protected CacheService $cacheService,
) {}

public function listAction(string $filter = ''): ResponseInterface
Expand Down Expand Up @@ -124,7 +126,8 @@ protected function getCachePagesEntries(string $filter): array
$rows = [];

try {
$cache = GeneralUtility::makeInstance(CacheService::class)->get();
/** @var UriFrontend $cache */
$cache = $this->cacheService->get();
} catch (\Exception $exception) {
$this->logger->error('Problems by fetching the cache: ' . $exception->getMessage() . ' / ' . $exception->getFile() . ':' . $exception->getLine());

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Repository/QueueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function countOpenByIdentifier($identifier): int

/**
* Find old entries.
* @return iterable<int>
* @return iterable<array{uid: int}>
*/
public function findOldUids(): iterable
{
Expand Down
8 changes: 5 additions & 3 deletions Classes/Middleware/GenerateMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SFC\Staticfilecache\Middleware;

use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Context\Context;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -24,13 +25,14 @@

class GenerateMiddleware implements MiddlewareInterface
{
protected ?UriFrontend $cache = null;
protected ?FrontendInterface $cache = null;
protected ServerRequestInterface $request;

public function __construct(
readonly protected EventDispatcherInterface $eventDispatcher,
readonly protected CookieService $cookieService,
readonly protected Typo3Version $typo3Version
readonly protected Typo3Version $typo3Version,
readonly protected CacheService $cacheService
) {}

/**
Expand All @@ -54,7 +56,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}

try {
$this->cache = GeneralUtility::makeInstance(CacheService::class)->get();
$this->cache = $this->cacheService->get();
} catch (\Exception $exception) {
return $this->removeSfcHeaders($response);
}
Expand Down
3 changes: 2 additions & 1 deletion Classes/Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SFC\Staticfilecache\Domain\Repository\QueueRepository;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -20,7 +21,7 @@ class CacheService
*
* @throws NoSuchCacheException
*/
public function get(): UriFrontend
public function get(): FrontendInterface
{
return $this->getManager()->getCache('staticfilecache');
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/ClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function getCallableClient(string $domain): Client
$httpOptions['verify'] = filter_var($httpOptions['verify'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? $httpOptions['verify'];
if (isset($httpOptions['handler']) && \is_array($httpOptions['handler'])) {
$stack = HandlerStack::create();
foreach ($httpOptions['handler'] ?? [] as $handler) {
foreach ($httpOptions['handler'] as $handler) {
$stack->push($handler);
}
$httpOptions['handler'] = $stack;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/InlineAssets/InlineFavIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class InlineFavIcon extends AbstractInlineAssets
/**
* FavIcon extensions.
*/
private $favIconExtensions = ['svg', 'ico', 'png'];
private array $favIconExtensions = ['svg', 'ico', 'png'];

/**
* Check if the class can handle the file extension.
Expand Down
2 changes: 1 addition & 1 deletion Classes/Service/InlineAssets/InlineImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class InlineImages extends AbstractInlineAssets
/**
* Image extensions.
*/
private $imageExtensions = ['png', 'jpg', 'jpeg'];
private array $imageExtensions = ['png', 'jpg', 'jpeg'];

/**
* Check if the class can handle the file extension.
Expand Down
4 changes: 2 additions & 2 deletions Classes/Service/InlineAssets/InlineStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class InlineStyles extends AbstractInlineAssets
/**
* Image extensions.
*/
private $imageExtensions = ['ico', 'png', 'jpg', 'jpeg'];
private array $imageExtensions = ['ico', 'png', 'jpg', 'jpeg'];

/**
* Font extensions.
*/
private $fontExtensions = ['woff', 'woff2'];
private array $fontExtensions = ['woff', 'woff2'];

/**
* Check if the class can handle the file extension.
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ includes:
- .Build/vendor/andersundsehr/phpstan-git-files/extension.php

parameters:
level: 2
level: 5
reportUnmatchedIgnoredErrors: false

0 comments on commit 71ee510

Please sign in to comment.