Skip to content

Commit b7b727b

Browse files
committed
Fix mapping linter issues
1 parent 77c70fe commit b7b727b

File tree

9 files changed

+30
-25
lines changed

9 files changed

+30
-25
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ parameters:
88
fileExtensions:
99
- php
1010
paths:
11-
- src
11+
- src/Mapping
1212
tmpDir: vendor/.cache.phpstan
1313
reportUnmatchedIgnoredErrors: false
1414
ignoreErrors:

src/Mapping/Metadata/ClassMetadata.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,7 @@ public function getTypeStatement(Context $context, bool $read): TypeStatement
7676
$fields = [];
7777

7878
foreach ($this->properties as $property) {
79-
$field = $property->getFieldNode($context, $read);
80-
81-
if ($field === null) {
82-
continue;
83-
}
84-
85-
$fields[] = $field;
79+
$fields[] = $property->getFieldNode($context, $read);
8680
}
8781

8882
if ($fields === []) {

src/Mapping/Metadata/Condition/ExpressionConditionMetadata.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99

1010
final class ExpressionConditionMetadata extends ConditionMetadata
1111
{
12+
/**
13+
* @var non-empty-string
14+
*/
15+
public const DEFAULT_CONTEXT_VARIABLE_NAME = ExpressionConditionInfo::DEFAULT_CONTEXT_VARIABLE_NAME;
16+
1217
public function __construct(
1318
public readonly ParsedExpression $expression,
1419
/**
1520
* Gets expression variable name.
1621
*
1722
* @var non-empty-string
1823
*/
19-
public readonly string $variable,
24+
public readonly string $variable = self::DEFAULT_CONTEXT_VARIABLE_NAME,
2025
?int $createdAt = null,
2126
) {
2227
parent::__construct($createdAt);

src/Mapping/Provider/MetadataReaderProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public function getClassMetadata(
5454
): ClassMetadata {
5555
$info = $this->reader->read($class);
5656

57-
dd($info);
58-
5957
return $this->toClassMetadata($info, $types, $parser);
6058
}
6159

src/Mapping/Reader/AttributeReader/ClassAttributeLoader.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
abstract class ClassAttributeLoader implements ClassAttributeLoaderInterface
88
{
99
/**
10-
* @template TAttribute of object
10+
* @template TArgAttribute of object
1111
*
1212
* @param \ReflectionClass<object> $class
13-
* @param class-string<TAttribute> $name
13+
* @param class-string<TArgAttribute> $name
1414
*
15-
* @return TAttribute|null
15+
* @return TArgAttribute|null
1616
*/
1717
protected function findClassAttribute(\ReflectionClass $class, string $name): ?object
1818
{
@@ -24,11 +24,12 @@ protected function findClassAttribute(\ReflectionClass $class, string $name): ?o
2424
}
2525

2626
/**
27-
* @template TAttribute of object
27+
* @template TArgAttribute of object
2828
*
29-
* @param class-string<TAttribute> $name
29+
* @param \ReflectionClass<object> $class
30+
* @param class-string<TArgAttribute> $name
3031
*
31-
* @return iterable<array-key, TAttribute>
32+
* @return iterable<array-key, TArgAttribute>
3233
*/
3334
protected function getAllClassAttributes(\ReflectionClass $class, string $name): iterable
3435
{

src/Mapping/Reader/AttributeReader/PropertyAttributeLoader.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
abstract class PropertyAttributeLoader implements PropertyAttributeLoaderInterface
1111
{
1212
/**
13-
* @template TAttribute of object
13+
* @template TArgAttribute of object
1414
*
15-
* @param class-string<TAttribute> $name
15+
* @param class-string<TArgAttribute> $name
1616
*
17-
* @return TAttribute|null
17+
* @return TArgAttribute|null
1818
*/
1919
protected function findPropertyAttribute(RefProperty|RefHook $property, string $name): ?object
2020
{
@@ -26,11 +26,11 @@ protected function findPropertyAttribute(RefProperty|RefHook $property, string $
2626
}
2727

2828
/**
29-
* @template TAttribute of object
29+
* @template TArgAttribute of object
3030
*
31-
* @param class-string<TAttribute> $name
31+
* @param class-string<TArgAttribute> $name
3232
*
33-
* @return iterable<array-key, TAttribute>
33+
* @return iterable<array-key, TArgAttribute>
3434
*/
3535
protected function getAllPropertyAttributes(RefProperty|RefHook $property, string $name): iterable
3636
{

src/Mapping/Reader/ConfigReader/DiscriminatorMapClassConfigLoader.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ public function load(\ReflectionClass $class, ClassInfo $info, array $config): v
2424
$map[$value] = new TypeInfo($type);
2525
}
2626

27+
$default = null;
28+
29+
if (isset($discriminatorConfig['otherwise'])) {
30+
$default = new TypeInfo($discriminatorConfig['otherwise']);
31+
}
32+
2733
$info->discriminator = new DiscriminatorInfo(
2834
field: $discriminatorConfig['field'],
2935
map: $map,
30-
default: $discriminatorConfig['default'] ?? null,
36+
default: $default,
3137
);
3238
}
3339
}

src/Mapping/Reader/ConfigReader/SchemaValidator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @phpstan-type PropertyConfigType array{
2121
* name?: non-empty-string,
2222
* type?: non-empty-string,
23+
* write?: non-empty-string,
2324
* skip?: 'null'|'empty'|non-empty-string|list<'null'|'empty'|non-empty-string>,
2425
* type_error_message?: non-empty-string,
2526
* undefined_error_message?: non-empty-string,

src/Mapping/SkipWhen.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace TypeLang\Mapper\Mapping;
66

77
use JetBrains\PhpStorm\Language;
8-
use TypeLang\Mapper\Mapping\Metadata\ExpressionConditionMetadata;
8+
use TypeLang\Mapper\Mapping\Metadata\Condition\ExpressionConditionMetadata;
99

1010
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
1111
class SkipWhen

0 commit comments

Comments
 (0)