Skip to content

Commit 82e6f3d

Browse files
committed
PHPStan fixes
1 parent d6ab309 commit 82e6f3d

16 files changed

Lines changed: 147 additions & 14 deletions

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
excludePaths:
3+
- src/Widget/*
4+
- tests/*

src/DependencyInjection/CodefogTagsExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
class CodefogTagsExtension extends ConfigurableExtension
1515
{
16+
/**
17+
* @param array<string, mixed> $mergedConfig
18+
*/
1619
protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void
1720
{
1821
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
@@ -24,6 +27,9 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
2427
}
2528
}
2629

30+
/**
31+
* @param array<string, mixed> $config
32+
*/
2733
private function createManager(string $name, array $config, ContainerBuilder $container): void
2834
{
2935
$id = \sprintf('codefog_tags.manager.%s', $name);

src/Driver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212
class Driver extends DC_Table
1313
{
14+
/**
15+
* @param array<string> $orderBy
16+
*/
1417
public function setOrderBy(array $orderBy): void
1518
{
1619
$this->orderBy = $orderBy;

src/EventListener/DataContainer/TagListener.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ public function onPanelCallback(DataContainer $dc): string
134134
</div>';
135135
}
136136

137+
/**
138+
* @param array<string, mixed> $row
139+
* @param array<int, mixed> $args
140+
*
141+
* @return array<int, mixed>
142+
*/
137143
#[AsCallback('tl_cfg_tag', 'list.label.label')]
138144
public function onLabelCallback(array $row, string $label, DataContainer $dc, array $args): array
139145
{
@@ -148,6 +154,11 @@ public function onLabelCallback(array $row, string $label, DataContainer $dc, ar
148154
return $args;
149155
}
150156

157+
/**
158+
* @param array<string, string> $buttons
159+
*
160+
* @return array<string, string>
161+
*/
151162
#[AsCallback('tl_cfg_tag', 'select.buttons')]
152163
public function onButtonsCallback(array $buttons, DataContainer $dc): array
153164
{
@@ -201,6 +212,9 @@ public function onButtonsCallback(array $buttons, DataContainer $dc): array
201212
return $buttons;
202213
}
203214

215+
/**
216+
* @return array<string>
217+
*/
204218
#[AsCallback('tl_cfg_tag', 'fields.source.options')]
205219
public function onSourceOptionsCallback(): array
206220
{

src/EventListener/TagManagerListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public function onFieldSaveCallback(string $value, DataContainer $dc): string
6363
return $value;
6464
}
6565

66+
/**
67+
* @return array<string, string>
68+
*/
6669
public function onOptionsCallback(DataContainer $dc): array
6770
{
6871
$value = [];

src/Finder/SourceCriteria.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88

99
class SourceCriteria
1010
{
11+
/**
12+
* @var array<int>
13+
*/
1114
protected array $ids = [];
1215

1316
/**
1417
* @var array<Tag>
1518
*/
1619
protected array $tags = [];
1720

21+
/**
22+
* @var array<string>
23+
*/
1824
protected array $tagValues = [];
1925

2026
public function __construct(
@@ -43,11 +49,17 @@ public function getSourceField(): string
4349
return explode('.', $this->source, 2)[1];
4450
}
4551

52+
/**
53+
* @return array<int>
54+
*/
4655
public function getIds(): array
4756
{
4857
return $this->ids;
4958
}
5059

60+
/**
61+
* @param array<int> $ids
62+
*/
5163
public function setIds(array $ids): self
5264
{
5365
$this->ids = $ids;
@@ -80,11 +92,17 @@ public function setTag(Tag $tag): self
8092
return $this;
8193
}
8294

95+
/**
96+
* @return array<string>
97+
*/
8398
public function getTagValues(): array
8499
{
85100
return $this->tagValues;
86101
}
87102

103+
/**
104+
* @param array<string> $tagValues
105+
*/
88106
public function setTagValues(array $tagValues): self
89107
{
90108
$this->tagValues = $tagValues;

src/Finder/SourceFinder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public function count(SourceCriteria $criteria): int
3434

3535
/**
3636
* Find multiple source record IDs by criteria.
37+
*
38+
* @return array<int>
3739
*/
3840
public function findMultiple(SourceCriteria $criteria): array
3941
{
@@ -53,6 +55,8 @@ public function findMultiple(SourceCriteria $criteria): array
5355
/**
5456
* Find the related source records.
5557
*
58+
* @return array<string, mixed>
59+
*
5660
* @throws \RuntimeException
5761
*/
5862
public function findRelatedSourceRecords(SourceCriteria $criteria, int|null $limit = null): array
@@ -61,7 +65,7 @@ public function findRelatedSourceRecords(SourceCriteria $criteria, int|null $lim
6165
throw new \RuntimeException('No IDs have been provided');
6266
}
6367

64-
if (false === ($relation = $this->dcaRelationsManager->getRelation($criteria->getSourceTable(), $criteria->getSourceField()))) {
68+
if (null === ($relation = $this->dcaRelationsManager->getRelation($criteria->getSourceTable(), $criteria->getSourceField()))) {
6569
throw new \RuntimeException(\sprintf('The field %s.%s is not related', $criteria->getSourceTable(), $criteria->getSourceField()));
6670
}
6771

src/Finder/TagCriteria.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66

77
class TagCriteria
88
{
9+
/**
10+
* @var array<string>
11+
*/
912
protected array $aliases = [];
1013

14+
/**
15+
* @var array<int>
16+
*/
1117
protected array $sourceIds = [];
1218

1319
protected bool $usedOnly = false;
1420

21+
/**
22+
* @var array<int|string>
23+
*/
1524
protected array $values = [];
1625

1726
protected string $order = 'name';
@@ -42,11 +51,17 @@ public function getSourceField(): string
4251
return explode('.', $this->source, 2)[1];
4352
}
4453

54+
/**
55+
* @return array<string>
56+
*/
4557
public function getAliases(): array
4658
{
4759
return $this->aliases;
4860
}
4961

62+
/**
63+
* @param array<string> $aliases
64+
*/
5065
public function setAliases(array $aliases): self
5166
{
5267
$this->aliases = array_values(array_unique($aliases));
@@ -61,11 +76,17 @@ public function setAlias(string $alias): self
6176
return $this;
6277
}
6378

79+
/**
80+
* @return array<int>
81+
*/
6482
public function getSourceIds(): array
6583
{
6684
return $this->sourceIds;
6785
}
6886

87+
/**
88+
* @param array<int> $sourceIds
89+
*/
6990
public function setSourceIds(array $sourceIds): self
7091
{
7192
$this->sourceIds = array_values(array_unique($sourceIds));
@@ -85,11 +106,17 @@ public function setUsedOnly(bool $usedOnly): self
85106
return $this;
86107
}
87108

109+
/**
110+
* @return array<int|string>
111+
*/
88112
public function getValues(): array
89113
{
90114
return $this->values;
91115
}
92116

117+
/**
118+
* @param array<int|string> $values
119+
*/
93120
public function setValues(array $values): self
94121
{
95122
$this->values = array_values(array_unique($values));

src/Finder/TagFinder.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
readonly class TagFinder
2121
{
22-
/**
23-
* Count tags by criteria.
24-
*/
2522
public function count(TagCriteria $criteria): int
2623
{
2724
try {
@@ -37,9 +34,6 @@ public function count(TagCriteria $criteria): int
3734
return TagModel::countBy($columns, $values, $options);
3835
}
3936

40-
/**
41-
* Find a single tag by criteria.
42-
*/
4337
public function findSingle(TagCriteria $criteria): Tag|null
4438
{
4539
try {
@@ -56,7 +50,7 @@ public function findSingle(TagCriteria $criteria): Tag|null
5650
}
5751

5852
/**
59-
* Find multiple tags by criteria.
53+
* @return array<Tag>
6054
*/
6155
public function findMultiple(TagCriteria $criteria): array
6256
{
@@ -88,6 +82,8 @@ public function findMultiple(TagCriteria $criteria): array
8882

8983
/**
9084
* Get the top tags. The tag count will be part of tag's data ($tag->getData()['count']).
85+
*
86+
* @return array<Tag>
9187
*/
9288
public function getTopTags(TagCriteria $criteria, int|null $limit = null, bool $withCount = false): array
9389
{
@@ -110,6 +106,8 @@ public function getTopTags(TagCriteria $criteria, int|null $limit = null, bool $
110106

111107
/**
112108
* Get the top tag IDs.
109+
*
110+
* @return array<int, int>
113111
*/
114112
public function getTopTagIds(TagCriteria $criteria, int|null $limit = null, bool $withCount = false): array
115113
{
@@ -143,16 +141,17 @@ public function getTopTagIds(TagCriteria $criteria, int|null $limit = null, bool
143141
return \array_slice($helper, 0, $limit, $withCount);
144142
}
145143

146-
/**
147-
* Create tag from model.
148-
*/
149144
public function createTagFromModel(TagModel $model): Tag
150145
{
151146
return new Tag((string) $model->id, (string) $model->name, $model->row());
152147
}
153148

154149
/**
155-
* Parse the criteria to object.
150+
* @return array{
151+
* array<string>,
152+
* array<string>,
153+
* array<string, string>,
154+
* }
156155
*
157156
* @throws NoTagsException
158157
*/

src/InsertTag/TagResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __invoke(ResolvedInsertTag $insertTag): InsertTagResult
3333
$manager = $this->registry->get($source);
3434

3535
if ($manager instanceof InsertTagsAwareInterface) {
36-
return $manager->getInsertTagValue($value, $property, $parameters->all());
36+
return new InsertTagResult($manager->getInsertTagValue($value, $property, $parameters->all()));
3737
}
3838

3939
return new InsertTagResult('');

0 commit comments

Comments
 (0)