Skip to content

Commit fb59efe

Browse files
committed
phpstan level 6
1 parent 545003c commit fb59efe

19 files changed

Lines changed: 129 additions & 59 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
"@test:database:postgres",
4242
"@test:database:sqlite"
4343
],
44-
"test:phpstan": "./vendor/bin/phpstan analyse data-access-kit/src data-access-kit-symfony/src --memory-limit=512M"
44+
"test:phpstan": "./vendor/bin/phpstan analyse --memory-limit=512M"
4545
}
4646
}

data-access-kit-symfony/src/DataAccessKitBundle.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public function configure(DefinitionConfigurator $definition): void
8888
->end();
8989
}
9090

91+
/**
92+
* @param array<string, mixed> $config
93+
*/
9194
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
9295
{
9396
$services = $container->services();
@@ -104,6 +107,9 @@ private function persistenceId(string $name): string
104107
return "data_access_kit.{$name}_persistence";
105108
}
106109

110+
/**
111+
* @param array<string, mixed> $config
112+
*/
107113
private function configureGlobalServices(array $config, ServicesConfigurator $services, ContainerBuilder $builder): void
108114
{
109115
$services->set($config["name_converter"])->autowire();
@@ -117,6 +123,9 @@ private function configureGlobalServices(array $config, ServicesConfigurator $se
117123
$services->alias(ValueConverterInterface::class, $config["value_converter"]);
118124
}
119125

126+
/**
127+
* @param array<string, mixed> $config
128+
*/
120129
private function configureDatabaseServices(array $config, ServicesConfigurator $services): void
121130
{
122131
foreach ($config["databases"] as $name => $database) {
@@ -130,6 +139,9 @@ private function configureDatabaseServices(array $config, ServicesConfigurator $
130139
}
131140
}
132141

142+
/**
143+
* @param array<string, mixed> $config
144+
*/
133145
private function configureRepositoryServices(array $config, ServicesConfigurator $services, ContainerBuilder $builder): void
134146
{
135147
$nameConverter = new $config["name_converter"]();
@@ -169,6 +181,9 @@ private function configureRepositoryServices(array $config, ServicesConfigurator
169181
}
170182
}
171183

184+
/**
185+
* @return array{0: \DataAccessKit\Repository\Result|null, 1: string|null}
186+
*/
172187
private function compileRepository(string $className, Compiler $compiler, ContainerBuilder $builder, string $outputDir, bool $debug): array
173188
{
174189
try {

data-access-kit/src/Attribute/Table.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#[Attribute(Attribute::TARGET_CLASS)]
99
class Table
1010
{
11+
/** @var ReflectionClass<object> */
1112
public ReflectionClass $reflection;
1213

1314
/** @var Column[] */
@@ -19,11 +20,17 @@ public function __construct(
1920
{
2021
}
2122

23+
/**
24+
* @param ReflectionClass<object> $reflection
25+
*/
2226
public function setReflection(ReflectionClass $reflection): void
2327
{
2428
$this->reflection = $reflection;
2529
}
2630

31+
/**
32+
* @param array<string, Column> $columns
33+
*/
2734
public function setColumns(array $columns): void
2835
{
2936
$this->columns = $columns;

data-access-kit/src/Converter/DefaultNameConverter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public function __construct()
1414
{
1515
}
1616

17+
/**
18+
* @param ReflectionClass<object>|string $reflection
19+
*/
1720
public function classToTable(ReflectionClass|string $reflection): string
1821
{
1922
if ($reflection instanceof ReflectionClass) {

data-access-kit/src/Converter/NameConverterInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
interface NameConverterInterface
99
{
1010
public function __construct();
11+
/**
12+
* @param ReflectionClass<object> $reflection
13+
*/
1114
public function classToTable(ReflectionClass $reflection): string;
1215
public function propertyToColumn(ReflectionProperty $reflection): string;
1316
}

data-access-kit/src/Persistence.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public function upsert(object|array $data, ?array $columns = null): void
8585
$this->doInsert($data, $columns);
8686
}
8787

88+
/**
89+
* @param array<object> $objects
90+
* @param array<string>|null $upsertColumns
91+
*/
8892
private function doInsert(array $objects, ?array $upsertColumns = null): void
8993
{
9094
if (count($objects) === 0) {
@@ -417,7 +421,7 @@ public function toRow(object $object): array
417421
return $row;
418422
}
419423

420-
private function determineValueType(mixed $value)
424+
private function determineValueType(mixed $value): ParameterType
421425
{
422426
return match (true) {
423427
is_bool($value) => ParameterType::BOOLEAN,

data-access-kit/src/PersistenceInterface.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function select(string $className, string $sql, array $parameters = []):
1919
* Run SELECT $sql with $parameters and return a scalar value.
2020
*
2121
* @param string $sql
22-
* @param array $parameters
22+
* @param array<int|string, mixed> $parameters
2323
* @return scalar
2424
*/
2525
public function selectScalar(string $sql, array $parameters = []): mixed;
@@ -28,42 +28,46 @@ public function selectScalar(string $sql, array $parameters = []): mixed;
2828
* Run INSERT, UPDATE, or DELETE $sql with $parameters and return the number of affected rows.
2929
*
3030
* @param string $sql
31-
* @param array $parameters
31+
* @param array<int|string, mixed> $parameters
3232
* @return int
3333
*/
3434
public function execute(string $sql, array $parameters = []): int;
3535

3636
/**
3737
* Insert data into the database.
3838
*
39-
* @param object|array $data
39+
* @param object|array<string, mixed> $data
4040
*/
4141
public function insert(object|array $data): void;
4242

4343
/**
4444
* Insert or update data in the database.
4545
*
46-
* @param object|array $data
46+
* @param object|array<string, mixed> $data
47+
* @param array<string>|null $columns
4748
*/
4849
public function upsert(object|array $data, ?array $columns = null): void;
4950

5051
/**
5152
* Update data in the database based on its primary key.
53+
*
54+
* @param object $data
55+
* @param array<string>|null $columns
5256
*/
5357
public function update(object $data, ?array $columns = null): void;
5458

5559
/**
5660
* Delete data from the database based on its primary key.
5761
*
58-
* @param object|array $data
62+
* @param object|array<string, mixed> $data
5963
*/
6064
public function delete(object|array $data): void;
6165

6266
/**
6367
* Convert $object to an associative array.
6468
*
6569
* @param object $object
66-
* @return array
70+
* @return array<string, mixed>
6771
*/
6872
public function toRow(object $object): array;
6973
}

data-access-kit/src/Registry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function get(object|string $objectOrClass, bool $requireTable = false): T
3636

3737
if (isset($this->tablesByClassName[$className])) {
3838
if ($requireTable && $this->tablesByClassName[$className]->name === null) {
39-
throw static::missingTableException($className);
39+
throw self::missingTableException($className);
4040
}
4141
return $this->tablesByClassName[$className];
4242
}
@@ -51,7 +51,7 @@ public function get(object|string $objectOrClass, bool $requireTable = false): T
5151
$tableRA = $rc->getAttributes(Table::class)[0] ?? null;
5252
if ($tableRA === null) {
5353
if ($requireTable) {
54-
throw static::missingTableException($className);
54+
throw self::missingTableException($className);
5555
}
5656

5757
$table = new Table();

data-access-kit/src/Repository/Attribute/Update.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#[Attribute(Attribute::TARGET_METHOD)]
88
class Update
99
{
10+
/**
11+
* @param array<string>|null $columns
12+
*/
1013
public function __construct(
1114
public readonly ?array $columns = null,
1215
)

data-access-kit/src/Repository/Attribute/Upsert.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#[Attribute(Attribute::TARGET_METHOD)]
88
class Upsert
99
{
10+
/**
11+
* @param array<string>|null $columns
12+
*/
1013
public function __construct(
1114
public readonly ?array $columns = null,
1215
)

0 commit comments

Comments
 (0)