Skip to content

Commit

Permalink
[TASK] Fix code quality tools issues
Browse files Browse the repository at this point in the history
  • Loading branch information
richardkrikler authored and wazum committed Dec 16, 2024
1 parent 439aaf6 commit b9dc6fe
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Build/php-cs-fixer.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'declare_parentheses' => true,
'dir_constant' => true,
'ereg_to_preg' => true,
'escape_implicit_backslashes' => true,
'string_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'fopen_flags' => ['b_mode' => false],
Expand Down
15 changes: 10 additions & 5 deletions Build/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
cacheDirectory="../.Build/"
errorLevel="5"
hideExternalErrors="true"
phpVersion="8.1">
phpVersion="8.2">
<projectFiles>
<directory name="../" />
<directory name="../Classes" />
<ignoreFiles>
<directory name="../Build" />
<directory name="../.Build" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedClass>
<UnusedClass>
<errorLevel type="suppress">
<referencedClass name="Wazum\Sluggi\Upgrade\SlugLockUpgradeWizard" />
<directory name="../Classes"/>
</errorLevel>
</UndefinedClass>
</UnusedClass>
<UnusedParam>
<errorLevel type="suppress">
<directory name="../Classes/DataHandler"/>
</errorLevel>
</UnusedParam>
</issueHandlers>
</psalm>
15 changes: 14 additions & 1 deletion Classes/Backend/Form/InputSlugElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
final class InputSlugElement extends \TYPO3\CMS\Backend\Form\Element\InputSlugElement
{
/**
* @return array<array-key, mixed>
* @return array<string, mixed>
*/
public function render(): array
{
Expand All @@ -37,6 +37,11 @@ public function render(): array
return $result;
}

/**
* @param array<string, mixed> $result
*
* @return array<string, mixed>
*/
private function setStatusDataAttributes(array $result): array
{
$attributes = [
Expand All @@ -57,6 +62,11 @@ private function setStatusDataAttributes(array $result): array
return $result;
}

/**
* @param array<string, mixed> $result
*
* @return array<string, mixed>
*/
private function updateUiForRestrictedAccess(array $result): array
{
$languageId = $this->getLanguageId($this->data['tableName'], $this->data['databaseRow']);
Expand Down Expand Up @@ -84,6 +94,9 @@ private function updateUiForRestrictedAccess(array $result): array
return $result;
}

/**
* @param array<string, mixed> $row
*/
private function getLanguageId(string $table, array $row): int
{
if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
Expand Down
4 changes: 2 additions & 2 deletions Classes/Backend/Form/InputTextWithSlugImpactElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class InputTextWithSlugImpactElement extends InputTextElement
{
/**
* @return array<array-key, mixed>
* @return array<string, mixed>
*/
public function render(): array
{
Expand All @@ -22,7 +22,7 @@ public function render(): array
}

/**
* @return array<array-key, mixed>
* @return array<string, mixed>
*/
protected function renderWithImpactMark(): array
{
Expand Down
2 changes: 2 additions & 0 deletions Classes/Backend/PageRendererRenderPreProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ final class PageRendererRenderPreProcess
{
/**
* @param array<array-key, mixed> $params
*
* @psalm-suppress UnusedParam
*/
public function run(array $params, PageRenderer $pageRenderer): void
{
Expand Down
4 changes: 4 additions & 0 deletions Classes/Backend/SlugModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

final class SlugModifier extends \B13\Masi\SlugModifier
{
/**
* @param array<array-key, mixed> $configuration
* @param array<array-key, mixed> $record
*/
protected function resolveHookParameters(array $configuration, string $tableName, string $fieldName, int $pid, int $workspaceId, array $record): void
{
parent::resolveHookParameters($configuration, $tableName, $fieldName, $pid, $workspaceId, $record);
Expand Down
9 changes: 9 additions & 0 deletions Classes/DataHandler/HandleExcludeSlugForSubpages.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps

declare(strict_types=1);

namespace Wazum\Sluggi\DataHandler;
Expand Down Expand Up @@ -35,6 +37,8 @@ public function __construct(
}

/**
* @param array<string, mixed> $fields
*
* @throws \Exception
* @throws Exception
*/
Expand Down Expand Up @@ -76,6 +80,8 @@ public function processDatamap_afterDatabaseOperations(
/**
* Method copied from \TYPO3\CMS\Redirects\Service\SlugService.
*
* @return array<array-key, mixed>
*
* @throws \Exception
* @throws Exception
*/
Expand Down Expand Up @@ -163,6 +169,9 @@ private function disableHook(): void
unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['sluggi-exclude']);
}

/**
* @param array<string, mixed> $fields
*/
private function shouldRun(string $status, string $table, array $fields): bool
{
return 'update' === $status && 'pages' === $table && isset($fields['exclude_slug_for_subpages']);
Expand Down
17 changes: 15 additions & 2 deletions Classes/DataHandler/HandlePageCopy.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps

declare(strict_types=1);

namespace Wazum\Sluggi\DataHandler;
Expand Down Expand Up @@ -27,13 +29,16 @@ public function __construct()
);
}

/**
* @param array<array-key, mixed> $pasteDataMap
*/
public function processCmdmap_postProcess(
string $command,
string $table,
string|int $id,
$value,
string|int $value,
DataHandler $dataHandler,
$pasteUpdate,
bool $pasteUpdate,
array &$pasteDataMap,
): void {
if ('copy' !== $command || 'pages' !== $table) {
Expand Down Expand Up @@ -70,6 +75,9 @@ public function processCmdmap_postProcess(
}
}

/**
* @param array<array-key, mixed> $pasteDataMap
*/
private function handleAllChildPages(int $id, string $parentSlug, int $languageId, DataHandler $dataHandler, array &$pasteDataMap): void
{
foreach ($this->getChildPagesFor($id, $languageId) as $childPage) {
Expand All @@ -90,6 +98,11 @@ private function handleAllChildPages(int $id, string $parentSlug, int $languageI
}
}

/**
* @return array<array-key, array<string, mixed>>
*
* @throws \Doctrine\DBAL\Exception
*/
private function getChildPagesFor(int $parentPageId, int $languageId): array
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
Expand Down
11 changes: 10 additions & 1 deletion Classes/DataHandler/HandlePageMove.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps

declare(strict_types=1);

namespace Wazum\Sluggi\DataHandler;
Expand All @@ -13,6 +15,10 @@

final class HandlePageMove
{
/**
* @param array<string, mixed> $moveRecord
* @param array<string, mixed> $updateFields
*/
public function moveRecord_afterAnotherElementPostProcess(
/* @noinspection PhpUnusedParameterInspection */
string $table,
Expand All @@ -30,6 +36,10 @@ public function moveRecord_afterAnotherElementPostProcess(
$this->updateSlugForMovedPage($id, $targetId, $dataHandler);
}

/**
* @param array<string, mixed> $moveRecord
* @param array<string, mixed> $updateFields
*/
public function moveRecord_firstElementPostProcess(
/* @noinspection PhpUnusedParameterInspection */
string $table,
Expand Down Expand Up @@ -67,7 +77,6 @@ private function updateSlugForMovedPage(int $id, int $targetId, DataHandler $dat

$data = [];
$data['pages'][$id]['slug'] = $newSlug;
/** @var DataHandler $localDataHandler */
$localDataHandler = GeneralUtility::makeInstance(DataHandler::class);
$localDataHandler->start($data, []);
$localDataHandler->setCorrelationId($dataHandler->getCorrelationId());
Expand Down
8 changes: 6 additions & 2 deletions Classes/DataHandler/HandlePageUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public function processDatamap_preProcessFieldArray(
$fields = $this->prependInaccessibleSlugSegments($pageRecord, $fields);
}

/**
* @param array<string, mixed> $fields
*/
public function processDatamap_postProcessFieldArray(
string $status,
string $table,
Expand Down Expand Up @@ -173,7 +176,6 @@ private function mergePageRecordWithIncomingFields(array $pageRecord, array $fie
*/
private function regenerateSlug(array $pageRecord): string
{
/** @var SlugHelper $helper */
$helper = GeneralUtility::makeInstance(
SlugHelper::class,
'pages',
Expand Down Expand Up @@ -295,6 +297,9 @@ private function sanitizeSlug(string $slug): string
return '/' . ltrim($slug, '/');
}

/**
* @param array<string, mixed> $fields
*/
private function isManualUpdateWithOnlyLastSegmentAllowed(array $fields): bool
{
return isset($fields['slug']) && Configuration::get('last_segment_only') && !PermissionHelper::hasFullPermission();
Expand All @@ -308,7 +313,6 @@ private function isManualUpdateWithOnlyLastSegmentAllowed(array $fields): bool
*/
private function updateLastSegment(array $pageRecord, array $fields): array
{
/** @var SlugHelper $helper */
$helper = GeneralUtility::makeInstance(
SlugHelper::class,
'pages',
Expand Down
6 changes: 6 additions & 0 deletions Classes/Helper/PermissionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public static function hasFullPermission(): bool
return false;
}

/**
* @param array<string, mixed> $page
*/
public static function isLocked(array $page): bool
{
return (bool) $page['slug_locked'];
Expand All @@ -40,6 +43,9 @@ public static function hasSlugLockAccess(): bool
return self::getBackendUser()->check('non_exclude_fields', 'pages:slug_locked');
}

/**
* @return array<string, mixed>|null
*/
public static function getTopmostAccessiblePage(int $pageId): ?array
{
$rootLine = BackendUtility::BEgetRootLine(
Expand Down
7 changes: 6 additions & 1 deletion Classes/Service/SlugService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

final class SlugService extends \TYPO3\CMS\Redirects\Service\SlugService
{
/**
* @psalm-suppress PossiblyUnusedMethod
*/
public function __construct(
Context $context,
PageRepository $pageRepository,
Expand All @@ -36,7 +39,9 @@ public function __construct(
}

/**
* @return string[] all unique source hosts for created redirects
* @param array<array-key, mixed> $currentPageRecord
*
* @return string[]
*/
protected function checkSubPages(array $currentPageRecord, SlugRedirectChangeItem $parentChangeItem): array
{
Expand Down
3 changes: 3 additions & 0 deletions Classes/Upgrade/SlugLockUpgradeWizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function updateNecessary(): bool
return false;
}

/**
* @return string[]
*/
public function getPrerequisites(): array
{
return [
Expand Down

0 comments on commit b9dc6fe

Please sign in to comment.