Code Duplication    Length = 23-25 lines in 3 locations

src/Kunstmaan/GeneratorBundle/Generator/ArticleGenerator.php 1 location

@@ 488-510 (lines=23) @@
485
    /**
486
     * Update the getPossibleChildTypes function of the parent Page classes
487
     */
488
    public function updateParentPages()
489
    {
490
        $phpCode = "            [\n";
491
        $phpCode .= "                'name' => '" . $this->entity . "OverviewPage',\n";
492
        $phpCode .= "                'class'=> '" . $this->bundle->getNamespace() . '\\Entity\\Pages\\' . $this->entity . "OverviewPage'\n";
493
        $phpCode .= '            ],'."\n        ";
494
495
        // When there is a BehatTestPage, we should also allow the new page as sub page
496
        $behatTestPage = $this->bundle->getPath() . '/Entity/Pages/BehatTestPage.php';
497
        if (file_exists($behatTestPage)) {
498
            $this->parentPages[] = $behatTestPage;
499
        }
500
501
        foreach ($this->parentPages as $file) {
502
            $data = file_get_contents($file);
503
            $data = preg_replace(
504
                '/(function\s*getPossibleChildTypes\s*\(\)\s*\{\s*)(return\s*\[|return\s*array\()/',
505
                "$1$2\n$phpCode",
506
                $data
507
            );
508
            file_put_contents($file, $data);
509
        }
510
    }
511
}
512

src/Kunstmaan/GeneratorBundle/Generator/FormPageGenerator.php 1 location

@@ 214-238 (lines=25) @@
211
    /**
212
     * Update the getPossibleChildTypes function of the parent Page classes
213
     */
214
    private function updateParentPages()
215
    {
216
        $phpCode = "            [\n";
217
        $phpCode .= "                'name' => '" . $this->entity . "',\n";
218
        $phpCode .= "                'class'=> '" .
219
            $this->bundle->getNamespace() .
220
            '\\Entity\\Pages\\' . $this->entity . "'\n";
221
        $phpCode .= '            ],'."\n        ";
222
223
        // When there is a BehatTestPage, we should also allow the new page as sub page
224
        $behatTestPage = $this->bundle->getPath() . '/Entity/Pages/BehatTestPage.php';
225
        if (file_exists($behatTestPage)) {
226
            $this->parentPages[] = $behatTestPage;
227
        }
228
229
        foreach ($this->parentPages as $file) {
230
            $data = file_get_contents($file);
231
            $data = preg_replace(
232
                '/(function\s*getPossibleChildTypes\s*\(\)\s*\{\s*)(return\s*\[|return\s*array\()/',
233
                "$1$2\n$phpCode",
234
                $data
235
            );
236
            file_put_contents($file, $data);
237
        }
238
    }
239
}
240

src/Kunstmaan/GeneratorBundle/Generator/PageGenerator.php 1 location

@@ 165-189 (lines=25) @@
162
    /**
163
     * Update the getPossibleChildTypes function of the parent Page classes
164
     */
165
    private function updateParentPages()
166
    {
167
        $phpCode = "            [\n";
168
        $phpCode .= "                'name' => '" . $this->entity . "',\n";
169
        $phpCode .= "                'class'=> '" .
170
            $this->bundle->getNamespace() .
171
            '\\Entity\\Pages\\' . $this->entity . "'\n";
172
        $phpCode .= '            ],'."\n        ";
173
174
        // When there is a BehatTestPage, we should also allow the new page as sub page
175
        $behatTestPage = $this->bundle->getPath() . '/Entity/Pages/BehatTestPage.php';
176
        if (file_exists($behatTestPage)) {
177
            $this->parentPages[] = $behatTestPage;
178
        }
179
180
        foreach ($this->parentPages as $file) {
181
            $data = file_get_contents($file);
182
            $data = preg_replace(
183
                '/(function\s*getPossibleChildTypes\s*\(\)\s*\{\s*)(return\s*\[|return\s*array\()/',
184
                "$1$2\n$phpCode",
185
                $data
186
            );
187
            file_put_contents($file, $data);
188
        }
189
    }
190
}
191