Skip to content

Commit

Permalink
Fix rector and ecs messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Tepper committed Mar 7, 2024
1 parent 7ab6100 commit 508c045
Show file tree
Hide file tree
Showing 21 changed files with 249 additions and 386 deletions.
30 changes: 0 additions & 30 deletions .code-quality/rector-8_0.php

This file was deleted.

2 changes: 2 additions & 0 deletions .code-quality/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
use Rector\Set\ValueObject\SetList;
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
Expand Down Expand Up @@ -38,6 +39,7 @@
TypedPropertyFromStrictSetUpRector::class,
AddMethodCallBasedStrictParamTypeRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
YieldDataProviderRector::class,
])
->withAutoloadPaths([__DIR__ . '/../Classes'])
->registerService(RemoveUnusedPrivatePropertyRector::class);
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Build/testing-docker/.env
/typo3_src
/typo3conf
/vendor
/phpstan-baseline.neon
20 changes: 4 additions & 16 deletions Classes/Domain/Model/Footnote.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ class Footnote extends AbstractEntity

protected ?string $description = null;

/**
* @param string $description
*/
public function setDescription($description): void
public function setDescription(?string $description): void
{
$this->description = $description;
}
Expand All @@ -55,10 +52,7 @@ public function getDescription(): ?string
return $this->description;
}

/**
* @param string $header
*/
public function setHeader($header): void
public function setHeader(?string $header): void
{
$this->header = $header;
}
Expand All @@ -68,10 +62,7 @@ public function getHeader(): ?string
return $this->header;
}

/**
* @param integer $index
*/
public function setIndexNumber($index): void
public function setIndexNumber(?int $index): void
{
$this->indexNumber = $index;
}
Expand All @@ -81,10 +72,7 @@ public function getIndexNumber(): ?int
return $this->indexNumber;
}

/**
* @param string $title
*/
public function setTitle($title): void
public function setTitle(?string $title): void
{
$this->title = $title;
}
Expand Down
20 changes: 10 additions & 10 deletions Classes/Domain/Repository/FootnoteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class FootnoteRepository extends Repository

protected string $tableName = 'tx_happyfeet_domain_model_footnote';


public function initializeObject(): void
{
/** @var Typo3QuerySettings $defaultQuerySettings */
Expand All @@ -62,10 +61,8 @@ public function initializeObject(): void

/**
* Returns the smallest index which is not used.
*
* @return integer
*/
public function getLowestFreeIndexNumber()
public function getLowestFreeIndexNumber(): int
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
Expand All @@ -84,16 +81,19 @@ public function getLowestFreeIndexNumber()
if (count($results) < 1) {
return $index;
}

$indexes = [];
foreach ($results as $result) {
$indexes[] = (int) $result['index_number'];
}

$indexCount = count($indexes);
for ($index = 1; $index <= $indexCount + 1; $index++) {
for ($index = 1; $index <= $indexCount + 1; ++$index) {
if (!in_array($index, $indexes, true)) {
break;
}
}

return $index;
}

Expand All @@ -110,6 +110,7 @@ public function add($object): void
1392911702
);
}

$object->setIndexNumber($this->getLowestFreeIndexNumber());
parent::add($object);
}
Expand Down Expand Up @@ -150,21 +151,20 @@ public function sortFootnotesByUids($queryResult, $uids)
if ($queryResult instanceof QueryResultInterface) {
$queryResult = $queryResult->toArray();
}
usort($queryResult, [$this, 'usortFootnotesByUids']);

usort($queryResult, fn (Footnote $a, Footnote $b): int => $this::usortFootnotesByUids($a, $b));
return $queryResult;
}

/**
* @return integer
*/
public static function usortFootnotesByUids(
Footnote $a,
Footnote $b
) {
): int {
$map = array_flip(self::$uids);
if ($map[$a->getUid()] >= $map[$b->getUid()]) {
return 1;
}

return -1;
}
}
6 changes: 4 additions & 2 deletions Classes/Service/FCEFootnoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,28 @@ public function __construct(RenderingService $renderingService)
}

/**
* @param string $content
* @param array $conf optional (this will be automatically set, of this method is called via 'TYPOSCRIPT-userFunc')
* @return ?string The wrapped index value
* @throws UnexpectedValueException
*/
public function renderItemList($content, $conf = [])
public function renderItemList(string $content, array $conf = []): ?string
{
if (!array_key_exists('userFunc', $conf) || !array_key_exists('field', $conf)) {
return '';
}

if (array_key_exists('isGridElement', $conf) && (bool) $conf['isGridElement']) {
$footnoteUids = $this->getCObj()
->data['pi_flexform']['data']['sDEF']['lDEF'][$conf['field']]['vDEF'];
} else {
$footnoteUids = $this->getCObj()
->getCurrentVal();
}

if (empty($footnoteUids)) {
return '';
}

return $this->renderingService->renderFootnotes(explode(',', $footnoteUids));
}

Expand Down
17 changes: 6 additions & 11 deletions Classes/Service/RenderingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ public function __construct(FootnoteRepository $footnoteRepository)
*/
public function renderFootnotes(array $uids, array $conf = []): ?string
{
if (empty($uids)) {
if ($uids === []) {
return '';
}

$footnotes = $this->footnoteRepository->getFootnotesByUids($uids);
if (count($footnotes) < 1) {
return '';
}

/** @var Footnote $footnote */
foreach ($footnotes as $footnote) {
if ($footnote instanceof Footnote) {
Expand Down Expand Up @@ -104,25 +106,18 @@ protected function getContentObjectRenderer(): ContentObjectRenderer
if ($this->contentObjectRenderer === null) {
$this->contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
}

return $this->contentObjectRenderer;
}

/**
* @param string $template
* @return \TYPO3\CMS\Fluid\View\StandaloneView
*/
private function createView($template)
private function createView(string $template): StandaloneView
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($template));
return $view;
}

/**
* @param string $template
* @return string
*/
private function getTemplatePathAndFilename($template)
private function getTemplatePathAndFilename(string $template): string
{
return 'EXT:happy_feet/Resources/Private/Templates/Rendering/' . $template . '.html';
}
Expand Down
3 changes: 2 additions & 1 deletion Classes/Typo3/Hook/LinkHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\LinkHandling\LinkHandlingInterface;
use InvalidArgumentException;
use TYPO3\CMS\Core\LinkHandling\LinkHandlingInterface;

/**
* Linkhandler hook to manipulate link data before it is processed by core typolink method.
Expand All @@ -44,6 +44,7 @@ public function asString(array $parameters): string
if (empty($parameters['uid'])) {
throw new \InvalidArgumentException('The HappyFeetLinkHandler expects uid as $parameter configuration.', 1486155150);
}

$urn = $this->baseUrn;
$urn .= sprintf('?uid=%s', $parameters['uid']);

Expand Down
4 changes: 0 additions & 4 deletions Classes/Typo3/Hook/LinkRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class LinkRenderer extends AbstractTypolinkBuilder
{
private ?RenderingService $renderingService = null;

/**
* @param TypoScriptFrontendController|null $typoScriptFrontendController
*/
public function __construct(
ContentObjectRenderer $contentObjectRenderer,
TypoScriptFrontendController $typoScriptFrontendController = null,
Expand All @@ -26,7 +23,6 @@ public function __construct(
}

/**
* @inheritDoc
* @throws UnableToLinkException
*/
public function build(array &$linkDetails, string $linkText, string $target, array $conf): array
Expand Down
22 changes: 7 additions & 15 deletions Classes/Typo3/Hook/LinkWizzard.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
*/
final class LinkWizzard extends AbstractLinkHandler implements LinkHandlerInterface, LinkParameterProviderInterface
{
/**
* Configuration key in TSconfig TCEMAIN.linkHandler.record
*/
private string $identifier;

/**
* Specific TSconfig for the current instance (corresponds to TCEMAIN.linkHandler.record.identifier.configuration)
*/
Expand All @@ -53,13 +48,11 @@ final class LinkWizzard extends AbstractLinkHandler implements LinkHandlerInterf
/**
* Initializes the handler.
*
* @param string $identifier
* @param array $configuration Page TSconfig
*/
public function initialize(AbstractLinkBrowserController $linkBrowser, $identifier, array $configuration): void
public function initialize(AbstractLinkBrowserController $linkBrowser, mixed $identifier, array $configuration): void
{
parent::initialize($linkBrowser, $identifier, $configuration);
$this->identifier = $identifier;
$this->configuration = $configuration;
}

Expand All @@ -72,10 +65,8 @@ public function initialize(AbstractLinkBrowserController $linkBrowser, $identifi
*/
public function canHandleLink(array $linkParts): bool
{
if (isset($linkParts['type'])) {
if ($linkParts['type'] === null || strcmp($linkParts['type'], 'happy_feet') !== 0) {
return false;
}
if (isset($linkParts['type']) && ($linkParts['type'] == null || strcmp($linkParts['type'], 'happy_feet') !== 0)) {
return false;
}

if (!$linkParts['url']) {
Expand All @@ -94,6 +85,7 @@ public function canHandleLink(array $linkParts): bool
$linkParts['pid'] = (int) $record['pid'];
$linkParts['title'] = isset($linkParts['title']) ?: BackendUtility::getRecordTitle($table, $record);
}

$linkParts['url']['type'] = $linkParts['type'];
$this->linkParts = $linkParts;

Expand Down Expand Up @@ -151,7 +143,7 @@ public function render(ServerRequestInterface $request): string
'treeActions' => ['link'],
]);

$this->view->setTemplate('Record');
#$this->view->setTemplate('Record');
return '';
}

Expand All @@ -165,7 +157,7 @@ public function getBodyTagAttributes(): array
$attributes = [
'data-identifier' => 't3://happy_feet?uid=',
];
if (!empty($this->linkParts)) {
if ($this->linkParts !== []) {
$attributes['data-current-link'] = GeneralUtility::makeInstance(LinkService::class)->asString($this->linkParts['url']);
}

Expand Down Expand Up @@ -200,7 +192,7 @@ public function getUrlParameters(array $values): array
*/
public function isCurrentlySelectedItem(array $values): bool
{
return !empty($this->linkParts) && (int) $this->linkParts['pid'] === (int) $values['pid'];
return $this->linkParts !== [] && (int) $this->linkParts['pid'] === (int) $values['pid'];
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Classes/Typo3/Hook/Tcemain.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public function processDatamap_postProcessFieldArray($status, $table, $id, array
if ($table !== 'tx_happyfeet_domain_model_footnote') {
return;
}

if ($status === 'new') {
$fieldArray['index_number'] = $this->footnoteRepository->getLowestFreeIndexNumber();
}

if ($status === 'delete') {
$fieldArray['index_number'] = 0;
}
Expand Down
11 changes: 3 additions & 8 deletions Classes/ViewHelpers/FlatifyViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,14 @@
*/
class FlatifyViewHelper extends AbstractViewHelper
{
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* @param string|null $str
* @return string
*/
public function render($str = null)

public function render(?string $str = null): string
{
if ($str === null) {
$str = $this->renderChildren();
}

return str_replace(["\r", "\n"], '', $str);
}
}
Loading

0 comments on commit 508c045

Please sign in to comment.