Skip to content

Commit de58df9

Browse files
vjiksamdark
andauthored
Fix psalm errors (#488)
* fix * fix * fix * Update src/Helper/ObjectParser.php Co-authored-by: Alexander Makarov <[email protected]> Co-authored-by: Alexander Makarov <[email protected]>
1 parent 2a4f223 commit de58df9

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/DataSet/ObjectDataSet.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ final class ObjectDataSet implements RulesProviderInterface, DataSetInterface, A
163163
* and protected only, this means that the rest (private ones) will be skipped. Defaults to all visibility levels
164164
* (public, protected and private).
165165
* @param bool $useCache Whether to use cache for data and attribute methods (partially) and rules (completely).
166+
*
167+
* @psalm-param int-mask-of<ReflectionProperty::IS_*> $propertyVisibility
166168
*/
167169
public function __construct(
168170
/**

src/Helper/ObjectParser.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
*
113113
* @link https://www.php.net/manual/en/language.attributes.overview.php
114114
*
115-
* @psalm-type RulesCache = array<int,array{0:RuleInterface,1:Attribute::TARGET_*}>|array<string,list<array{0:RuleInterface,1:Attribute::TARGET_*}>>
115+
* @psalm-type RulesCacheItem = array{0:RuleInterface,1:Attribute::TARGET_*}
116116
*/
117117
final class ObjectParser
118118
{
@@ -152,6 +152,7 @@ public function __construct(
152152
* @var int Visibility levels the parsed properties must have. For example: public and protected only, this
153153
* means that the rest (private ones) will be skipped. Defaults to all visibility levels (public, protected and
154154
* private).
155+
* @psalm-var int-mask-of<ReflectionProperty::IS_*>
155156
*/
156157
private int $propertyVisibility = ReflectionProperty::IS_PRIVATE |
157158
ReflectionProperty::IS_PROTECTED |
@@ -197,7 +198,7 @@ public function __construct(
197198
public function getRules(): array
198199
{
199200
if ($this->hasCacheItem('rules')) {
200-
/** @psalm-var RulesCache */
201+
/** @var array $rules */
201202
$rules = $this->getCacheItem('rules');
202203
return $this->prepareRules($rules);
203204
}
@@ -317,6 +318,7 @@ public function getReflectionProperties(): array
317318
}
318319

319320
if (PHP_VERSION_ID < 80100) {
321+
/** @psalm-suppress UnusedMethodCall Need for pslam with PHP 8.1+ */
320322
$property->setAccessible(true);
321323
}
322324

@@ -351,21 +353,24 @@ private function getReflectionSource(): ReflectionObject|ReflectionClass
351353
}
352354

353355
/**
354-
* @psalm-param RulesCache $source Raw rules containing additional metadata besides rule instances.
356+
* @psalm-param array $source Raw rules containing additional metadata besides rule instances.
355357
*
356358
* @return array<int, RuleInterface>|array<string, list<RuleInterface>> An array of rules ready to use for the
357359
* validation.
358360
*/
359361
private function prepareRules(array $source): array
360362
{
361363
$rules = [];
364+
/**
365+
* @var mixed $data
366+
*/
362367
foreach ($source as $key => $data) {
363368
if (is_int($key)) {
364-
/** @psalm-var array{0:RuleInterface,1:Attribute::TARGET_*} $data */
369+
/** @psalm-var RulesCacheItem $data */
365370
$rules[$key] = $this->prepareRule($data[0], $data[1]);
366371
} else {
367372
/**
368-
* @psalm-var list<array{0:RuleInterface,1:Attribute::TARGET_*}> $data
373+
* @psalm-var list<RulesCacheItem> $data
369374
* @psalm-suppress UndefinedInterfaceMethod
370375
*/
371376
foreach ($data as $rule) {

src/Rule/Nested.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ public function __construct(
7777

7878
/**
7979
* @var int What visibility levels to use when reading data and rules from validated object.
80+
* @psalm-var int-mask-of<ReflectionProperty::IS_*>
8081
*/
8182
private int $propertyVisibility = ReflectionProperty::IS_PRIVATE
8283
| ReflectionProperty::IS_PROTECTED
8384
| ReflectionProperty::IS_PUBLIC,
8485
/**
8586
* @var int What visibility levels to use when reading rules from the class specified in {@see $rules}
8687
* attribute.
88+
* @psalm-var int-mask-of<ReflectionProperty::IS_*>
8789
*/
8890
private int $rulesPropertyVisibility = ReflectionProperty::IS_PRIVATE
8991
| ReflectionProperty::IS_PROTECTED
@@ -124,6 +126,9 @@ public function getRules(): iterable|null
124126
return $this->rules;
125127
}
126128

129+
/**
130+
* @psalm-return int-mask-of<ReflectionProperty::IS_*>
131+
*/
127132
public function getPropertyVisibility(): int
128133
{
129134
return $this->propertyVisibility;

src/RulesProvider/AttributesRulesProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ final class AttributesRulesProvider implements RulesProviderInterface
102102
* protected only, this means that the rest (private ones) will be skipped. Defaults to all visibility levels
103103
* (public, protected and private).
104104
* @param bool $skipStaticProperties Whether the properties with "static" modifier must be skipped.
105+
*
106+
* @psalm-param int-mask-of<ReflectionProperty::IS_*> $propertyVisibility
105107
*/
106108
public function __construct(
107109
string|object $source,

0 commit comments

Comments
 (0)