Skip to content

Commit 20d1415

Browse files
committed
phpstan level 6, fix remaining cs
1 parent 50d0be5 commit 20d1415

10 files changed

Lines changed: 63 additions & 44 deletions

File tree

lib/GaletteAuto/AbstractObject.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public function __construct(Db $zdb, string $table, string $pk, string $field, s
7676

7777
/**
7878
* Get the list
79+
*
80+
* @return array<int, array<string,mixed>>
7981
*/
8082
public function getList(): array
8183
{

lib/GaletteAuto/Auto.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Auto
6969
private Plugins $plugins;
7070
private Db $zdb;
7171

72+
/** @var array<string, string> */
7273
private array $fields = [
7374
'id_car' => 'integer',
7475
'car_name' => 'string',
@@ -92,6 +93,7 @@ class Auto
9293
Adherent::PK => 'integer'
9394
];
9495

96+
/** @var array<string, int> */
9597
private array $required = [
9698
'name' => 1,
9799
'model' => 1,
@@ -145,7 +147,9 @@ class Auto
145147
//do we have to fire a history entry?
146148
private bool $fire_history = false;
147149

148-
//internal properties (not updatable outside the object)
150+
/**
151+
* @var array<string> internal properties (not updatable outside the object)
152+
*/
149153
private array $internals = [
150154
'id',
151155
'creation_date',
@@ -158,14 +162,15 @@ class Auto
158162
'plugins',
159163
'zdb'
160164
];
165+
/** @var array<int, string> */
161166
private array $errors = [];
162167

163168
/**
164169
* Default constructor
165170
*
166-
* @param Plugins $plugins Plugins
167-
* @param Db $zdb Database instance
168-
* @param ?ArrayObject $args A resultset row to load
171+
* @param Plugins $plugins Plugins
172+
* @param Db $zdb Database instance
173+
* @param ?ArrayObject<string, int|string> $args A resultset row to load
169174
*/
170175
public function __construct(Plugins $plugins, Db $zdb, ?ArrayObject $args = null)
171176
{
@@ -241,7 +246,7 @@ public function load(int $id): bool
241246
/**
242247
* Populate object from a resultset row
243248
*
244-
* @param ArrayObject $r a resultset row
249+
* @param ArrayObject<string, int|string> $r a resultset row
245250
*/
246251
private function loadFromRS(ArrayObject $r): void
247252
{
@@ -281,6 +286,8 @@ private function loadFromRS(ArrayObject $r): void
281286

282287
/**
283288
* Return the list of available fuels
289+
*
290+
* @return array<int, string> List of fuels
284291
*/
285292
public function listFuels(): array
286293
{
@@ -448,11 +455,13 @@ public function store(bool $new = false): bool
448455
*
449456
* @param bool $restrict true to exclude $this->internals from returned
450457
* result, false otherwise. Default to false
458+
*
459+
* @return array<string> List of properties
451460
*/
452461
private function getAllProperties(bool $restrict = false): array
453462
{
454463
$result = [];
455-
foreach (get_class_vars(static::class) as $key => $value) {
464+
foreach (array_keys(get_class_vars(static::class)) as $key) {
456465
if (
457466
!$restrict
458467
|| !in_array($key, $this->internals)
@@ -466,6 +475,8 @@ private function getAllProperties(bool $restrict = false): array
466475
/**
467476
* Get object's properties. List only properties that can be modified
468477
* externally (ie. not in $this->internals)
478+
*
479+
* @return array<string> List of properties
469480
*/
470481
public function getProperties(): array
471482
{
@@ -637,8 +648,8 @@ public function __isset(string $name): bool
637648
/**
638649
* Check posted values validity
639650
*
640-
* @param array $post All values to check, basically the $_POST array
641-
* after sending the form
651+
* @param array<string,mixed> $post All values to check, basically the $_POST array
652+
* after sending the form
642653
*/
643654
public function check(array $post): bool
644655
{
@@ -787,6 +798,8 @@ public function check(array $post): bool
787798

788799
/**
789800
* Get errors
801+
*
802+
* @return array<string>
790803
*/
791804
public function getErrors(): array
792805
{
@@ -795,6 +808,8 @@ public function getErrors(): array
795808

796809
/**
797810
* Get required fields
811+
*
812+
* @return array<string,int>
798813
*/
799814
public function getRequired(): array
800815
{

lib/GaletteAuto/Autos.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(Plugins $plugins, Db $zdb)
6161
/**
6262
* Remove specified vehicles
6363
*
64-
* @param int|array $ids Vehicles identifiers to delete
64+
* @param int|array<int> $ids Vehicles identifiers to delete
6565
*/
6666
public function removeVehicles(int|array $ids): bool
6767
{
@@ -153,6 +153,8 @@ public function removeVehicles(int|array $ids): bool
153153
*
154154
* @param int $id_adh Members id
155155
* @param ?AutosList $filters Filters
156+
*
157+
* @return array<int, Autos> Vehicles list
156158
*/
157159
public function getMemberList(int $id_adh, ?AutosList $filters): array
158160
{
@@ -162,14 +164,14 @@ public function getMemberList(int $id_adh, ?AutosList $filters): array
162164
/**
163165
* Get the list of all vehicles
164166
*
165-
* @param bool $as_autos return the results as an array of Auto object.
166-
* When true, fields are not relevant
167-
* @param bool $mine show only current logged member cars
168-
* @param ?array $fields field(s) name(s) to get.
169-
* or an array. If null, all fields will be returned
170-
* @param ?AutosList $filters Filters
171-
* @param ?int $id_adh Member id
172-
* @param bool $public Get public list
167+
* @param bool $as_autos return the results as an array of Auto object.
168+
* When true, fields are not relevant
169+
* @param bool $mine show only current logged member cars
170+
* @param ?array<string> $fields field(s) name(s) to get.
171+
* or an array. If null, all fields will be returned
172+
* @param ?AutosList $filters Filters
173+
* @param ?int $id_adh Member id
174+
* @param bool $public Get public list
173175
*
174176
* @return array<int, Autos>|ResultSet
175177
*/

lib/GaletteAuto/Controllers/Crud/ModelsController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function doEdit(Request $request, Response $response, ?int $id = null, st
301301
/**
302302
* Get redirection URI
303303
*
304-
* @param array $args Route arguments
304+
* @param array<string,mixed> $args Route arguments
305305
*/
306306
public function redirectUri(array $args): string
307307
{
@@ -311,7 +311,7 @@ public function redirectUri(array $args): string
311311
/**
312312
* Get form URI
313313
*
314-
* @param array $args Route arguments
314+
* @param array<string,mixed> $args Route arguments
315315
*/
316316
public function formUri(array $args): string
317317
{
@@ -324,7 +324,7 @@ public function formUri(array $args): string
324324
/**
325325
* Get confirmation removal page title
326326
*
327-
* @param array $args Route arguments
327+
* @param array<string,mixed> $args Route arguments
328328
*/
329329
public function confirmRemoveTitle(array $args): string
330330
{
@@ -349,8 +349,8 @@ public function confirmRemoveTitle(array $args): string
349349
/**
350350
* Remove object
351351
*
352-
* @param array $args Route arguments
353-
* @param array $post POST values
352+
* @param array<string,mixed> $args Route arguments
353+
* @param array<string,mixed> $post POST values
354354
*/
355355
protected function doDelete(array $args, array $post): bool
356356
{

lib/GaletteAuto/Controllers/Crud/PropertiesController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ protected function propertiesList(
186186
case 'brands':
187187
$obj = new Brand($this->zdb);
188188
$title = _T("Brands list", "auto");
189-
$show_title = _T("Brand '%s'", "auto");
190189
$add_text = _T("Add new brand", "auto");
191190
$can_show = true;
192191
break;
@@ -213,7 +212,6 @@ protected function propertiesList(
213212

214213
$params = [
215214
'page_title' => $title,
216-
//'models' => $models->getList(),
217215
'list' => $obj->getList(),
218216
'set' => $property,
219217
'field_name' => $obj->getFieldLabel(),

lib/GaletteAuto/History.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,19 @@
3333
*
3434
* @author Johan Cwiklinski <johan@x-tnd.be>
3535
*
36-
* @property int $id_car
37-
* @property array $fields
38-
* @property array $entries
36+
* @property int $id_car
37+
* @property array<string, string> $fields
38+
* @property array<int, array<string,mixed>> $entries
3939
*/
4040
class History
4141
{
4242
public const TABLE = 'history';
4343

4444
private Db $zdb;
4545

46-
//fields list and type
46+
/**
47+
* @var array<string, string> $fields fields list and type
48+
*/
4749
private array $fields = [
4850
Auto::PK => 'integer',
4951
Adherent::PK => 'integer',
@@ -108,7 +110,7 @@ public function load(int $id): bool
108110
/**
109111
* Get the most recent history entry
110112
*
111-
* @return ArrayObject|false row
113+
* @return ArrayObject<string, int|string>|false row
112114
*/
113115
public function getLatest(): ArrayObject|false
114116
{
@@ -168,7 +170,7 @@ private function formatEntries(array $entries): void
168170
/**
169171
* Register a new history entry.
170172
*
171-
* @param array $props list of properties to update
173+
* @param array<string,mixed> $props list of properties to update
172174
*/
173175
public function register(array $props): void
174176
{

lib/GaletteAuto/Model.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class Model
5454
/**
5555
* Default constructor
5656
*
57-
* @param Db $zdb Database instance
58-
* @param ArrayObject|int|null $args model's id to load or ResultSet. Defaults to null
57+
* @param Db $zdb Database instance
58+
* @param ArrayObject<string, int|string>|int|null $args model's id to load or ResultSet. Defaults to null
5959
*/
6060
public function __construct(Db $zdb, ArrayObject|int|null $args = null)
6161
{
@@ -104,7 +104,7 @@ public function load(int $id): bool
104104
/**
105105
* Populate object from a resultset row
106106
*
107-
* @param ArrayObject $r the resultset row
107+
* @param ArrayObject<string, int|string> $r the resultset row
108108
*/
109109
private function loadFromRS(ArrayObject $r): void
110110
{
@@ -160,7 +160,7 @@ public function store(bool $new = false): bool
160160
/**
161161
* Delete some models
162162
*
163-
* @param array $ids Array of models id to delete
163+
* @param array<int> $ids Array of models id to delete
164164
*/
165165
public function delete(array $ids): bool
166166
{
@@ -205,8 +205,8 @@ public function __isset(string $name): bool
205205
/**
206206
* Check posted values validity
207207
*
208-
* @param array $post All values to check, basically the $_POST array
209-
* after sending the form
208+
* @param array<string,mixed> $post All values to check, basically the $_POST array
209+
* after sending the form
210210
*/
211211
public function check(array $post): bool
212212
{

lib/GaletteAuto/PluginGaletteAuto.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PluginGaletteAuto extends GalettePlugin
3838
/**
3939
* Extra menus entries
4040
*
41-
* @return array|array[]
41+
* @return array<string, string|array<string,mixed>>
4242
*/
4343
public static function getMenusContents(): array
4444
{
@@ -124,7 +124,7 @@ public static function getMenusContents(): array
124124
/**
125125
* Extra public menus entries
126126
*
127-
* @return array|array[]
127+
* @return array<int, string|array<string,mixed>>
128128
*/
129129
public static function getPublicMenusItemsList(): array
130130
{
@@ -142,7 +142,7 @@ public static function getPublicMenusItemsList(): array
142142
/**
143143
* Get current logged-in user dashboards contents
144144
*
145-
* @return array|array[]
145+
* @return array<int, string|array<string,mixed>>
146146
*/
147147
public static function getMyDashboardsContents(): array
148148
{
@@ -167,7 +167,7 @@ public static function getMyDashboardsContents(): array
167167
/**
168168
* Get dashboards contents
169169
*
170-
* @return array|array[]
170+
* @return array<int, string|array<string,mixed>>
171171
*/
172172
public static function getDashboardsContents(): array
173173
{
@@ -200,7 +200,7 @@ public static function getListActionsContents(Adherent $member): array
200200
*
201201
* @param Adherent $member Member instance
202202
*
203-
* @return array|array[]
203+
* @return array<int, string|array<string,mixed>>
204204
*/
205205
public static function getDetailedActionsContents(Adherent $member): array
206206
{
@@ -210,7 +210,7 @@ public static function getDetailedActionsContents(Adherent $member): array
210210
/**
211211
* Get batch actions contents
212212
*
213-
* @return array|array[]
213+
* @return array<int, string|array<string,mixed>>
214214
*/
215215
public static function getBatchActionsContents(): array
216216
{

lib/GaletteAuto/Repository/Models.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private function buildSelect(): Select
126126
/**
127127
* Builds the order clause
128128
*
129-
* @return array SQL ORDER clause
129+
* @return array<string> SQL ORDER clause
130130
*/
131131
private function buildOrderClause(): array
132132
{

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parameters:
22
parallel:
33
maximumNumberOfProcesses: 2
4-
level: 5
4+
level: 6
55
paths:
66
- lib/
77
scanFiles:

0 commit comments

Comments
 (0)