Olivier Massot 1 год назад
Родитель
Сommit
92a03b2213
1 измененных файлов с 27 добавлено и 5 удалено
  1. 27 5
      src/Service/Doctrine/SchemaValidation/SchemaSnippetsMaker.php

+ 27 - 5
src/Service/Doctrine/SchemaValidation/SchemaSnippetsMaker.php

@@ -81,7 +81,7 @@ class SchemaSnippetsMaker
 
                 $class->addMember($prop);
 
-                $methods = [...$methods, ...$this->makeMethodsSnippetForProp($field, $prop) ];
+                $methods = [...$methods, ...$this->makeMethodsSnippetForProp($prop)];
             }
 
             foreach ($methods as $method) {
@@ -108,11 +108,16 @@ class SchemaSnippetsMaker
         }
     }
 
-    protected function makeMethodsSnippetForProp(string $field, Property $prop): array {
+    /**
+     * Make the getters / setters for the given property
+     *
+     * @param Property $prop
+     * @return array<Method>
+     */
+    protected function makeMethodsSnippetForProp(Property $prop): array {
         $methods = [];
 
-        if ($prop->getType() !== 'Collection')
-        {
+        if ($prop->getType() !== 'Collection') {
             $methods[] = $this->makeSnippetGetterForProp($prop);
             $methods[] = $this->makeSnippetSetterForProp($prop);
         } else {
@@ -198,9 +203,13 @@ class SchemaSnippetsMaker
         }
 
         $printer = new PsrPrinter;
+
+        $content = $printer->printFile($phpFile);
+        $content = $this->postProcessFileContent($content);
+
         $f = fopen($fileName, 'w+');
         try {
-            fwrite($f, $printer->printFile($phpFile));
+            fwrite($f, $content);
         } finally {
             fclose($f);
         }
@@ -518,4 +527,17 @@ class SchemaSnippetsMaker
         );
         return $method;
     }
+
+    /**
+     * Perform some post-fixes on the file content
+     *
+     * @param string $content
+     * @return string
+     */
+    protected function postProcessFileContent(string $content): string
+    {
+        return preg_replace("/targetEntity: '(\w+)::class'/", "targetEntity: $1::class", $content);
+    }
+
+
 }