Skip to content

Commit 1e00c81

Browse files
#11 Push to phpstan level 10
1 parent 82fe912 commit 1e00c81

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
'header_comment' => ['header' => $fileHeaderComment],
3636
'modernize_strpos' => true,
3737
'get_class_to_class_keyword' => true,
38+
'phpdoc_to_comment' => ['ignored_tags' => ['var']], // Fix issue on initializeStatement method $params variable
3839
])
3940
->setRiskyAllowed(true)
4041
->setFinder(

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 8
2+
level: 10
33
paths:
44
- src
55
- tests

src/Task/Database/DatabaseReaderTask.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* 'paginate': ?int,
3737
* 'offset': ?int,
3838
* 'input_as_params': bool,
39-
* 'params': array<int<0, max>|string, mixed>,
39+
* 'params': array<string, mixed>,
4040
* 'types': array<int, int|string|Type|null>|array<string, int|string|Type|null>
4141
* }
4242
*/
@@ -137,10 +137,13 @@ protected function initializeStatement(ProcessState $state): Result
137137
$sql = $qb->getSQL();
138138
}
139139

140-
/** @var array<string> $inputAsParams */
141140
$inputAsParams = $state->getInput();
142141
$params = $options['input_as_params'] ? $inputAsParams : $options['params'];
142+
if (!\is_array($params)) {
143+
throw new \UnexpectedValueException('Expecting an array of params');
144+
}
143145

146+
/** @var array<string, mixed> $params */
144147
return $connection->executeQuery($sql, $params, $options['types']);
145148
}
146149

@@ -186,8 +189,10 @@ protected function configureOptions(OptionsResolver $resolver): void
186189

187190
protected function getConnection(ProcessState $state): Connection
188191
{
192+
/** @var ?string $connectionOptions */
193+
$connectionOptions = $this->getOption($state, 'connection');
189194
/** @var Connection $connection */
190-
$connection = $this->doctrine->getConnection($this->getOption($state, 'connection'));
195+
$connection = $this->doctrine->getConnection($connectionOptions);
191196

192197
return $connection;
193198
}

src/Task/Database/DatabaseUpdaterTask.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @phpstan-type Options array{
3131
* 'sql': string,
3232
* 'input_as_params': bool,
33-
* 'params': mixed,
33+
* 'params': array<string, mixed>,
3434
* 'types': array<int, int|string|Type|null>|array<string, int|string|Type|null>
3535
* }
3636
*/
@@ -60,13 +60,13 @@ protected function initializeStatement(ProcessState $state): int
6060
$options = $this->getOptions($state);
6161
$connection = $this->getConnection($state);
6262

63-
/** @var array<string> $inputAsParams */
6463
$inputAsParams = $state->getInput();
6564
$params = $options['input_as_params'] ? $inputAsParams : $options['params'];
6665
if (!\is_array($params)) {
6766
throw new \UnexpectedValueException('Expecting an array of params');
6867
}
6968

69+
/** @var array<string, mixed> $params */
7070
return (int) $connection->executeStatement($options['sql'], $params, $options['types']);
7171
}
7272

@@ -88,8 +88,10 @@ protected function configureOptions(OptionsResolver $resolver): void
8888

8989
protected function getConnection(ProcessState $state): Connection
9090
{
91+
/** @var ?string $connectionOptions */
92+
$connectionOptions = $this->getOption($state, 'connection');
9193
/** @var Connection $connection */
92-
$connection = $this->doctrine->getConnection($this->getOption($state, 'connection'));
94+
$connection = $this->doctrine->getConnection($connectionOptions);
9395

9496
return $connection;
9597
}

src/Task/EntityManager/DoctrineBatchWriterTask.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public function flush(ProcessState $state): void
3434

3535
public function execute(ProcessState $state): void
3636
{
37-
$this->batch[] = $state->getInput();
37+
/** @var object $input */
38+
$input = $state->getInput();
39+
$this->batch[] = $input;
3840

3941
if (\count($this->batch) >= $this->getOption($state, 'batch_count')) {
4042
$this->writeBatch($state);

0 commit comments

Comments
 (0)