Skip to content

Commit

Permalink
[TASK] Raise PHPstan level to 6
Browse files Browse the repository at this point in the history
  • Loading branch information
linawolf committed May 4, 2024
1 parent ca2e07d commit 5445697
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Build/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ includes:

parameters:
phpVersion: 80200
level: 5
level: 6

bootstrapFiles:
- phpstan-typo3-constants.php
Expand Down
5 changes: 4 additions & 1 deletion Classes/ContextMenu/HelloWorldItemProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HelloWorldItemProvider extends AbstractProvider
{
/**
* This array contains configuration for items you want to add
* @var array
* @var array<string, array<string, string>>
*/
protected $itemsConfiguration = [
'hello' => [
Expand Down Expand Up @@ -64,6 +64,7 @@ public function getPriority(): int
* Registers the additional JavaScript ES6 callback-module which will allow to display a notification
* whenever the user tries to click on the "Hello World" item.
* The method is called from AbstractProvider::prepareItems() for each context menu item.
* @return array<string, string>
*/
protected function getAdditionalAttributes(string $itemName): array
{
Expand All @@ -77,6 +78,8 @@ protected function getAdditionalAttributes(string $itemName): array
* This method adds custom item to list of items generated by item providers with higher priority value (PageProvider)
* You could also modify existing items here.
* The new item is added after the 'info' item.
* @param array<string, mixed> $items
* @return array<string, mixed>
*/
public function addItems(array $items): array
{
Expand Down
2 changes: 2 additions & 0 deletions Classes/Controller/Haiku/DetailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class DetailController
* The back-reference to the mother cObj object set at call time
*/
private ContentObjectRenderer $cObj;
/** @var array<string, mixed> */
private array $conf = [];
private StandaloneView $view;

Expand All @@ -49,6 +50,7 @@ public function setContentObjectRenderer(ContentObjectRenderer $cObj): void
}

/**
* @param array<string, mixed> $conf
* @throws PropagateResponseException
*/
public function main(string $content, array $conf, ServerRequestInterface $request): string
Expand Down
6 changes: 6 additions & 0 deletions Classes/Controller/Haiku/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace T3docs\Examples\Controller\Haiku;

use Doctrine\DBAL\Exception;
use Psr\Http\Message\ServerRequestInterface;
use T3docs\Examples\Domain\Repository\HaikuRepository;
use T3docs\Examples\Service\FlexFormSettingsService;
Expand All @@ -27,6 +28,7 @@ final class ListController
* The back-reference to the mother cObj object set at call time
*/
private ContentObjectRenderer $cObj;
/** @var array<string, mixed> */
private array $conf = [];

public function __construct(
Expand All @@ -35,6 +37,10 @@ public function __construct(
private readonly StandaloneViewService $viewService,
) {}

/**
* @param array<string, mixed> $conf
* @throws Exception
*/
public function main(string $content, array $conf, ServerRequestInterface $request): string
{
$this->conf = $conf;
Expand Down
7 changes: 5 additions & 2 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ModuleController extends ActionController implements LoggerAwareInterface
use LoggerAwareTrait;

private int $pageUid;
/** @var array<string, mixed> */
private array $exampleConfig;

public function __construct(
Expand Down Expand Up @@ -210,7 +211,7 @@ public function debugAction(
return $view->renderResponse();
}

protected function debugCookies()
protected function debugCookies(): void
{
DebugUtility::debug($_COOKIE, 'cookie');
}
Expand Down Expand Up @@ -246,6 +247,7 @@ public function clipboardAction(

/**
* Debugs the content of the clipboard
* @return array<string, mixed>
*/
protected function getClipboard(string $identifier): array
{
Expand All @@ -264,6 +266,7 @@ protected function getClipboard(string $identifier): array

/**
* Debugs the content of the clipboard
* @return array<string, mixed>
*/
protected function getCurrentClipboard(): array
{
Expand All @@ -282,7 +285,7 @@ protected function getCurrentClipboard(): array
/**
* Debugs the content of the clipboard
*/
protected function debugClipboard()
protected function debugClipboard(): void
{
/** @var Clipboard $clipboard */
$clipboard = GeneralUtility::makeInstance(Clipboard::class);
Expand Down
8 changes: 4 additions & 4 deletions Classes/DataProcessing/CustomCategoryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class CustomCategoryProcessor implements DataProcessorInterface
* Process data for the content element "My new content element"
*
* @param ContentObjectRenderer $cObj The data of the content element or page
* @param array $contentObjectConfiguration The configuration of Content Object
* @param array $processorConfiguration The configuration of this processor
* @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
* @return array the processed data as key/value store
* @param array<string, mixed> $contentObjectConfiguration The configuration of Content Object
* @param array<string, mixed> $processorConfiguration The configuration of this processor
* @param array<string, mixed> $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
* @return array<string, mixed> the processed data as key/value store
*/
public function process(
ContentObjectRenderer $cObj,
Expand Down
4 changes: 4 additions & 0 deletions Classes/Domain/Repository/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

namespace T3docs\Examples\Domain\Repository;

use T3docs\Examples\Domain\Model\Category;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;

/**
* @extends Repository<Category>
*/
class CategoryRepository extends Repository
{
public function initializeObject(): void
Expand Down
13 changes: 11 additions & 2 deletions Classes/Domain/Repository/HaikuRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace T3docs\Examples\Domain\Repository;

use Doctrine\DBAL\Exception;
use T3docs\Examples\Exception\NoSuchHaikuException;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
Expand All @@ -32,6 +33,10 @@ public function __construct(
$this->connection = $connectionPool->getConnectionForTable(self::TABLENAME);
}

/**
* @return list<array<string,mixed>>
* @throws Exception
*/
public function findAll(): array
{
$queryBuilder = $this->connection->createQueryBuilder();
Expand All @@ -40,24 +45,28 @@ public function findAll(): array
}

/**
* @return array<string,mixed>
* @throws NoSuchHaikuException
* @throws Exception
*/
public function findByUid(int $uid): array
{
$queryBuilder = $this->connection->createQueryBuilder();
// $uid is an integer so we don't have to worry about SQL injections
// $uid is an integer, so we don't have to worry about SQL injections
$where = $queryBuilder->expr()->eq('uid', $uid);
$result = $queryBuilder->select('*')->from(self::TABLENAME)->where(
$where,
)->executeQuery()->fetchAssociative();
if (!$result) {
if ($result === false) {
throw new NoSuchHaikuException('Haiku with uid ' . $uid . 'not found.', 1664390495);
}
return $result;
}

/**
* @return array<string,mixed>
* @throws NoSuchHaikuException
* @throws Exception
*/
public function findByTitle(string $title): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserFactory;
use TYPO3\CMS\Core\DataHandling\SoftReference\SoftReferenceParserInterface;
use TYPO3\CMS\Linkvalidator\Event\BeforeRecordIsAnalyzedEvent;
use TYPO3\CMS\Linkvalidator\Repository\BrokenLinkRepository;

Expand Down Expand Up @@ -52,6 +53,11 @@ public function __invoke(BeforeRecordIsAnalyzedEvent $event): void
$event->setResults($results);
}

/**
* @param array<mixed> $record
* @param array<mixed> $results
* @return array<mixed>
*/
private function parseField(array $record, array $results): array
{
$conf = $GLOBALS['TCA'][self::TABLE_NAME]['columns'][self::FIELD_NAME]['config'];
Expand Down Expand Up @@ -79,6 +85,10 @@ private function parseField(array $record, array $results): array
return $results;
}

/**
* @param array<mixed> $conf
* @return SoftReferenceParserInterface[]
*/
private function findAllParsers(array $conf): iterable
{
return $this->softReferenceParserFactory->getParsersBySoftRefParserList(
Expand All @@ -87,6 +97,10 @@ private function findAllParsers(array $conf): iterable
);
}

/**
* @param array<mixed> $record
* @param array<mixed> $results
*/
private function matchUrl(string $foundUrl, array $record, array &$results): void
{
if (str_contains($foundUrl, self::LOCAL_DOMAIN)) {
Expand All @@ -95,6 +109,9 @@ private function matchUrl(string $foundUrl, array $record, array &$results): voi
}
}

/**
* @param array<string, scalar> $record
*/
private function addItemToBrokenLinkRepository(array $record, string $foundUrl): void
{
$link = [
Expand Down
3 changes: 3 additions & 0 deletions Classes/Form/Element/SpecialFieldElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

class SpecialFieldElement extends AbstractFormElement
{
/**
* @return array<mixed>
*/
public function render(): array
{
$row = $this->data['databaseRow'];
Expand Down
21 changes: 13 additions & 8 deletions Classes/LinkHandler/GitHubLinkHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class GitHubLinkHandler implements LinkHandlerInterface
*/
protected array $linkAttributes = ['target', 'title', 'class', 'params', 'rel'];

/** @var array<string, mixed> */
protected array $linkParts = [];

protected ViewInterface $view;

/** @var array<string, mixed> */
protected array $configuration;

public function __construct(
Expand All @@ -45,10 +47,13 @@ public function __construct(
* Initialize the handler
*
* @param string $identifier Key of the current page TSconfig configuration
* @param array $configuration Page TSconfig
* @param array<string, mixed> $configuration Page TSconfig
*/
public function initialize(AbstractLinkBrowserController $linkBrowser, $identifier, array $configuration): void
{
public function initialize(
AbstractLinkBrowserController $linkBrowser,
$identifier,
array $configuration,
): void {
$this->configuration = $configuration;
}

Expand All @@ -57,7 +62,7 @@ public function initialize(AbstractLinkBrowserController $linkBrowser, $identifi
*
* Also stores information locally about currently linked issue
*
* @param array $linkParts Link parts as returned from TypoLinkCodecService
* @param array<string, mixed> $linkParts Link parts as returned from TypoLinkCodecService
*/
public function canHandleLink(array $linkParts): bool
{
Expand Down Expand Up @@ -108,9 +113,9 @@ public function getBodyTagAttributes(): array
}

/**
* @return array
* @return array<string, mixed>
*/
public function getLinkAttributes()
public function getLinkAttributes(): array
{
return $this->linkAttributes;
}
Expand All @@ -119,7 +124,7 @@ public function getLinkAttributes()
* @param string[] $fieldDefinitions Array of link attribute field definitions
* @return string[]
*/
public function modifyLinkAttributes(array $fieldDefinitions)
public function modifyLinkAttributes(array $fieldDefinitions): array
{
return $fieldDefinitions;
}
Expand All @@ -129,7 +134,7 @@ public function modifyLinkAttributes(array $fieldDefinitions)
*
* @return bool
*/
public function isUpdateSupported()
public function isUpdateSupported(): bool
{
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions Classes/LinkHandler/GitHubLinkHandling.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class GitHubLinkHandling implements LinkHandlingInterface
{
/**
* The Base URN for this link handling to act on
* @var string
*/
protected $baseUrn = 't3://github';
protected string $baseUrn = 't3://github';

/**
* Returns a string interpretation of the link href query from objects,
Expand All @@ -39,6 +38,7 @@ class GitHubLinkHandling implements LinkHandlingInterface
* - mailto:[email protected]
*
* array of data -> string
* @param array<string, scalar> $parameters
*/
public function asString(array $parameters): string
{
Expand All @@ -51,6 +51,8 @@ public function asString(array $parameters): string
* representation.
*
* array of strings -> array of data
* @param array<string, scalar> $data
* @return array<string, scalar>
*/
public function resolveHandlerData(array $data): array
{
Expand Down
7 changes: 7 additions & 0 deletions Classes/LinkHandler/GithubLinkBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class GithubLinkBuilder extends AbstractTypolinkBuilder
{
private const TYPE_GITHUB = 'github';

/**
* @param array<mixed> $linkDetails parsed link details by the LinkService
* @param string $linkText the link text
* @param string $target the target to point to
* @param array<mixed> $conf the TypoLink configuration array
* @throws UnableToLinkException
*/
public function build(
array &$linkDetails,
string $linkText,
Expand Down
Loading

0 comments on commit 5445697

Please sign in to comment.