Completed
Pull Request — master (#1088)
by
unknown
02:55
created

ModuleGenerator::generate()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5.3256

Importance

Changes 0
Metric Value
cc 5
nc 9
nop 0
dl 0
loc 33
ccs 13
cts 17
cp 0.7647
crap 5.3256
rs 9.0808
c 0
b 0
f 0
1
<?php
2
3
namespace Nwidart\Modules\Generators;
4
5
use Illuminate\Config\Repository as Config;
6
use Illuminate\Console\Command as Console;
7
use Illuminate\Filesystem\Filesystem;
8
use Illuminate\Support\Str;
9
use Nwidart\Modules\Contracts\ActivatorInterface;
10
use Nwidart\Modules\FileRepository;
11
use Nwidart\Modules\Support\Config\GenerateConfigReader;
12
use Nwidart\Modules\Support\Stub;
13
14
class ModuleGenerator extends Generator
15
{
16
    /**
17
     * The module name will created.
18
     *
19
     * @var string
20
     */
21
    protected $name;
22
23
    /**
24
     * The laravel config instance.
25
     *
26
     * @var Config
27
     */
28
    protected $config;
29
30
    /**
31
     * The laravel filesystem instance.
32
     *
33
     * @var Filesystem
34
     */
35
    protected $filesystem;
36
37
    /**
38
     * The laravel console instance.
39
     *
40
     * @var Console
41
     */
42
    protected $console;
43
44
    /**
45
     * The activator instance
46
     *
47
     * @var ActivatorInterface
48
     */
49
    protected $activator;
50
51
    /**
52
     * The module instance.
53
     *
54
     * @var \Nwidart\Modules\Module
55
     */
56
    protected $module;
57
58
    /**
59
     * Force status.
60
     *
61
     * @var bool
62
     */
63
    protected $force = false;
64
65
    /**
66
     * Generate a plain module.
67
     *
68
     * @var bool
69
     */
70
    protected $plain = false;
71
72
    /**
73
     * Enables the module.
74
     *
75
     * @var bool
76
     */
77
    protected $isActive = false;
78
79
    /**
80
     * The constructor.
81
     * @param $name
82
     * @param FileRepository $module
83
     * @param Config     $config
84
     * @param Filesystem $filesystem
85
     * @param Console    $console
86
     */
87 4
    public function __construct(
88
        $name,
89
        FileRepository $module = null,
90
        Config $config = null,
91
        Filesystem $filesystem = null,
92
        Console $console = null,
93
        ActivatorInterface $activator = null
94
    ) {
95 4
        $this->name = $name;
96 4
        $this->config = $config;
97 4
        $this->filesystem = $filesystem;
98 4
        $this->console = $console;
99 4
        $this->module = $module;
0 ignored issues
show
Documentation Bug introduced by
It seems like $module can also be of type object<Nwidart\Modules\FileRepository>. However, the property $module is declared as type object<Nwidart\Modules\Module>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
100 4
        $this->activator = $activator;
101 4
    }
102
103
    /**
104
     * Set plain flag.
105
     *
106
     * @param bool $plain
107
     *
108
     * @return $this
109
     */
110 4
    public function setPlain($plain)
111
    {
112 4
        $this->plain = $plain;
113
114 4
        return $this;
115
    }
116
117
    /**
118
     * Set active flag.
119
     *
120
     * @param bool $active
121
     *
122
     * @return $this
123
     */
124 4
    public function setActive(bool $active)
125
    {
126 4
        $this->isActive = $active;
127
128 4
        return $this;
129
    }
130
131
    /**
132
     * Get the name of module will created. By default in studly case.
133
     *
134
     * @return string
135
     */
136 4
    public function getName()
137
    {
138 4
        return Str::studly($this->name);
139
    }
140
141
    /**
142
     * Get the laravel config instance.
143
     *
144
     * @return Config
145
     */
146
    public function getConfig()
147
    {
148
        return $this->config;
149
    }
150
151
    /**
152
     * Set the laravel config instance.
153
     *
154
     * @param Config $config
155
     *
156
     * @return $this
157
     */
158 4
    public function setConfig($config)
159
    {
160 4
        $this->config = $config;
161
162 4
        return $this;
163
    }
164
165
    /**
166
     * Set the modules activator
167
     *
168
     * @param ActivatorInterface $activator
169
     *
170
     * @return $this
171
     */
172 4
    public function setActivator(ActivatorInterface $activator)
173
    {
174 4
        $this->activator = $activator;
175
176 4
        return $this;
177
    }
178
179
    /**
180
     * Get the laravel filesystem instance.
181
     *
182
     * @return Filesystem
183
     */
184
    public function getFilesystem()
185
    {
186
        return $this->filesystem;
187
    }
188
189
    /**
190
     * Set the laravel filesystem instance.
191
     *
192
     * @param Filesystem $filesystem
193
     *
194
     * @return $this
195
     */
196 4
    public function setFilesystem($filesystem)
197
    {
198 4
        $this->filesystem = $filesystem;
199
200 4
        return $this;
201
    }
202
203
    /**
204
     * Get the laravel console instance.
205
     *
206
     * @return Console
207
     */
208
    public function getConsole()
209
    {
210
        return $this->console;
211
    }
212
213
    /**
214
     * Set the laravel console instance.
215
     *
216
     * @param Console $console
217
     *
218
     * @return $this
219
     */
220 4
    public function setConsole($console)
221
    {
222 4
        $this->console = $console;
223
224 4
        return $this;
225
    }
226
227
    /**
228
     * Get the module instance.
229
     *
230
     * @return \Nwidart\Modules\Module
231
     */
232
    public function getModule()
233
    {
234
        return $this->module;
235
    }
236
237
    /**
238
     * Set the module instance.
239
     *
240
     * @param mixed $module
241
     *
242
     * @return $this
243
     */
244 4
    public function setModule($module)
245
    {
246 4
        $this->module = $module;
247
248 4
        return $this;
249
    }
250
251
    /**
252
     * Get the list of folders will created.
253
     *
254
     * @return array
255
     */
256 4
    public function getFolders()
257
    {
258 4
        return $this->module->config('paths.generator');
0 ignored issues
show
Documentation Bug introduced by
The method config does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
259
    }
260
261
    /**
262
     * Get the list of files will created.
263
     *
264
     * @return array
265
     */
266 1
    public function getFiles()
267
    {
268 1
        return $this->module->config('stubs.files');
0 ignored issues
show
Documentation Bug introduced by
The method config does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
269
    }
270
271
    /**
272
     * Set force status.
273
     *
274
     * @param bool|int $force
275
     *
276
     * @return $this
277
     */
278 4
    public function setForce($force)
279
    {
280 4
        $this->force = $force;
0 ignored issues
show
Documentation Bug introduced by
It seems like $force can also be of type integer. However, the property $force is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
281
282 4
        return $this;
283
    }
284
285
    /**
286
     * Generate the module.
287
     */
288 4
    public function generate(): int
289
    {
290 4
        $name = $this->getName();
291
292 4
        if ($this->module->has($name)) {
0 ignored issues
show
Documentation Bug introduced by
The method has does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
293
            if ($this->force) {
294
                $this->module->delete($name);
0 ignored issues
show
Unused Code introduced by
The call to Module::delete() has too many arguments starting with $name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
295
            } else {
296
                $this->console->warning("{$name} module already exist!");
297
298
                return E_ERROR;
299
            }
300
        }
301
302 4
        $this->generateFolders();
303
304 4
        $this->generateModuleJsonFile();
305
306 4
        if ($this->plain !== true) {
307 1
            $this->generateFiles();
308 1
            $this->generateResources();
309
        }
310
311 4
        if ($this->plain === true) {
312 3
            $this->cleanModuleJsonFile();
313
        }
314
315 4
        $this->activator->setActiveByName($name, $this->isActive);
316
317 4
        $this->console->success("{$name} module has been created successfully.");
318
319 4
        return 0;
320
    }
321
322
    /**
323
     * Generate the folders.
324
     */
325 4
    public function generateFolders()
326
    {
327 4
        foreach ($this->getFolders() as $key => $folder) {
328 4
            $folder = GenerateConfigReader::read($key);
329
330 4
            if ($folder->generate() === false) {
331 1
                continue;
332
            }
333
334 4
            $path = $this->module->getModulePath($this->getName()) . '/' . $folder->getPath();
0 ignored issues
show
Documentation Bug introduced by
The method getModulePath does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
335
336 4
            $this->filesystem->makeDirectory($path, 0755, true);
337 4
            if (config('modules.stubs.gitkeep')) {
338 4
                $this->generateGitKeep($path);
339
            }
340
        }
341 4
    }
342
343
    /**
344
     * Generate git keep to the specified path.
345
     *
346
     * @param string $path
347
     */
348 4
    public function generateGitKeep($path)
349
    {
350 4
        $this->filesystem->put($path . '/.gitkeep', '');
351 4
    }
352
353
    /**
354
     * Generate the files.
355
     */
356 1
    public function generateFiles()
357
    {
358 1
        foreach ($this->getFiles() as $stub => $file) {
359 1
            $path = $this->module->getModulePath($this->getName()) . $file;
0 ignored issues
show
Documentation Bug introduced by
The method getModulePath does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
360
361 1 View Code Duplication
            if (!$this->filesystem->isDirectory($dir = dirname($path))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
362 1
                $this->filesystem->makeDirectory($dir, 0775, true);
363
            }
364
365 1
            $this->filesystem->put($path, $this->getStubContents($stub));
366
367 1
            $this->console->info("Created " . basename($path));
368
        }
369 1
    }
370
371
    /**
372
     * Generate some resources.
373
     */
374 1
    public function generateResources()
375
    {
376 1 View Code Duplication
        if (GenerateConfigReader::read('seeder')->generate() === true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
377
            $this->console->call('module:make-seed', [
378
                'name' => $this->getName(),
379
                'module' => $this->getName(),
380
                '--master' => true,
381
            ]);
382
        }
383
384 1
        if (GenerateConfigReader::read('provider')->generate() === true) {
385
            $this->console->call('module:make-provider', [
386
                'name' => $this->getName() . 'ServiceProvider',
387
                'module' => $this->getName(),
388
                '--master' => true,
389
            ]);
390
            $this->console->call('module:route-provider', [
391
                'module' => $this->getName(),
392
            ]);
393
        }
394
395 1 View Code Duplication
        if (GenerateConfigReader::read('controller')->generate() === true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
396
            $this->console->call('module:make-controller', [
397
                'controller' => $this->getName() . 'Controller',
398
                'module' => $this->getName(),
399
            ]);
400
        }
401 1
    }
402
403
    /**
404
     * Get the contents of the specified stub file by given stub name.
405
     *
406
     * @param $stub
407
     *
408
     * @return string
409
     */
410 4
    protected function getStubContents($stub)
411
    {
412 4
        return (new Stub(
413 4
            '/' . $stub . '.stub',
414 4
            $this->getReplacement($stub)
415 4
        ))->render();
416
    }
417
418
    /**
419
     * get the list for the replacements.
420
     */
421
    public function getReplacements()
422
    {
423
        return $this->module->config('stubs.replacements');
0 ignored issues
show
Documentation Bug introduced by
The method config does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
424
    }
425
426
    /**
427
     * Get array replacement for the specified stub.
428
     *
429
     * @param $stub
430
     *
431
     * @return array
432
     */
433 4
    protected function getReplacement($stub)
434
    {
435 4
        $replacements = $this->module->config('stubs.replacements');
0 ignored issues
show
Documentation Bug introduced by
The method config does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
436
437 4
        if (!isset($replacements[$stub])) {
438 1
            return [];
439
        }
440
441 4
        $keys = $replacements[$stub];
442
443 4
        $replaces = [];
444
445 4
        if ($stub === 'json' || $stub === 'composer') {
446 4
            if (in_array('PROVIDER_NAMESPACE', $keys, true) === false) {
447
                $keys[] = 'PROVIDER_NAMESPACE';
448
            }
449
        }
450 4
        foreach ($keys as $key) {
451 4
            if (method_exists($this, $method = 'get' . ucfirst(Str::studly(strtolower($key))) . 'Replacement')) {
452 4
                $replaces[$key] = $this->$method();
453
            } else {
454
                $replaces[$key] = null;
455
            }
456
        }
457
458 4
        return $replaces;
459
    }
460
461
    /**
462
     * Generate the module.json file
463
     */
464 4
    private function generateModuleJsonFile()
465
    {
466 4
        $path = $this->module->getModulePath($this->getName()) . 'module.json';
0 ignored issues
show
Documentation Bug introduced by
The method getModulePath does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
467
468 4 View Code Duplication
        if (!$this->filesystem->isDirectory($dir = dirname($path))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
469
            $this->filesystem->makeDirectory($dir, 0775, true);
470
        }
471
472 4
        $this->filesystem->put($path, $this->getStubContents('json'));
473
474 4
        $this->console->info("Created " . basename($path));
475 4
    }
476
477
    /**
478
     * Remove the default service provider that was added in the module.json file
479
     * This is needed when a --plain module was created
480
     */
481 3
    private function cleanModuleJsonFile()
482
    {
483 3
        $path = $this->module->getModulePath($this->getName()) . 'module.json';
0 ignored issues
show
Documentation Bug introduced by
The method getModulePath does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
484
485 3
        $content = $this->filesystem->get($path);
486 3
        $namespace = $this->getModuleNamespaceReplacement();
487 3
        $studlyName = $this->getStudlyNameReplacement();
488
489 3
        $provider = '"' . $namespace . '\\\\' . $studlyName . '\\\\Providers\\\\' . $studlyName . 'ServiceProvider"';
490
491 3
        $content = str_replace($provider, '', $content);
492
493 3
        $this->filesystem->put($path, $content);
494 3
    }
495
496
    /**
497
     * Get the module name in lower case.
498
     *
499
     * @return string
500
     */
501 4
    protected function getLowerNameReplacement()
502
    {
503 4
        return strtolower($this->getName());
504
    }
505
506
    /**
507
     * Get the module name in studly case.
508
     *
509
     * @return string
510
     */
511 4
    protected function getStudlyNameReplacement()
512
    {
513 4
        return $this->getName();
514
    }
515
516
    /**
517
     * Get replacement for $VENDOR$.
518
     *
519
     * @return string
520
     */
521 1
    protected function getVendorReplacement()
522
    {
523 1
        return $this->module->config('composer.vendor');
0 ignored issues
show
Documentation Bug introduced by
The method config does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
524
    }
525
526
    /**
527
     * Get replacement for $MODULE_NAMESPACE$.
528
     *
529
     * @return string
530
     */
531 4
    protected function getModuleNamespaceReplacement()
532
    {
533 4
        return str_replace('\\', '\\\\', $this->module->config('namespace'));
0 ignored issues
show
Documentation Bug introduced by
The method config does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
534
    }
535
536
    /**
537
     * Get replacement for $AUTHOR_NAME$.
538
     *
539
     * @return string
540
     */
541 1
    protected function getAuthorNameReplacement()
542
    {
543 1
        return $this->module->config('composer.author.name');
0 ignored issues
show
Documentation Bug introduced by
The method config does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
544
    }
545
546
    /**
547
     * Get replacement for $AUTHOR_EMAIL$.
548
     *
549
     * @return string
550
     */
551 1
    protected function getAuthorEmailReplacement()
552
    {
553 1
        return $this->module->config('composer.author.email');
0 ignored issues
show
Documentation Bug introduced by
The method config does not exist on object<Nwidart\Modules\Module>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
554
    }
555
556 4
    protected function getProviderNamespaceReplacement(): string
557
    {
558 4
        return str_replace('\\', '\\\\', GenerateConfigReader::read('provider')->getNamespace());
559
    }
560
}
561