Skip to content

Commit f830df5

Browse files
committed
move is nullable to base relation
1 parent ff75c96 commit f830df5

File tree

5 files changed

+42
-58
lines changed

5 files changed

+42
-58
lines changed

src/Doctrine/BaseRelation.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(
2727
private ?string $customReturnType = null,
2828
private bool $isOwning = false,
2929
private bool $orphanRemoval = false,
30+
private bool $isNullable = false,
3031
) {
3132
}
3233

@@ -79,4 +80,9 @@ public function getOrphanRemoval(): bool
7980
{
8081
return $this->orphanRemoval;
8182
}
83+
84+
public function isNullable(): bool
85+
{
86+
return $this->isNullable;
87+
}
8288
}

src/Doctrine/BaseSingleRelation.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,4 @@
1616
*/
1717
abstract class BaseSingleRelation extends BaseRelation
1818
{
19-
private $isNullable;
20-
21-
public function isNullable(): bool
22-
{
23-
if ($this->isNullable) {
24-
return $this->isNullable;
25-
}
26-
27-
return false;
28-
}
29-
30-
public function setIsNullable(bool $isNullable): self
31-
{
32-
$this->isNullable = $isNullable;
33-
34-
return $this;
35-
}
3619
}

src/Doctrine/EntityRegenerator.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@ public function regenerateEntities(string $classOrNamespace): void
128128
targetPropertyName: $mapping['inversedBy'],
129129
mapInverseRelation: null !== $mapping['inversedBy'],
130130
isOwning: true,
131-
))
132-
->setIsNullable($getIsNullable($mapping))
133-
;
131+
isNullable: $getIsNullable($mapping),
132+
));
134133

135134
$manipulator->addManyToOneRelation($relation);
136135

@@ -165,9 +164,8 @@ public function regenerateEntities(string $classOrNamespace): void
165164
targetPropertyName: $mapping['isOwningSide'] ? $mapping['inversedBy'] : $mapping['mappedBy'],
166165
mapInverseRelation: $mapping['isOwningSide'] ? (null !== $mapping['inversedBy']) : true,
167166
isOwning: $mapping['isOwningSide'],
168-
))
169-
->setIsNullable($getIsNullable($mapping))
170-
;
167+
isNullable: $getIsNullable($mapping),
168+
));
171169

172170
$manipulator->addOneToOneRelation($relation);
173171

src/Doctrine/EntityRelation.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public function getOwningRelation(): RelationManyToMany|RelationOneToOne|Relatio
8888
isSelfReferencing: $this->isSelfReferencing,
8989
mapInverseRelation: $this->mapInverseRelation,
9090
isOwning: true,
91-
))
92-
->setIsNullable($this->isNullable),
91+
isNullable: $this->isNullable,
92+
)),
9393
self::MANY_TO_MANY => (new RelationManyToMany(
9494
propertyName: $this->owningProperty,
9595
targetClassName: $this->inverseClass,
@@ -105,8 +105,8 @@ public function getOwningRelation(): RelationManyToMany|RelationOneToOne|Relatio
105105
isSelfReferencing: $this->isSelfReferencing,
106106
mapInverseRelation: $this->mapInverseRelation,
107107
isOwning: true,
108-
))
109-
->setIsNullable($this->isNullable),
108+
isNullable: $this->isNullable,
109+
)),
110110
default => throw new \InvalidArgumentException('Invalid type'),
111111
};
112112
}
@@ -131,9 +131,9 @@ public function getInverseRelation(): RelationManyToMany|RelationOneToOne|Relati
131131
propertyName: $this->inverseProperty,
132132
targetClassName: $this->owningClass,
133133
targetPropertyName: $this->owningProperty,
134-
isSelfReferencing: $this->isSelfReferencing
135-
))
136-
->setIsNullable($this->isNullable),
134+
isSelfReferencing: $this->isSelfReferencing,
135+
isNullable: $this->isNullable,
136+
)),
137137
default => throw new \InvalidArgumentException('Invalid type'),
138138
};
139139
}

tests/Util/ClassSourceManipulatorTest.php

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,7 @@ public function getAddManyToOneRelationTests(): \Generator
382382
targetClassName: \App\Entity\Category::class,
383383
targetPropertyName: 'foods',
384384
isOwning: true,
385-
))
386-
->setIsNullable(false),
385+
)),
387386
];
388387

389388
yield 'many_to_one_nullable' => [
@@ -394,8 +393,8 @@ public function getAddManyToOneRelationTests(): \Generator
394393
targetClassName: \App\Entity\Category::class,
395394
targetPropertyName: 'foods',
396395
isOwning: true,
397-
))
398-
->setIsNullable(true),
396+
isNullable: true,
397+
)),
399398
];
400399

401400
yield 'many_to_one_other_namespace' => [
@@ -406,8 +405,8 @@ public function getAddManyToOneRelationTests(): \Generator
406405
targetClassName: \Foo\Entity\Category::class,
407406
targetPropertyName: 'foods',
408407
isOwning: true,
409-
))
410-
->setIsNullable(true),
408+
isNullable: true,
409+
)),
411410
];
412411

413412
yield 'many_to_one_empty_other_namespace' => [
@@ -418,8 +417,8 @@ public function getAddManyToOneRelationTests(): \Generator
418417
targetClassName: \Foo\Entity\Category::class,
419418
targetPropertyName: 'foods',
420419
isOwning: true,
421-
))
422-
->setIsNullable(true),
420+
isNullable: true,
421+
)),
423422
];
424423

425424
yield 'many_to_one_same_and_other_namespaces' => [
@@ -430,8 +429,8 @@ public function getAddManyToOneRelationTests(): \Generator
430429
targetClassName: \App\Entity\SubDirectory\Category::class,
431430
targetPropertyName: 'foods',
432431
isOwning: true,
433-
))
434-
->setIsNullable(true),
432+
isNullable: true,
433+
)),
435434
];
436435

437436
yield 'many_to_one_no_inverse' => [
@@ -443,8 +442,8 @@ public function getAddManyToOneRelationTests(): \Generator
443442
targetPropertyName: 'foods',
444443
mapInverseRelation: false,
445444
isOwning: true,
446-
))
447-
->setIsNullable(true),
445+
isNullable: true,
446+
)),
448447
];
449448
}
450449

@@ -637,8 +636,8 @@ public function getAddOneToOneRelationTests(): \Generator
637636
targetClassName: \App\Entity\UserProfile::class,
638637
targetPropertyName: 'user',
639638
isOwning: true,
640-
))
641-
->setIsNullable(true),
639+
isNullable: true,
640+
)),
642641
];
643642

644643
// a relationship to yourself - return type is self
@@ -650,8 +649,8 @@ public function getAddOneToOneRelationTests(): \Generator
650649
targetClassName: \App\Entity\User::class,
651650
targetPropertyName: 'user',
652651
isOwning: true,
653-
))
654-
->setIsNullable(true),
652+
isNullable: true,
653+
)),
655654
];
656655

657656
yield 'one_to_one_inverse' => [
@@ -661,8 +660,8 @@ public function getAddOneToOneRelationTests(): \Generator
661660
propertyName: 'user',
662661
targetClassName: \App\Entity\User::class,
663662
targetPropertyName: 'userProfile',
664-
))
665-
->setIsNullable(true),
663+
isNullable: true,
664+
)),
666665
];
667666

668667
yield 'one_to_one_inverse_not_nullable' => [
@@ -672,8 +671,7 @@ public function getAddOneToOneRelationTests(): \Generator
672671
propertyName: 'user',
673672
targetClassName: \App\Entity\User::class,
674673
targetPropertyName: 'userProfile',
675-
))
676-
->setIsNullable(false),
674+
)),
677675
];
678676

679677
yield 'one_to_one_no_inverse' => [
@@ -684,8 +682,8 @@ public function getAddOneToOneRelationTests(): \Generator
684682
targetClassName: \App\Entity\UserProfile::class,
685683
mapInverseRelation: false,
686684
isOwning: true,
687-
))
688-
->setIsNullable(true),
685+
isNullable: true,
686+
)),
689687
];
690688

691689
yield 'one_to_one_no_inverse_not_nullable' => [
@@ -696,8 +694,7 @@ public function getAddOneToOneRelationTests(): \Generator
696694
targetClassName: \App\Entity\UserProfile::class,
697695
mapInverseRelation: false,
698696
isOwning: true,
699-
))
700-
->setIsNullable(false),
697+
)),
701698
];
702699

703700
yield 'avoid_duplicate_use_statement' => [
@@ -708,8 +705,8 @@ public function getAddOneToOneRelationTests(): \Generator
708705
targetClassName: \App\OtherEntity\UserProfile::class,
709706
targetPropertyName: 'user',
710707
isOwning: true,
711-
))
712-
->setIsNullable(true),
708+
isNullable: true,
709+
)),
713710
];
714711

715712
yield 'avoid_duplicate_use_statement_with_alias' => [
@@ -720,8 +717,8 @@ public function getAddOneToOneRelationTests(): \Generator
720717
targetClassName: \App\OtherEntity\Category::class,
721718
targetPropertyName: 'user',
722719
isOwning: true,
723-
))
724-
->setIsNullable(true),
720+
isNullable: true,
721+
)),
725722
];
726723
}
727724

0 commit comments

Comments
 (0)