Skip to content

Commit 07a4383

Browse files
committed
isOwning belongs in the base relation object
1 parent 0cdfc0b commit 07a4383

9 files changed

+44
-74
lines changed

src/Doctrine/BaseRelation.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ public function __construct(
2525
private bool $avoidSetter = false,
2626
private bool $isCustomReturnTypeNullable = false,
2727
private ?string $customReturnType = null,
28+
protected bool $isOwning = false,
2829
) {
2930
// @TODO - triggers are tmp, do not merge w/ them in place.
3031
if (null === $this->targetPropertyName) {
3132
trigger_deprecation('symfony/maker-bundle', '0.0.0', 'No null target property name');
3233
}
3334
}
3435

35-
abstract public function isOwning(): bool;
36-
3736
public function getPropertyName(): string
3837
{
3938
return $this->propertyName;
@@ -73,4 +72,9 @@ public function isCustomReturnTypeNullable(): bool
7372
{
7473
return $this->isCustomReturnTypeNullable;
7574
}
75+
76+
public function isOwning(): bool
77+
{
78+
return $this->isOwning;
79+
}
7680
}

src/Doctrine/EntityRegenerator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public function regenerateEntities(string $classOrNamespace): void
127127
targetClassName: $mapping['targetEntity'],
128128
targetPropertyName: $mapping['inversedBy'],
129129
mapInverseRelation: null !== $mapping['inversedBy'],
130+
isOwning: true,
130131
))
131132
->setIsNullable($getIsNullable($mapping))
132133
;
@@ -152,9 +153,8 @@ public function regenerateEntities(string $classOrNamespace): void
152153
targetClassName: $mapping['targetEntity'],
153154
targetPropertyName: $mapping['mappedBy'],
154155
mapInverseRelation: $mapping['isOwningSide'] ? (null !== $mapping['inversedBy']) : true,
155-
))
156-
->setIsOwning($mapping['isOwningSide'])
157-
;
156+
isOwning: $mapping['isOwningSide'],
157+
));
158158

159159
$manipulator->addManyToManyRelation($relation);
160160

@@ -165,8 +165,8 @@ public function regenerateEntities(string $classOrNamespace): void
165165
targetClassName: $mapping['targetEntity'],
166166
targetPropertyName: $mapping['isOwningSide'] ? $mapping['inversedBy'] : $mapping['mappedBy'],
167167
mapInverseRelation: $mapping['isOwningSide'] ? (null !== $mapping['inversedBy']) : true,
168+
isOwning: $mapping['isOwningSide'],
168169
))
169-
->setIsOwning($mapping['isOwningSide'])
170170
->setIsNullable($getIsNullable($mapping))
171171
;
172172

src/Doctrine/EntityRelation.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function getOwningRelation(): RelationManyToMany|RelationOneToOne|Relatio
8787
targetPropertyName: $this->inverseProperty,
8888
isSelfReferencing: $this->isSelfReferencing,
8989
mapInverseRelation: $this->mapInverseRelation,
90+
isOwning: true,
9091
))
9192
->setIsNullable($this->isNullable),
9293
self::MANY_TO_MANY => (new RelationManyToMany(
@@ -95,17 +96,17 @@ public function getOwningRelation(): RelationManyToMany|RelationOneToOne|Relatio
9596
targetPropertyName: $this->inverseProperty,
9697
isSelfReferencing: $this->isSelfReferencing,
9798
mapInverseRelation: $this->mapInverseRelation,
98-
))
99-
->setIsOwning(true),
99+
isOwning: true,
100+
)),
100101
self::ONE_TO_ONE => (new RelationOneToOne(
101102
propertyName: $this->owningProperty,
102103
targetClassName: $this->inverseClass,
103104
targetPropertyName: $this->inverseProperty,
104105
isSelfReferencing: $this->isSelfReferencing,
105106
mapInverseRelation: $this->mapInverseRelation,
107+
isOwning: true,
106108
))
107-
->setIsNullable($this->isNullable)
108-
->setIsOwning(true),
109+
->setIsNullable($this->isNullable),
109110
default => throw new \InvalidArgumentException('Invalid type'),
110111
};
111112
}
@@ -117,24 +118,22 @@ public function getInverseRelation(): RelationManyToMany|RelationOneToOne|Relati
117118
propertyName: $this->inverseProperty,
118119
targetClassName: $this->owningClass,
119120
targetPropertyName: $this->owningProperty,
120-
isSelfReferencing: $this->isSelfReferencing
121+
isSelfReferencing: $this->isSelfReferencing,
121122
))
122123
->setOrphanRemoval($this->orphanRemoval),
123124
self::MANY_TO_MANY => (new RelationManyToMany(
124125
propertyName: $this->inverseProperty,
125126
targetClassName: $this->owningClass,
126127
targetPropertyName: $this->owningProperty,
127128
isSelfReferencing: $this->isSelfReferencing
128-
))
129-
->setIsOwning(false),
129+
)),
130130
self::ONE_TO_ONE => (new RelationOneToOne(
131131
propertyName: $this->inverseProperty,
132132
targetClassName: $this->owningClass,
133133
targetPropertyName: $this->owningProperty,
134134
isSelfReferencing: $this->isSelfReferencing
135135
))
136-
->setIsNullable($this->isNullable)
137-
->setIsOwning(false),
136+
->setIsNullable($this->isNullable),
138137
default => throw new \InvalidArgumentException('Invalid type'),
139138
};
140139
}

src/Doctrine/RelationManyToMany.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@
1818
*/
1919
final class RelationManyToMany extends BaseCollectionRelation
2020
{
21-
private $isOwning;
22-
23-
public function isOwning(): bool
24-
{
25-
return $this->isOwning;
26-
}
27-
28-
public function setIsOwning($isOwning): self
29-
{
30-
$this->isOwning = $isOwning;
31-
32-
return $this;
33-
}
34-
3521
public function getOrphanRemoval(): bool
3622
{
3723
return false;

src/Doctrine/RelationManyToOne.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,4 @@
1616
*/
1717
final class RelationManyToOne extends BaseSingleRelation
1818
{
19-
public function isOwning(): bool
20-
{
21-
return true;
22-
}
2319
}

src/Doctrine/RelationOneToMany.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public function getTargetSetterMethodName(): string
4242
return 'set'.Str::asCamelCase($this->getTargetPropertyName());
4343
}
4444

45-
public function isOwning(): bool
46-
{
47-
return false;
48-
}
49-
5045
public function isMapInverseRelation(): bool
5146
{
5247
throw new \Exception('OneToMany IS the inverse side!');

src/Doctrine/RelationOneToOne.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@
1818
*/
1919
final class RelationOneToOne extends BaseSingleRelation
2020
{
21-
private $isOwning;
22-
23-
public function isOwning(): bool
24-
{
25-
return $this->isOwning;
26-
}
27-
28-
public function setIsOwning($isOwning): self
29-
{
30-
$this->isOwning = $isOwning;
31-
32-
return $this;
33-
}
34-
3521
public function getTargetGetterMethodName(): string
3622
{
3723
return 'get'.Str::asCamelCase($this->getTargetPropertyName());

src/Maker/MakeResetPassword.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ private function generateRequestEntity(Generator $generator, ClassNameDetails $r
434434
avoidSetter: true,
435435
isCustomReturnTypeNullable: false,
436436
customReturnType: 'object',
437+
isOwning: true,
437438
)));
438439

439440
$this->fileManager->dumpFile($requestEntityPath, $manipulator->getSourceCode());

tests/Util/ClassSourceManipulatorTest.php

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ public function getAddManyToOneRelationTests(): \Generator
381381
propertyName: 'category',
382382
targetClassName: \App\Entity\Category::class,
383383
targetPropertyName: 'foods',
384+
isOwning: true,
384385
))
385386
->setIsNullable(false),
386387
];
@@ -392,6 +393,7 @@ public function getAddManyToOneRelationTests(): \Generator
392393
propertyName: 'category',
393394
targetClassName: \App\Entity\Category::class,
394395
targetPropertyName: 'foods',
396+
isOwning: true,
395397
))
396398
->setIsNullable(true),
397399
];
@@ -403,6 +405,7 @@ public function getAddManyToOneRelationTests(): \Generator
403405
propertyName: 'category',
404406
targetClassName: \Foo\Entity\Category::class,
405407
targetPropertyName: 'foods',
408+
isOwning: true,
406409
))
407410
->setIsNullable(true),
408411
];
@@ -414,6 +417,7 @@ public function getAddManyToOneRelationTests(): \Generator
414417
propertyName: 'category',
415418
targetClassName: \Foo\Entity\Category::class,
416419
targetPropertyName: 'foods',
420+
isOwning: true,
417421
))
418422
->setIsNullable(true),
419423
];
@@ -425,6 +429,7 @@ public function getAddManyToOneRelationTests(): \Generator
425429
propertyName: 'subCategory',
426430
targetClassName: \App\Entity\SubDirectory\Category::class,
427431
targetPropertyName: 'foods',
432+
isOwning: true,
428433
))
429434
->setIsNullable(true),
430435
];
@@ -437,6 +442,7 @@ public function getAddManyToOneRelationTests(): \Generator
437442
targetClassName: \App\Entity\Category::class,
438443
targetPropertyName: 'foods',
439444
mapInverseRelation: false,
445+
isOwning: true,
440446
))
441447
->setIsNullable(true),
442448
];
@@ -561,8 +567,8 @@ public function getAddManyToManyRelationTests(): \Generator
561567
propertyName: 'recipes',
562568
targetClassName: \App\Entity\Recipe::class,
563569
targetPropertyName: 'foods',
564-
))
565-
->setIsOwning(true),
570+
isOwning: true,
571+
)),
566572
];
567573

568574
yield 'many_to_many_inverse' => [
@@ -572,8 +578,7 @@ public function getAddManyToManyRelationTests(): \Generator
572578
propertyName: 'recipes',
573579
targetClassName: \App\Entity\Recipe::class,
574580
targetPropertyName: 'foods',
575-
))
576-
->setIsOwning(false),
581+
)),
577582
];
578583

579584
yield 'many_to_many_owning_inverse' => [
@@ -584,8 +589,8 @@ public function getAddManyToManyRelationTests(): \Generator
584589
targetClassName: \App\Entity\Recipe::class,
585590
targetPropertyName: 'foods',
586591
mapInverseRelation: false,
587-
))
588-
->setIsOwning(true),
592+
isOwning: true,
593+
)),
589594
];
590595
}
591596

@@ -633,9 +638,9 @@ public function getAddOneToOneRelationTests(): \Generator
633638
propertyName: 'userProfile',
634639
targetClassName: \App\Entity\UserProfile::class,
635640
targetPropertyName: 'user',
641+
isOwning: true,
636642
))
637-
->setIsNullable(true)
638-
->setIsOwning(true),
643+
->setIsNullable(true),
639644
];
640645

641646
// a relationship to yourself - return type is self
@@ -646,9 +651,9 @@ public function getAddOneToOneRelationTests(): \Generator
646651
propertyName: 'embeddedUser',
647652
targetClassName: \App\Entity\User::class,
648653
targetPropertyName: 'user',
654+
isOwning: true,
649655
))
650-
->setIsNullable(true)
651-
->setIsOwning(true),
656+
->setIsNullable(true),
652657
];
653658

654659
yield 'one_to_one_inverse' => [
@@ -659,8 +664,7 @@ public function getAddOneToOneRelationTests(): \Generator
659664
targetClassName: \App\Entity\User::class,
660665
targetPropertyName: 'userProfile',
661666
))
662-
->setIsNullable(true)
663-
->setIsOwning(false),
667+
->setIsNullable(true),
664668
];
665669

666670
yield 'one_to_one_inverse_not_nullable' => [
@@ -671,8 +675,7 @@ public function getAddOneToOneRelationTests(): \Generator
671675
targetClassName: \App\Entity\User::class,
672676
targetPropertyName: 'userProfile',
673677
))
674-
->setIsNullable(false)
675-
->setIsOwning(false),
678+
->setIsNullable(false),
676679
];
677680

678681
yield 'one_to_one_no_inverse' => [
@@ -682,9 +685,9 @@ public function getAddOneToOneRelationTests(): \Generator
682685
propertyName: 'userProfile',
683686
targetClassName: \App\Entity\UserProfile::class,
684687
mapInverseRelation: false,
688+
isOwning: true,
685689
))
686-
->setIsNullable(true)
687-
->setIsOwning(true),
690+
->setIsNullable(true),
688691
];
689692

690693
yield 'one_to_one_no_inverse_not_nullable' => [
@@ -694,9 +697,9 @@ public function getAddOneToOneRelationTests(): \Generator
694697
propertyName: 'userProfile',
695698
targetClassName: \App\Entity\UserProfile::class,
696699
mapInverseRelation: false,
700+
isOwning: true,
697701
))
698-
->setIsNullable(false)
699-
->setIsOwning(true),
702+
->setIsNullable(false),
700703
];
701704

702705
yield 'avoid_duplicate_use_statement' => [
@@ -706,9 +709,9 @@ public function getAddOneToOneRelationTests(): \Generator
706709
propertyName: 'userProfile',
707710
targetClassName: \App\OtherEntity\UserProfile::class,
708711
targetPropertyName: 'user',
712+
isOwning: true,
709713
))
710-
->setIsNullable(true)
711-
->setIsOwning(true),
714+
->setIsNullable(true),
712715
];
713716

714717
yield 'avoid_duplicate_use_statement_with_alias' => [
@@ -718,9 +721,9 @@ public function getAddOneToOneRelationTests(): \Generator
718721
propertyName: 'category',
719722
targetClassName: \App\OtherEntity\Category::class,
720723
targetPropertyName: 'user',
724+
isOwning: true,
721725
))
722-
->setIsNullable(true)
723-
->setIsOwning(true),
726+
->setIsNullable(true),
724727
];
725728
}
726729

0 commit comments

Comments
 (0)