DataBuilderGenerator creates invalid code


#1

When does the bug occur:

When calling console transfer:databuilder:generate the Generated\Shared\DataBuilder\ReclamationBuilder will contain the methods withOrder() and withAnotherOrder twice, as the order dependency is added twice but with different casing (order and Order).
The issue does occur with the recent demoshop (tested commit: https://github.com/spryker/demoshop/commit/1dcb5b1f9b11c56f2e8c7d7a45314aa3da45e119)

Why does this is an issue:
As soon as the code needs to be compiled or executed, for example to cache it via opcode cache, it will fail the compilation process. This could lead to an empty opcode cache and therefore decrease the performance in a production system or worse trigger an opcode cache regeneration for the given file every time it is executed with the same falling result.

Possible solution:
I could solve it with the following patch (using a normalized case version for dependencies to avoid duplicated dependencies).

Index: vendor/spryker/transfer/src/Spryker/Zed/Transfer/Business/Model/Generator/DataBuilderDefinition.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- vendor/spryker/transfer/src/Spryker/Zed/Transfer/Business/Model/Generator/DataBuilderDefinition.php	(date 1548398538000)
+++ vendor/spryker/transfer/src/Spryker/Zed/Transfer/Business/Model/Generator/DataBuilderDefinition.php	(date 1548398538000)
@@ -68,9 +68,10 @@
                 if (isset($property['singular']) && !isset($this->dependencies[$property['singular']])) {
                     $property['name'] = $property['singular'];
                 }
-                $property['ucfirstName'] = ucfirst($property['name']);
+                $uppercaseName = ucfirst($property['name']);
+                $property['ucfirstName'] = $uppercaseName;
                 $property['type'] = str_replace('[]', '', $property['type']); // remove array marker
-                $this->dependencies[$property['name']] = $property;
+                $this->dependencies[$uppercaseName] = $property;
                 continue;
             }

#2

Hi Alberto,

Thank you for the feedback. The ticket is created. I will notify when it is fixed.

Best regards,
Valerii