Passed
Push — master ( 17804e...9c6a95 )
by Fran
06:14
created

GeneratorService   B

Complexity

Total Complexity 50

Size/Duplication

Total Lines 499
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 499
rs 8.6206
c 0
b 0
f 0
wmc 50
lcom 1
cbo 7

20 Methods

Rating   Name   Duplication   Size   Complexity  
B findTranslations() 0 29 6
A createStructureModule() 0 12 1
A createModulePath() 0 7 1
A createModulePathTree() 0 17 3
A createModuleBaseFiles() 0 12 1
B createModuleModels() 0 26 1
B generateControllerTemplate() 0 38 3
B generateBaseApiTemplate() 0 21 6
A generateConfigTemplate() 0 8 1
A generatePublicTemplates() 0 12 2
A generateServiceTemplate() 0 14 1
A genereateAutoloaderTemplate() 0 18 2
A generateSchemaTemplate() 0 14 1
A generatePropertiesTemplate() 0 16 1
A generateIndexTemplate() 0 11 1
A writeTemplateToFile() 0 15 4
A createApiBaseFile() 0 17 1
A createApi() 0 13 1
B copyResources() 0 15 7
B copyr() 0 15 6

How to fix   Complexity   

Complex Class

Complex classes like GeneratorService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use GeneratorService, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace PSFS\Services;
3
4
use PSFS\base\Cache;
5
use PSFS\base\exception\ConfigException;
6
use PSFS\base\Service;
7
use PSFS\base\types\helpers\GeneratorHelper;
8
9
class GeneratorService extends Service
10
{
11
    /**
12
     * @Inyectable
13
     * @var \PSFS\base\config\Config Servicio de configuración
14
     */
15
    protected $config;
16
    /**
17
     * @Inyectable
18
     * @var \PSFS\base\Security Servicio de autenticación
19
     */
20
    protected $security;
21
    /**
22
     * @Inyectable
23
     * @var \PSFS\base\Template Servicio de gestión de plantillas
24
     */
25
    protected $tpl;
26
27
    /**
28
     * Método que revisa las traducciones directorio a directorio
29
     * @param $path
30
     * @param $locale
31
     * @return array
32
     */
33
    public static function findTranslations($path, $locale)
34
    {
35
        $locale_path = realpath(BASE_DIR . DIRECTORY_SEPARATOR . 'locale');
36
        $locale_path .= DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR;
37
38
        $translations = array();
39
        if (file_exists($path)) {
40
            $d = dir($path);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $d. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
41
            while (false !== ($dir = $d->read())) {
42
                GeneratorHelper::createDir($locale_path);
43
                if (!file_exists($locale_path . 'translations.po')) {
44
                    file_put_contents($locale_path . 'translations.po', '');
45
                }
46
                $inspect_path = realpath($path . DIRECTORY_SEPARATOR . $dir);
47
                $cmd_php = "export PATH=\$PATH:/opt/local/bin; xgettext " .
48
                    $inspect_path . DIRECTORY_SEPARATOR .
49
                    "*.php --from-code=UTF-8 -j -L PHP --debug --force-po -o {$locale_path}translations.po";
50
                if (is_dir($path . DIRECTORY_SEPARATOR . $dir) && preg_match('/^\./', $dir) == 0) {
51
                    $res = _('Revisando directorio: ') . $inspect_path;
52
                    $res .= _('Comando ejecutado: ') . $cmd_php;
53
                    $res .= shell_exec($cmd_php);
54
                    usleep(10);
55
                    $translations[] = $res;
56
                    $translations = array_merge($translations, self::findTranslations($inspect_path, $locale));
57
                }
58
            }
59
        }
60
        return $translations;
61
    }
62
63
    /**
64
     * Servicio que genera la estructura de un módulo o lo actualiza en caso de ser necesario
65
     * @param string $module
66
     * @param boolean $force
67
     * @param string $type
68
     * @param string $apiClass
69
     * @return mixed
70
     */
71
    public function createStructureModule($module, $force = false, $type = "", $apiClass = "")
72
    {
73
        $mod_path = CORE_DIR . DIRECTORY_SEPARATOR;
74
        $module = ucfirst($module);
75
        $this->createModulePath($module, $mod_path);
76
        $this->createModulePathTree($module, $mod_path);
0 ignored issues
show
Documentation introduced by
$mod_path is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
77
        $this->createModuleBaseFiles($module, $mod_path, $force, $type);
78
        $this->createModuleModels($module, $mod_path);
79
        $this->generateBaseApiTemplate($module, $mod_path, $force, $apiClass);
80
        //Redireccionamos al home definido
81
        $this->log->infoLog("Módulo generado correctamente");
82
    }
83
84
    /**
85
     * Service that creates the root paths for the modules
86
     * @param string $module
87
     * @param string $mod_path
88
     * @param boolean $isModule
0 ignored issues
show
Documentation introduced by
There is no parameter named $isModule. Did you maybe mean $module?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
89
     */
90
    private function createModulePath($module, $mod_path)
91
    {
92
        // Creates the src folder
93
        GeneratorHelper::createDir($mod_path);
94
        // Create module path
95
        GeneratorHelper::createDir($mod_path . $module);
96
    }
97
98
    /**
99
     * Servicio que genera la estructura base
100
     * @param string $module
101
     * @param boolean $mod_path
102
     * @return boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
103
     */
104
    private function createModulePathTree($module, $mod_path)
105
    {
106
        //Creamos las carpetas CORE del módulo
107
        $this->log->infoLog("Generamos la estructura");
108
        $paths = [
109
            "Api", "Api/base", "Config", "Controller", "Form", "Models", "Public", "Templates", "Services", "Test"
110
        ];
111
        $module_path = $mod_path . $module;
112
        foreach ($paths as $path) {
113
            GeneratorHelper::createDir($module_path . DIRECTORY_SEPARATOR . $path);
114
        }
115
        //Creamos las carpetas de los assets
116
        $htmlPaths = array("css", "js", "img", "media", "font");
117
        foreach ($htmlPaths as $path) {
118
            GeneratorHelper::createDir($module_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . $path);
119
        }
120
    }
121
122
    /**
123
     * Servicio que genera las plantillas básicas de ficheros del módulo
124
     * @param string $module
125
     * @param string $mod_path
126
     * @param boolean $force
127
     * @param string $controllerType
128
     */
129
    private function createModuleBaseFiles($module, $mod_path, $force = false, $controllerType = '')
130
    {
131
        $module_path = $mod_path . $module;
132
        $this->generateControllerTemplate($module, $module_path, $force, $controllerType);
133
        $this->generateServiceTemplate($module, $module_path, $force);
134
        $this->genereateAutoloaderTemplate($module, $module_path, $force);
135
        $this->generateSchemaTemplate($module, $module_path, $force);
136
        $this->generatePropertiesTemplate($module, $module_path, $force);
137
        $this->generateConfigTemplate($module_path, $force);
138
        $this->generateIndexTemplate($module, $module_path, $force);
139
        $this->generatePublicTemplates($module_path, $force);
140
    }
141
142
    /**
143
     * Servicio que ejecuta Propel y genera el modelo de datos
144
     * @param string $module
145
     * @param string $path
146
     */
147
    private function createModuleModels($module, $path)
148
    {
149
        $module_path = $path . $module;
150
        $module_path = str_replace(CORE_DIR . DIRECTORY_SEPARATOR, '', $module_path);
151
        //Generamos las clases de propel y la configuración
152
        $exec = "export PATH=\$PATH:/opt/local/bin; " . BASE_DIR . DIRECTORY_SEPARATOR .
153
            "vendor" . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "propel ";
154
        $schemaOpt = " --schema-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module_path .
155
            DIRECTORY_SEPARATOR . "Config";
156
        $opt = " --config-dir=" . CORE_DIR . DIRECTORY_SEPARATOR . $module_path . DIRECTORY_SEPARATOR .
157
            "Config --output-dir=" . CORE_DIR . " --verbose";
158
        $this->log->infoLog("[GENERATOR] Ejecutamos propel:\n" . $exec . "build" . $opt . $schemaOpt);
159
        $ret = shell_exec($exec . "build" . $opt . $schemaOpt);
160
161
        $this->log->infoLog("[GENERATOR] Generamos clases invocando a propel:\n $ret");
162
        $ret = shell_exec($exec . "sql:build" . $opt . " --output-dir=" . CORE_DIR . DIRECTORY_SEPARATOR .
163
            $module_path . DIRECTORY_SEPARATOR . "Config" . $schemaOpt);
164
        $this->log->infoLog("[GENERATOR] Generamos sql invocando a propel:\n $ret");
165
166
        $configTemplate = $this->tpl->dump("generator/config.propel.template.twig", array(
167
            "module" => $module,
168
        ));
169
        $this->writeTemplateToFile($configTemplate, CORE_DIR . DIRECTORY_SEPARATOR . $module_path . DIRECTORY_SEPARATOR . "Config" .
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
170
            DIRECTORY_SEPARATOR . "config.php", true);
171
        $this->log->infoLog("Generado config genérico para propel:\n $ret");
172
    }
173
174
    /**
175
     * @param string $module
176
     * @param string $mod_path
177
     * @param boolean $force
178
     * @param string $controllerType
179
     * @return boolean
180
     */
181
    private function generateControllerTemplate($module, $mod_path, $force = false, $controllerType = "")
182
    {
183
        //Generamos el controlador base
184
        $this->log->infoLog("Generamos el controlador BASE");
185
        $class = preg_replace('/(\\\|\/)/', '', $module);
186
        $controllerBody = $this->tpl->dump("generator/controller.template.twig", array(
187
            "module" => $module,
188
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
189
            "url" => preg_replace('/(\\\|\/)/', '/', $module),
190
            "class" => $class,
191
            "controllerType" => $class . "Base",
192
            "is_base" => false
193
        ));
194
        $controller = $this->writeTemplateToFile($controllerBody, $mod_path . DIRECTORY_SEPARATOR . "Controller" .
195
            DIRECTORY_SEPARATOR . "{$class}Controller.php", $force);
196
197
        $controllerBody = $this->tpl->dump("generator/controller.template.twig", array(
198
            "module" => $module,
199
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
200
            "url" => preg_replace('/(\\\|\/)/', '/', $module),
201
            "class" => $class . "Base",
202
            "service" => $class,
203
            "controllerType" => $controllerType,
204
            "is_base" => true,
205
            "domain" => $class,
206
        ));
207
        $controllerBase = $this->writeTemplateToFile($controllerBody, $mod_path . DIRECTORY_SEPARATOR . "Controller" .
208
            DIRECTORY_SEPARATOR . "base" . DIRECTORY_SEPARATOR . "{$class}BaseController.php", true);
209
210
        $testTemplate = $this->tpl->dump("generator/testCase.template.twig", array(
211
            "module" => $module,
212
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
213
            "class" => $class,
214
        ));
215
        $test = $this->writeTemplateToFile($testTemplate, $mod_path . DIRECTORY_SEPARATOR . "Test" .
216
            DIRECTORY_SEPARATOR . "{$class}Test.php", true);
217
        return ($controller && $controllerBase && $test);
218
    }
219
220
    /**
221
     * @param string $module
222
     * @param string $mod_path
223
     * @param boolean $force
224
     * @param string $apiClass
225
     * @return boolean
226
     */
227
    private function generateBaseApiTemplate($module, $mod_path, $force = false, $apiClass = "")
228
    {
229
        $created = true;
230
        $modelPath = $mod_path . $module . DIRECTORY_SEPARATOR . 'Models';
231
        $api_path = $mod_path . $module . DIRECTORY_SEPARATOR . 'Api';
232
        if (file_exists($modelPath)) {
233
            $dir = dir($modelPath);
234
            while ($file = $dir->read()) {
235
                if (!in_array($file, array('.', '..'))
236
                    && !preg_match('/Query\.php$/i', $file)
237
                    && preg_match('/\.php$/i', $file)
238
                ) {
239
                    $filename = str_replace(".php", "", $file);
240
                    $this->log->infoLog("Generamos Api BASES para {$filename}");
241
                    $this->createApiBaseFile($module, $api_path, $filename, $apiClass);
242
                    $this->createApi($module, $api_path, $force, $filename);
243
                }
244
            }
245
        }
246
        return $created;
247
    }
248
249
    /**
250
     * @param string $mod_path
251
     * @param boolean $force
252
     * @return boolean
253
     */
254
    private function generateConfigTemplate($mod_path, $force = false)
255
    {
256
        //Generamos el fichero de configuración
257
        $this->log->infoLog("Generamos fichero vacío de configuración");
258
        return $this->writeTemplateToFile("<?php\n\t",
259
            $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "config.php",
260
            $force);
261
    }
262
263
    /**
264
     * @param string $mod_path
265
     * @param string $mod_path
266
     * @param boolean $force
267
     * @return boolean
268
     */
269
    private function generatePublicTemplates($mod_path, $force = false)
270
    {
271
        //Generamos el fichero de configuración
272
        $this->log->infoLog("Generamos ficheros para assets base");
273
        $css = $this->writeTemplateToFile("/* CSS3 STYLES */\n\n",
274
            $mod_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . "css" . DIRECTORY_SEPARATOR . "styles.css",
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
275
            $force);
276
        $js = $this->writeTemplateToFile("/* APP MODULE JS */\n\n(function() {\n\t'use strict';\n})();",
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $js. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
277
            $mod_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . "js" . DIRECTORY_SEPARATOR . "app.js",
278
            $force);
279
        return ($css && $js);
280
    }
281
282
    /**
283
     * @param string $module
284
     * @param string $mod_path
285
     * @param boolean $force
286
     * @return boolean
287
     */
288
    private function generateServiceTemplate($module, $mod_path, $force = false)
289
    {
290
        //Generamos el controlador base
291
        $this->log->infoLog("Generamos el servicio BASE");
292
        $class = preg_replace('/(\\\|\/)/', '', $module);
293
        $controller = $this->tpl->dump("generator/service.template.twig", array(
294
            "module" => $module,
295
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
296
            "class" => $class,
297
        ));
298
        return $this->writeTemplateToFile($controller,
299
            $mod_path . DIRECTORY_SEPARATOR . "Services" . DIRECTORY_SEPARATOR . "{$class}Service.php",
300
            $force);
301
    }
302
303
    /**
304
     * @param string $module
305
     * @param string $mod_path
306
     * @param boolean $force
307
     * @return boolean
308
     */
309
    private function genereateAutoloaderTemplate($module, $mod_path, $force = false)
310
    {
311
        //Generamos el autoloader del módulo
312
        $this->log->infoLog("Generamos el autoloader");
313
        $autoloader = $this->tpl->dump("generator/autoloader.template.twig", array(
314
            "module" => $module,
315
            "autoloader" => preg_replace('/(\\\|\/)/', '_', $module),
316
            "regex" => preg_replace('/(\\\|\/)/m', '\\\\\\\\\\\\', $module),
317
        ));
318
        $autoload = $this->writeTemplateToFile($autoloader, $mod_path . DIRECTORY_SEPARATOR . "autoload.php", $force);
319
320
        $this->log->infoLog("Generamos el phpunit");
321
        $phpUnitTemplate = $this->tpl->dump("generator/phpunit.template.twig", array(
322
            "module" => $module,
323
        ));
324
        $phpunit = $this->writeTemplateToFile($phpUnitTemplate, $mod_path . DIRECTORY_SEPARATOR . "phpunit.xml.dist", $force);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 126 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
325
        return $autoload && $phpunit;
326
    }
327
328
    /**
329
     * @param string $module
330
     * @param string $mod_path
331
     * @param boolean $force
332
     * @return boolean
333
     */
334
    private function generateSchemaTemplate($module, $mod_path, $force = false)
335
    {
336
        //Generamos el autoloader del módulo
337
        $this->log->infoLog("Generamos el schema");
338
        $schema = $this->tpl->dump("generator/schema.propel.twig", array(
339
            "module" => $module,
340
            "namespace" => preg_replace('/(\\\|\/)/', '', $module),
341
            "prefix" => preg_replace('/(\\\|\/)/', '', $module),
342
            "db" => $this->config->get("db_name"),
343
        ));
344
        return $this->writeTemplateToFile($schema,
345
            $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "schema.xml",
346
            $force);
347
    }
348
349
    /**
350
     * @param string $module
351
     * @param string $mod_path
352
     * @param boolean $force
353
     * @return boolean
354
     */
355
    private function generatePropertiesTemplate($module, $mod_path, $force = false)
356
    {
357
        $this->log->infoLog("Generamos la configuración de Propel");
358
        $build_properties = $this->tpl->dump("generator/build.properties.twig", array(
359
            "module" => $module,
360
            "host" => $this->config->get("db_host"),
361
            "port" => $this->config->get("db_port"),
362
            "user" => $this->config->get("db_user"),
363
            "pass" => $this->config->get("db_password"),
364
            "db" => $this->config->get("db_name"),
365
            "namespace" => preg_replace('/(\\\|\/)/', '', $module),
366
        ));
367
        return $this->writeTemplateToFile($build_properties,
368
            $mod_path . DIRECTORY_SEPARATOR . "Config" . DIRECTORY_SEPARATOR . "propel.yml",
369
            $force);
370
    }
371
372
    /**
373
     * @param string $module
374
     * @param string $mod_path
375
     * @param boolean $force
376
     * @return boolean
377
     */
378
    private function generateIndexTemplate($module, $mod_path, $force = false)
379
    {
380
        //Generamos la plantilla de index
381
        $this->log->infoLog("Generamos una plantilla base por defecto");
382
        $index = $this->tpl->dump("generator/index.template.twig", array(
383
            "module" => $module,
384
        ));
385
        return $this->writeTemplateToFile($index,
386
            $mod_path . DIRECTORY_SEPARATOR . "Templates" . DIRECTORY_SEPARATOR . "index.html.twig",
387
            $force);
388
    }
389
390
    /**
391
     * Método que graba el contenido de una plantilla en un fichero
392
     * @param string $fileContent
393
     * @param string $filename
394
     * @param boolean $force
395
     * @return boolean
396
     */
397
    private function writeTemplateToFile($fileContent, $filename, $force = false)
398
    {
399
        $created = false;
400
        if ($force || !file_exists($filename)) {
401
            try {
402
                $this->cache->storeData($filename, $fileContent, Cache::TEXT, true);
403
                $created = true;
404
            } catch (\Exception $e) {
405
                $this->log->errorLog($e->getMessage());
406
            }
407
        } else {
408
            $this->log->errorLog($filename . _(' not exists or cant write'));
409
        }
410
        return $created;
411
    }
412
413
    /**
414
     * Create ApiBase
415
     * @param string $module
416
     * @param string $mod_path
417
     * @param string $api
418
     * @param string $apiClass
419
     *
420
     * @return bool
421
     */
422
    private function createApiBaseFile($module, $mod_path, $api, $apiClass = '')
423
    {
424
        $class = preg_replace('/(\\\|\/)/', '', $module);
425
        $customClass = GeneratorHelper::extractClassFromNamespace($apiClass);
426
        $controller = $this->tpl->dump("generator/api.base.template.twig", array(
427
            "module" => $module,
428
            "api" => $api,
429
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
430
            "url" => preg_replace('/(\\\|\/)/', '/', $module),
431
            "class" => $class,
432
            'customClass' => $customClass,
433
            'customNamespace' => $apiClass,
434
        ));
435
436
        return $this->writeTemplateToFile($controller,
437
            $mod_path . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . "{$api}BaseApi.php", true);
438
    }
439
440
    /**
441
     * Create Api
442
     * @param string $module
443
     * @param string $mod_path
444
     * @param bool $force
445
     * @param string $api
446
     *
447
     * @return bool
448
     */
449
    private function createApi($module, $mod_path, $force, $api)
450
    {
451
        $class = preg_replace('/(\\\|\/)/', '', $module);
452
        $controller = $this->tpl->dump("generator/api.template.twig", array(
453
            "module" => $module,
454
            "api" => $api,
455
            "namespace" => preg_replace('/(\\\|\/)/', '\\', $module),
456
            "url" => preg_replace('/(\\\|\/)/', '/', $module),
457
            "class" => $class,
458
        ));
459
460
        return $this->writeTemplateToFile($controller, $mod_path . DIRECTORY_SEPARATOR . "{$api}.php", $force);
461
    }
462
463
    /**
464
     * Method that copy resources recursively
465
     * @param string $dest
466
     * @param boolean $force
467
     * @param $filename_path
468
     * @param boolean $debug
469
     */
470
    public static function copyResources($dest, $force, $filename_path, $debug)
471
    {
472
        if (file_exists($filename_path)) {
473
            $destfolder = basename($filename_path);
474
            if (!file_exists(WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) || $debug || $force) {
475
                if (is_dir($filename_path)) {
476
                    self::copyr($filename_path, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder);
477
                } else {
478
                    if (@copy($filename_path, WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder) === FALSE) {
479
                        throw new ConfigException("Can't copy " . $filename_path . " to " . WEB_DIR . $dest . DIRECTORY_SEPARATOR . $destfolder);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
480
                    }
481
                }
482
            }
483
        }
484
    }
485
486
    /**
487
     * Method that copy a resource
488
     * @param string $src
489
     * @param string $dst
490
     * @throws ConfigException
491
     */
492
    public static function copyr($src, $dst)
493
    {
494
        $dir = opendir($src);
495
        GeneratorHelper::createDir($dst);
496
        while (false !== ($file = readdir($dir))) {
497
            if (($file != '.') && ($file != '..')) {
498
                if (is_dir($src . '/' . $file)) {
499
                    self::copyr($src . '/' . $file, $dst . '/' . $file);
500
                } elseif (@copy($src . '/' . $file, $dst . '/' . $file) === false) {
501
                    throw new ConfigException("Can't copy " . $src . " to " . $dst);
502
                }
503
            }
504
        }
505
        closedir($dir);
506
    }
507
}
508