Groups of groups does not work

Tibor Sári
2021-01-27T08:43:42Z

When I want to have groups within groups in the api.yml the parent cannot be an EntityArrayCollection.
When the child is an ArrayCollection the parent also has to an ArrayCollection as an ArrayCollection does not implement the EntityInterface.

```
Index: tests/Generator/EntityGeneratorTest.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/Generator/EntityGeneratorTest.php b/tests/Generator/EntityGeneratorTest.php
--- a/tests/Generator/EntityGeneratorTest.php (revision 864e6be69735b186374fa6f593977eddcddc8836)
+++ b/tests/Generator/EntityGeneratorTest.php (date 1611736361038)
@@ -162,7 +162,6 @@
namespace Test\GeneratedEntities;

use SimpleCollection\ArrayCollection;
-use SimpleCollection\Entity\EntityArrayCollection;
use Test\Collections\ItemCollection;
use Test\Entities\Country;
use Test\Entities\Item;
@@ -174,7 +173,7 @@
public ArrayCollection \$cities;
public Country \$country;
public ?Item \$item;
- public EntityArrayCollection \$itemGroups;
+ public ArrayCollection \$itemGroups;
public ItemCollection \$itemGroup;
public function populate(array \$data)
{
@@ -192,7 +191,7 @@
}
\$this->country = new Country(\$data['country'] ?? []);
\$this->item = isset(\$data['item']) ? new Item(\$data['item']) : null;
- \$this->itemGroups = new EntityArrayCollection();
+ \$this->itemGroups = new ArrayCollection();
foreach (\$data['item-groups'] ?? [] as \$item) {
\$this->itemGroups->add(new ArrayCollection(\$item));
}
Index: src/Generator/Pattern/GeneratedEntity/Property.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Generator/Pattern/GeneratedEntity/Property.php b/src/Generator/Pattern/GeneratedEntity/Property.php
--- a/src/Generator/Pattern/GeneratedEntity/Property.php (revision 864e6be69735b186374fa6f593977eddcddc8836)
+++ b/src/Generator/Pattern/GeneratedEntity/Property.php (date 1611735896535)
@@ -21,22 +21,22 @@
class Property extends AbstractPattern
{
protected Collector $collector;
+
protected PropertyPattern $pattern;
+
protected string $type;

-
public function __construct(
GenerationConfig $config,
string $targetNamespace,
UseCollector $useCollector,
Collector $collector,
PropertyPattern $pattern
- )
- {
+ ) {
parent::__construct($config, $targetNamespace, $useCollector);
$this->collector = $collector;
- $this->pattern = $pattern;
- $this->type = $this->determineType($pattern);
+ $this->pattern = $pattern;
+ $this->type = $this->determineType($pattern);
}

public function getPattern(): PropertyPattern
@@ -67,6 +67,7 @@
) {
$typePrefix = '?';
}
+
return $typePrefix . $this->type;
}

@@ -97,7 +98,9 @@
$contentPattern instanceof EntityPattern ||
$contentPattern instanceof AbstractContainerPattern
) {
- if ($pattern instanceof ArrayPattern) {
+ if ($pattern instanceof ArrayPattern && $contentPattern instanceof ArrayPattern) {
+ $type = ArrayCollection::class;
+ } elseif ($pattern instanceof ArrayPattern) {
$type = EntityArrayCollection::class;
} elseif ($pattern instanceof AssocPattern) {
$type = AssocCollection::class;
@@ -114,6 +117,7 @@
$type = AssocCollection::class;
}
}
+
return $type;
}
}
\ No newline at end of file
```