Skip to content

Commit 1fa57ee

Browse files
authored
IBX-9727: Added missing type hints (#76)
1 parent 1dd7c7a commit 1fa57ee

27 files changed

+174
-345
lines changed

phpstan-baseline.neon

Lines changed: 12 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,20 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: '#^Cannot access offset ''entries'' on array\|bool\|float\|int\|string\|null\.$#'
5-
identifier: offsetAccess.nonOffsetAccessible
6-
count: 1
7-
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
8-
9-
-
10-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) has parameter \$cells with no value type specified in iterable type array\.$#'
11-
identifier: missingType.iterableValue
12-
count: 1
13-
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
14-
15-
-
16-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) has parameter \$columns with no value type specified in iterable type array\.$#'
17-
identifier: missingType.iterableValue
18-
count: 1
19-
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
20-
21-
-
22-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) return type has no value type specified in iterable type array\.$#'
23-
identifier: missingType.iterableValue
4+
message: '#^Binary operation "%%" between int\|string and int\<0, max\> results in an error\.$#'
5+
identifier: binaryOp.invalid
246
count: 1
257
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
268

279
-
28-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:getContentClassAttributes\(\) return type has no value type specified in iterable type array\.$#'
29-
identifier: missingType.iterableValue
10+
message: '#^Cannot access offset ''entries'' on array\|bool\|float\|int\|string\|null\.$#'
11+
identifier: offsetAccess.nonOffsetAccessible
3012
count: 1
3113
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
3214

3315
-
34-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:getContentObjectAttributes\(\) return type has no value type specified in iterable type array\.$#'
35-
identifier: missingType.iterableValue
16+
message: '#^Cannot access property \$identifier on array\<string, mixed\>\.$#'
17+
identifier: property.nonObject
3618
count: 1
3719
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
3820

@@ -43,115 +25,19 @@ parameters:
4325
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
4426

4527
-
46-
message: '#^Parameter \#1 \$input of static method Symfony\\Component\\Yaml\\Yaml\:\:parse\(\) expects string, string\|false given\.$#'
47-
identifier: argument.type
48-
count: 1
49-
path: src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php
50-
51-
-
52-
message: '#^Property Ibexa\\Core\\Persistence\\Legacy\\Content\\StorageFieldDefinition\:\:\$dataText5 \(string\) on left side of \?\? is not nullable\.$#'
53-
identifier: nullCoalesce.property
54-
count: 1
55-
path: src/lib/FieldType/Converter/MatrixConverter.php
56-
57-
-
58-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__construct\(\) has parameter \$cells with no value type specified in iterable type array\.$#'
59-
identifier: missingType.iterableValue
60-
count: 1
61-
path: src/lib/FieldType/Value/Row.php
62-
63-
-
64-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__get\(\) has no return type specified\.$#'
65-
identifier: missingType.return
28+
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Mapper\\MatrixFormMapper\:\:mapFieldDefinitionForm\(\) has parameter \$fieldDefinitionForm with generic interface Symfony\\Component\\Form\\FormInterface but does not specify its types\: TData$#'
29+
identifier: missingType.generics
6630
count: 1
67-
path: src/lib/FieldType/Value/Row.php
31+
path: src/lib/FieldType/Mapper/MatrixFormMapper.php
6832

6933
-
70-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__get\(\) has parameter \$name with no type specified\.$#'
71-
identifier: missingType.parameter
34+
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Mapper\\MatrixFormMapper\:\:mapFieldValueForm\(\) has parameter \$fieldForm with generic interface Symfony\\Component\\Form\\FormInterface but does not specify its types\: TData$#'
35+
identifier: missingType.generics
7236
count: 1
73-
path: src/lib/FieldType/Value/Row.php
74-
75-
-
76-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__isset\(\) has parameter \$name with no type specified\.$#'
77-
identifier: missingType.parameter
78-
count: 1
79-
path: src/lib/FieldType/Value/Row.php
80-
81-
-
82-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:getCells\(\) return type has no value type specified in iterable type array\.$#'
83-
identifier: missingType.iterableValue
84-
count: 1
85-
path: src/lib/FieldType/Value/Row.php
37+
path: src/lib/FieldType/Mapper/MatrixFormMapper.php
8638

8739
-
8840
message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(string\)\: bool\)\|null, ''strlen'' given\.$#'
8941
identifier: argument.type
9042
count: 1
9143
path: src/lib/FieldType/Value/Row.php
92-
93-
-
94-
message: '#^Property Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:\$cells type has no value type specified in iterable type array\.$#'
95-
identifier: missingType.iterableValue
96-
count: 1
97-
path: src/lib/FieldType/Value/Row.php
98-
99-
-
100-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\InputHandler\:\:toFieldValue\(\) has parameter \$input with no type specified\.$#'
101-
identifier: missingType.parameter
102-
count: 1
103-
path: src/lib/GraphQL/InputHandler.php
104-
105-
-
106-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\InputHandler\:\:toFieldValue\(\) has parameter \$inputFormat with no type specified\.$#'
107-
identifier: missingType.parameter
108-
count: 1
109-
path: src/lib/GraphQL/InputHandler.php
110-
111-
-
112-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:canWork\(\) has parameter \$args with no value type specified in iterable type array\.$#'
113-
identifier: missingType.iterableValue
114-
count: 1
115-
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php
116-
117-
-
118-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:typeName\(\) has parameter \$args with no value type specified in iterable type array\.$#'
119-
identifier: missingType.iterableValue
120-
count: 1
121-
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php
122-
123-
-
124-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:work\(\) has parameter \$args with no value type specified in iterable type array\.$#'
125-
identifier: missingType.iterableValue
126-
count: 1
127-
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php
128-
129-
-
130-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:canWork\(\) has parameter \$args with no value type specified in iterable type array\.$#'
131-
identifier: missingType.iterableValue
132-
count: 1
133-
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php
134-
135-
-
136-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:typeName\(\) has parameter \$args with no value type specified in iterable type array\.$#'
137-
identifier: missingType.iterableValue
138-
count: 1
139-
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php
140-
141-
-
142-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:work\(\) has parameter \$args with no value type specified in iterable type array\.$#'
143-
identifier: missingType.iterableValue
144-
count: 1
145-
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php
146-
147-
-
148-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\SilentRow\:\:__get\(\) has no return type specified\.$#'
149-
identifier: missingType.return
150-
count: 1
151-
path: src/lib/GraphQL/SilentRow.php
152-
153-
-
154-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\SilentRow\:\:__get\(\) has parameter \$name with no type specified\.$#'
155-
identifier: missingType.parameter
156-
count: 1
157-
path: src/lib/GraphQL/SilentRow.php

src/bundle/Command/MigrateLegacyMatrixCommand.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,18 @@
2727
use Symfony\Component\Console\Style\SymfonyStyle;
2828

2929
#[AsCommand(name: 'ibexa:migrate:legacy_matrix')]
30-
class MigrateLegacyMatrixCommand extends Command
30+
final class MigrateLegacyMatrixCommand extends Command
3131
{
32-
private const DEFAULT_ITERATION_COUNT = 1000;
33-
private const EZMATRIX_IDENTIFIER = 'ezmatrix';
34-
private const CONFIRMATION_ANSWER = 'yes';
32+
private const int DEFAULT_ITERATION_COUNT = 1000;
33+
private const string IBEXA_MATRIX_IDENTIFIER = 'ibexa_matrix';
34+
private const string CONFIRMATION_ANSWER = 'yes';
3535

36-
private Connection $connection;
37-
38-
/**
39-
* @param \Doctrine\DBAL\Connection $connection
40-
*/
4136
public function __construct(
42-
Connection $connection
37+
private readonly Connection $connection
4338
) {
44-
$this->connection = $connection;
45-
4639
parent::__construct();
4740
}
4841

49-
/**
50-
* {@inheritdoc}
51-
*/
5242
protected function configure(): void
5343
{
5444
$this
@@ -66,9 +56,6 @@ protected function configure(): void
6656
);
6757
}
6858

69-
/**
70-
* {@inheritdoc}
71-
*/
7259
public function execute(InputInterface $input, OutputInterface $output): int
7360
{
7461
$io = new SymfonyStyle($input, $output);
@@ -84,7 +71,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
8471
}
8572
}
8673

87-
$io->comment('Migrating legacy ezmatrix fieldtype');
74+
$io->comment('Migrating legacy ibexa_matrix fieldtype');
8875

8976
$iterationCount = (int)$input->getOption('iteration-count');
9077
$converter = new MatrixConverter();
@@ -94,13 +81,19 @@ public function execute(InputInterface $input, OutputInterface $output): int
9481
libxml_use_internal_errors(true);
9582

9683
foreach ($contentClassAttributes as $contentClassAttribute) {
97-
$io->comment(sprintf('Migrate %s:%s attribute.', $contentClassAttribute['contenttype_identifier'], $contentClassAttribute['identifier']));
84+
$io->comment(
85+
sprintf(
86+
'Migrate %s:%s attribute.',
87+
$contentClassAttribute['contenttype_identifier'],
88+
$contentClassAttribute['identifier']
89+
)
90+
);
9891

9992
try {
10093
$xml = new SimpleXMLElement((string)$contentClassAttribute['columns']);
10194

10295
$isValidXml = true;
103-
} catch (Exception $e) {
96+
} catch (Exception) {
10497
$isValidXml = false;
10598
}
10699

@@ -128,8 +121,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
128121

129122
$this->updateContentClassAttribute(
130123
(int)$contentClassAttribute['id'],
131-
(int)$storageFieldDefinition->dataInt1,
132-
(string)$storageFieldDefinition->dataText5
124+
$storageFieldDefinition->dataInt1,
125+
$storageFieldDefinition->dataText5
133126
);
134127

135128
$columnsJson = $storageFieldDefinition->dataText5;
@@ -142,7 +135,14 @@ public function execute(InputInterface $input, OutputInterface $output): int
142135
);
143136

144137
if ($contentAttributesCount === 0) {
145-
$io->comment(sprintf('Zero instances of %s:%s attribute to migrate.', $contentClassAttribute['contenttype_identifier'], $contentClassAttribute['identifier']));
138+
$io->comment(
139+
sprintf(
140+
'Zero instances of %s:%s attribute to migrate.',
141+
$contentClassAttribute['contenttype_identifier'],
142+
$contentClassAttribute['identifier']
143+
)
144+
);
145+
146146
continue;
147147
}
148148

@@ -165,7 +165,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
165165
$xml = new SimpleXMLElement(
166166
(string)$contentObjectAttribute['data_text']
167167
);
168-
} catch (Exception $e) {
168+
} catch (Exception) {
169169
$progressBar->advance();
170170

171171
continue;
@@ -186,7 +186,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
186186

187187
$this->updateContentObjectAttribute(
188188
(int)$contentObjectAttribute['id'],
189-
(string)$storageFieldValue->dataText
189+
$storageFieldValue->dataText
190190
);
191191

192192
$progressBar->advance();
@@ -206,10 +206,10 @@ public function execute(InputInterface $input, OutputInterface $output): int
206206
}
207207

208208
/**
209-
* @param array $cells
210-
* @param array $columns
209+
* @param array<string|int, mixed> $cells
210+
* @param list<array<string, mixed>> $columns
211211
*
212-
* @return array
212+
* @return list<array<string, string>>
213213
*/
214214
private function convertCellsToRows(array $cells, array $columns): array
215215
{
@@ -223,7 +223,7 @@ private function convertCellsToRows(array $cells, array $columns): array
223223

224224
$row[$columnIdentifier] = (string)$cell;
225225

226-
if ($columnIndex === $columnsCount - 1) {
226+
if ($columnIndex == $columnsCount - 1) {
227227
$rows[] = $row;
228228
$row = [];
229229
}
@@ -233,7 +233,7 @@ private function convertCellsToRows(array $cells, array $columns): array
233233
}
234234

235235
/**
236-
* @return array
236+
* @return list<array<string,mixed>>
237237
*/
238238
private function getContentClassAttributes(): array
239239
{
@@ -249,7 +249,7 @@ private function getContentClassAttributes(): array
249249
->from(ContentTypeGateway::FIELD_DEFINITION_TABLE, 'attr')
250250
->join('attr', ContentTypeGateway::CONTENT_TYPE_TABLE, 'class', 'class.id = attr.content_type_id')
251251
->where('attr.data_type_string = :identifier')
252-
->setParameter('identifier', self::EZMATRIX_IDENTIFIER);
252+
->setParameter('identifier', self::IBEXA_MATRIX_IDENTIFIER);
253253

254254
return $query->executeQuery()->fetchAllAssociative();
255255
}
@@ -282,7 +282,7 @@ private function getContentObjectAttributesCount(int $id): int
282282
}
283283

284284
/**
285-
* @return array
285+
* @return list<array<string, mixed>>
286286
*/
287287
private function getContentObjectAttributes(int $id, int $offset, int $iterationCount): array
288288
{

src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
1717
use Symfony\Component\Yaml\Yaml;
1818

19-
class IbexaFieldTypeMatrixExtension extends Extension implements PrependExtensionInterface
19+
final class IbexaFieldTypeMatrixExtension extends Extension implements PrependExtensionInterface
2020
{
2121
public function load(array $configs, ContainerBuilder $container): void
2222
{
@@ -39,7 +39,7 @@ public function prepend(ContainerBuilder $container): void
3939
public function prependKernelSettings(ContainerBuilder $container): void
4040
{
4141
$configFile = __DIR__ . '/../Resources/config/kernel.yaml';
42-
$config = Yaml::parse(file_get_contents($configFile));
42+
$config = Yaml::parseFile($configFile);
4343
$container->prependExtensionConfig('ibexa', $config);
4444
$container->addResource(new FileResource($configFile));
4545
}

src/bundle/IbexaFieldTypeMatrixBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
use Symfony\Component\HttpKernel\Bundle\Bundle;
1212

13-
class IbexaFieldTypeMatrixBundle extends Bundle
13+
final class IbexaFieldTypeMatrixBundle extends Bundle
1414
{
1515
}

0 commit comments

Comments
 (0)