Skip to content

Commit 9c9b4d3

Browse files
committed
fix: Removed parent property from class blueprint. Changed parent from class blueprint to property blueprint in property blueprint
1 parent c3379f4 commit 9c9b4d3

File tree

7 files changed

+17
-35
lines changed

7 files changed

+17
-35
lines changed

src/Blueprint/Application/Model/Assets/ClassBlueprint.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class ClassBlueprint implements Normalizable
1616
public array $options = [];
1717

1818
public ?Blueprint $blueprint;
19-
public ?PropertyBlueprint $parent;
2019
public string $blueprintName;
2120

2221
/** @var class-string */
@@ -56,7 +55,6 @@ public static function create(string $class, ?PropertyBlueprint $parent, ?Bluepr
5655
}
5756

5857
$instance->blueprint = $blueprint;
59-
$instance->parent = $parent;
6058
$instance->name = $reflection->getName();
6159
$instance->shortName = $reflection->getShortName();
6260
$instance->namespace = $reflection->getNamespaceName();
@@ -80,7 +78,7 @@ public static function create(string $class, ?PropertyBlueprint $parent, ?Bluepr
8078
}
8179

8280
$instance->attributes = AttributeBlueprint::createCollection($instance);
83-
$instance->properties = PropertyBlueprint::createCollection($instance);
81+
$instance->properties = PropertyBlueprint::createCollection($instance, $parent);
8482
$instance->methods = MethodBlueprint::createCollection($instance);
8583

8684
return $instance;
@@ -91,11 +89,6 @@ public function getReflection(): \ReflectionClass
9189
return new \ReflectionClass($this->name);
9290
}
9391

94-
public function getPath(): string
95-
{
96-
return $this->parent?->getPath() ?? '';
97-
}
98-
9992
public function hasDeclarationFile(): bool
10093
{
10194
return false !== $this->filePath;

src/Blueprint/Application/Model/Assets/PropertyBlueprint.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class PropertyBlueprint implements Normalizable
1616
/** @var array<string, mixed> */
1717
public array $options = [];
1818

19-
public ClassBlueprint $parent;
19+
public ?PropertyBlueprint $parent;
20+
public ClassBlueprint $class;
2021
public string $originName;
2122

2223
public Visibility $visibility;
@@ -29,10 +30,11 @@ class PropertyBlueprint implements Normalizable
2930

3031
public AssetsAggregate $attributes;
3132

32-
public static function create(\ReflectionProperty $property, ClassBlueprint $parent): self
33+
public static function create(\ReflectionProperty $property, ClassBlueprint $class, ?PropertyBlueprint $parent): self
3334
{
3435
$instance = new self();
3536
$instance->parent = $parent;
37+
$instance->class = $class;
3638
$instance->originName = $property->getName();
3739
$instance->visibility = match (true) {
3840
$property->isPrivate() => Visibility::PRIVATE,
@@ -51,13 +53,13 @@ public static function create(\ReflectionProperty $property, ClassBlueprint $par
5153
return $instance;
5254
}
5355

54-
public static function createCollection(ClassBlueprint $root): AssetsAggregate
56+
public static function createCollection(ClassBlueprint $root, ?PropertyBlueprint $parent): AssetsAggregate
5557
{
5658
$ref = $root->getReflection();
5759

5860
$properties = [];
5961
foreach ($ref->getProperties() as $property) {
60-
$properties[$property->getName()] = static::create($property, $root);
62+
$properties[$property->getName()] = static::create($property, $root, $parent);
6163
}
6264

6365
return new AssetsAggregate($root, $properties);
@@ -74,7 +76,7 @@ public function getPath(): string
7476
return $this->options[self::OPTIONS_PATH];
7577
}
7678

77-
$path = $this->parent->getPath();
79+
$path = $this->parent?->getPath() ?? '';
7880

7981
if (!str_ends_with($path, '[]') && '' !== $path) {
8082
$path .= '.';
@@ -91,7 +93,7 @@ public function getPath(): string
9193

9294
public function getReflection(): \ReflectionProperty
9395
{
94-
return new \ReflectionProperty($this->parent->name, $this->originName);
96+
return new \ReflectionProperty($this->class->name, $this->originName);
9597
}
9698

9799
public function normalize(): array

src/Blueprint/Application/Model/Blueprint.php

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static function getBlueprint(
6565
): ?self {
6666
return match (get_class($asset)) {
6767
ClassBlueprint::class => $asset->blueprint,
68+
PropertyBlueprint::class => $asset->class->blueprint,
6869
default => self::getBlueprint($asset->parent)
6970
};
7071
}
@@ -74,6 +75,7 @@ public static function getClassBlueprint(
7475
): ClassBlueprint {
7576
return match (get_class($asset)) {
7677
ClassBlueprint::class => $asset,
78+
PropertyBlueprint::class => $asset->class,
7779
default => self::getClassBlueprint($asset->parent)
7880
};
7981
}

src/Mapper/Domain/Service/Matcher.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ protected function matchProperties(Process $processType, PropertyBlueprint $orig
6969
}
7070
}
7171

72-
throw new PropertyNotMatchedException($originProperty->getPath(), sprintf('Property "%s" from origin class "%s" could not be matched with any property from source and target classes.', $originProperty->originName, $originProperty->parent->name), sprintf('Check Your classes: origin:"%s", source:"%s" and target:"%s" for properties with the same name or with the same attributes. Use #[TargetProperty] attribute to match properties if the names cannot be same.', $originProperty->parent->name, $source->name, $target->name));
72+
throw new PropertyNotMatchedException($originProperty->getPath(), sprintf('Property "%s" from origin class "%s" could not be matched with any property from source and target classes.', $originProperty->originName, $originProperty->class->name), sprintf('Check Your classes: origin:"%s", source:"%s" and target:"%s" for properties with the same name or with the same attributes. Use #[TargetProperty] attribute to match properties if the names cannot be same.', $originProperty->class->name, $source->name, $target->name));
7373
}
7474

7575
protected function addLinks(

src/Mapper/Domain/Service/Matcher/TargetPropertyAttributeStrategy.php

-19
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,4 @@ protected function getPropertyTargetPropertyAttribute(PropertyBlueprint $bluepri
118118

119119
return null;
120120
}
121-
122-
protected function getClassTargetPropertyAttribute(ClassBlueprint $blueprint, string $processType): ?TargetProperty
123-
{
124-
if (!$blueprint->parent) {
125-
return null;
126-
}
127-
128-
foreach ($blueprint->parent->attributes[TargetProperty::class] as $attribute) {
129-
/** @var TargetProperty $instance */
130-
$instance = $attribute->newInstance();
131-
132-
$binaryProcessType = $instance::PROCESS_TYPE_MAP[$processType];
133-
if (($instance->usePathFor & $binaryProcessType) === $binaryProcessType) {
134-
return $instance;
135-
}
136-
}
137-
138-
return null;
139-
}
140121
}

tests/Blueprint/Unit/Application/Model/ClassBlueprintTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public function testTypeDeclarationsAreSetCorrectly(): void
8989
{
9090
$blueprint = ClassBlueprint::create(Dummy::class, null);
9191

92-
$this->assertNull($blueprint->parent);
9392
$this->assertTrue(false === $blueprint->docBlock || is_string($blueprint->docBlock));
9493
$this->assertEquals(ClassType::STANDARD, $blueprint->type);
9594
}

tools/phpstan/fpm-baseline.neon

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ parameters:
55
count: 1
66
path: ../../src/Blueprint/Application/Model/Assets/MethodBlueprint.php
77

8+
-
9+
message: "#^Access to an undefined property PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\AttributeBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\ClassBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\MethodBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\ParameterBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\PropertyBlueprint\\:\\:\\$parent\\.$#"
10+
count: 2
11+
path: ../../src/Blueprint/Application/Model/Blueprint.php
12+
813
-
914
message: "#^Parameter \\#1 \\$asset of static method PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Blueprint\\:\\:getBlueprint\\(\\) expects PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\AttributeBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\ClassBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\MethodBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\ParameterBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\PropertyBlueprint, PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\ClassBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\MethodBlueprint\\|PBaszak\\\\UltraMapper\\\\Blueprint\\\\Application\\\\Model\\\\Assets\\\\PropertyBlueprint\\|null given\\.$#"
1015
count: 1

0 commit comments

Comments
 (0)