Skip to content

Commit d34f2ba

Browse files
committed
[TASK] Fix PHPStan errors
1 parent 267ded4 commit d34f2ba

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

Classes/Command/MaskToContentBlocksCommand.php

+24-7
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ public function __construct(
3737
protected TableDefinitionCollection $tableDefinitionCollection,
3838
protected PreviewIconResolver $previewIconResolver,
3939
protected ContentBlockBuilder $contentBlockBuilder,
40+
/**
41+
* @var array{content?: string, backend?: string}
42+
*/
4043
protected array $maskExtensionConfiguration,
4144
) {
4245
parent::__construct();
4346
}
4447

4548
public function execute(InputInterface $input, OutputInterface $output): int
4649
{
47-
$table = ContentType::CONTENT_ELEMENT->getTable();
50+
$table = 'tt_content';
4851
$targetExtension = $this->extractExtensionFromMaskConfiguration();
4952
if (!$this->tableDefinitionCollection->hasTable($table)) {
5053
$output->writeln('No Mask elements found.');
@@ -55,7 +58,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
5558
if ($element->hidden) {
5659
continue;
5760
}
58-
$fieldArray = $this->traverseMaskColumnsRecursive($element, $element->columns, $contentElementTableDefinition);
61+
/** @var string[] $columns */
62+
$columns = $element->columns;
63+
$fieldArray = $this->traverseMaskColumnsRecursive($element, $columns, $contentElementTableDefinition);
5964
$contentBlockName = str_replace('_', '-', $element->key);
6065
$name = 'mask/' . $contentBlockName;
6166
$path = 'EXT:' . $targetExtension . '/' . ContentBlockPathUtility::getRelativeContentElementsPath();
@@ -102,7 +107,7 @@ protected function extractExtensionFromMaskConfiguration(): string
102107
return $extensionKey;
103108
}
104109

105-
protected function copyFrontendTemplate(string $contentElementKey, $targetExtPath): void
110+
protected function copyFrontendTemplate(string $contentElementKey, string $targetExtPath): void
106111
{
107112
$absolutePath = GeneralUtility::getFileAbsFileName($targetExtPath);
108113
$absoluteTemplatePath = $absolutePath . '/' . ContentBlockPathUtility::getFrontendTemplatePath();
@@ -112,22 +117,23 @@ protected function copyFrontendTemplate(string $contentElementKey, $targetExtPat
112117
}
113118
}
114119

115-
protected function copyPreviewTemplate(string $contentElementKey, $targetExtPath): void
120+
protected function copyPreviewTemplate(string $contentElementKey, string $targetExtPath): void
116121
{
117122
$absolutePath = GeneralUtility::getFileAbsFileName($targetExtPath);
118123
$absoluteTemplatePath = $absolutePath . '/' . ContentBlockPathUtility::getBackendPreviewPath();
124+
$backendPreviewTemplatePath = (string)($this->maskExtensionConfiguration['backend'] ?? '');
119125
$maskPreviewTemplate = TemplatePathUtility::getTemplatePath(
120126
$this->maskExtensionConfiguration,
121127
$contentElementKey,
122128
false,
123-
GeneralUtility::getFileAbsFileName($this->maskExtensionConfiguration['backend'] ?? '')
129+
GeneralUtility::getFileAbsFileName($backendPreviewTemplatePath)
124130
);
125131
if (file_exists($maskPreviewTemplate)) {
126132
copy($maskPreviewTemplate, $absoluteTemplatePath);
127133
}
128134
}
129135

130-
protected function copyIcon(string $contentElementKey, $targetExtPath): void
136+
protected function copyIcon(string $contentElementKey, string $targetExtPath): void
131137
{
132138
$absolutePath = GeneralUtility::getFileAbsFileName($targetExtPath);
133139
$absoluteIconPath = $absolutePath . '/' . ContentBlockPathUtility::getIconPathWithoutFileExtension();
@@ -144,12 +150,20 @@ protected function copyIcon(string $contentElementKey, $targetExtPath): void
144150
}
145151
}
146152

153+
/**
154+
* @param string[] $columns
155+
* @return array<array<string, mixed>>
156+
*/
147157
protected function traverseMaskColumnsRecursive(ElementDefinition $element, array $columns, TableDefinition $tableDefinition): array
148158
{
149159
$fieldArray = [];
160+
if ($tableDefinition->tca === null) {
161+
return $fieldArray;
162+
}
150163
foreach ($columns as $fieldKey) {
151164
$field = [];
152165
$tcaFieldDefinition = $tableDefinition->tca->getField($fieldKey);
166+
/** @var array<string, mixed> $tca */
153167
$tca = $tcaFieldDefinition->realTca['config'] ?? [];
154168
unset($tca['type']);
155169
try {
@@ -194,6 +208,7 @@ protected function traverseMaskColumnsRecursive(ElementDefinition $element, arra
194208
$columnsOverrides = [];
195209
if ($element->hasColumnsOverride($fieldKey)) {
196210
$columnsOverrideTcaDefinition = $element->getColumnsOverride($fieldKey);
211+
/** @var array<string, mixed> $columnsOverrides */
197212
$columnsOverrides = $columnsOverrideTcaDefinition->realTca['config'] ?? [];
198213
}
199214
$field = array_merge($field, $tca, $columnsOverrides);
@@ -227,7 +242,9 @@ protected function traverseMaskColumnsRecursive(ElementDefinition $element, arra
227242
}
228243
if ($fieldType->isParentField()) {
229244
$inlineFields = $this->tableDefinitionCollection->loadInlineFields($fieldKey, $element->key, $element);
230-
$inlineColumns = array_map(fn (array $tcaField) => $tcaField['fullKey'], $inlineFields->toArray());
245+
/** @var array<array{fullKey: string}> $array */
246+
$array = $inlineFields->toArray();
247+
$inlineColumns = array_map(fn (array $tcaField): string => $tcaField['fullKey'], $array);
231248
$foreignTableDefinition = $tableDefinition;
232249
if ($fieldType === FieldType::INLINE) {
233250
unset($field['foreign_table']);

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"require-dev": {
3737
"typo3/cms-install": "^13.4",
3838
"typo3/cms-rte-ckeditor": "^13.4",
39-
"typo3/cms-lowlevel": "^13.4"
39+
"typo3/cms-lowlevel": "^13.4",
40+
"phpstan/phpstan": "^2.0"
4041
}
4142
}

0 commit comments

Comments
 (0)