Completed
Push — master ( 6424ee...f103eb )
by Nicolas
18s queued 11s
created

ModuleGenerator::getFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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
     * set default module type.
67
     *
68
     * @var string
69
     */
70
    protected $type = 'web';
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 130
    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 130
        $this->name = $name;
96 130
        $this->config = $config;
97 130
        $this->filesystem = $filesystem;
98 130
        $this->console = $console;
99 130
        $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 130
        $this->activator = $activator;
101 130
    }
102
103
    /**
104
     * Set type.
105
     *
106
     * @param string $type
107
     *
108
     * @return $this
109
     */
110 130
    public function setType($type)
111
    {
112 130
        $this->type = $type;
113
114 130
        return $this;
115
    }
116
117
    /**
118
     * Set active flag.
119
     *
120
     * @param bool $active
121
     *
122
     * @return $this
123
     */
124 130
    public function setActive(bool $active)
125
    {
126 130
        $this->isActive = $active;
127
128 130
        return $this;
129
    }
130
131
    /**
132
     * Get the name of module will created. By default in studly case.
133
     *
134
     * @return string
135
     */
136 130
    public function getName()
137
    {
138 130
        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 130
    public function setConfig($config)
159
    {
160 130
        $this->config = $config;
161
162 130
        return $this;
163
    }
164
165
    /**
166
     * Set the modules activator
167
     *
168
     * @param ActivatorInterface $activator
169
     *
170
     * @return $this
171
     */
172 130
    public function setActivator(ActivatorInterface $activator)
173
    {
174 130
        $this->activator = $activator;
175
176 130
        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 130
    public function setFilesystem($filesystem)
197
    {
198 130
        $this->filesystem = $filesystem;
199
200 130
        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 130
    public function setConsole($console)
221
    {
222 130
        $this->console = $console;
223
224 130
        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 130
    public function setModule($module)
245
    {
246 130
        $this->module = $module;
247
248 130
        return $this;
249
    }
250
251
    /**
252
     * Get the list of folders will created.
253
     *
254
     * @return array
255
     */
256 130
    public function getFolders()
257
    {
258 130
        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 121
    public function getFiles()
267
    {
268 121
        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 130
    public function setForce($force)
279
    {
280 130
        $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 130
        return $this;
283
    }
284
285
    /**
286
     * Generate the module.
287
     */
288 130
    public function generate() : int
289
    {
290 130
        $name = $this->getName();
291
292 130
        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 2
            if ($this->force) {
294 1
                $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 1
                $this->console->error("Module [{$name}] already exist!");
297
298 1
                return E_ERROR;
299
            }
300
        }
301
302 130
        $this->generateFolders();
303
304 130
        $this->generateModuleJsonFile();
305
306 130
        if ($this->type !== 'plain') {
307 121
            $this->generateFiles();
308 121
            $this->generateResources();
309
        }
310
311 130
        if ($this->type === 'plain') {
312 9
            $this->cleanModuleJsonFile();
313
        }
314
315 130
        $this->activator->setActiveByName($name, $this->isActive);
316
317 130
        $this->console->info("Module [{$name}] created successfully.");
318
319 130
        return 0;
320
    }
321
322
    /**
323
     * Generate the folders.
324
     */
325 130
    public function generateFolders()
326
    {
327 130
        foreach ($this->getFolders() as $key => $folder) {
328 130
            $folder = GenerateConfigReader::read($key);
329
330 130
            if ($folder->generate() === false) {
331 4
                continue;
332
            }
333
334 130
            $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 130
            $this->filesystem->makeDirectory($path, 0755, true);
337 130
            if (config('modules.stubs.gitkeep')) {
338 130
                $this->generateGitKeep($path);
339
            }
340
        }
341 130
    }
342
343
    /**
344
     * Generate git keep to the specified path.
345
     *
346
     * @param string $path
347
     */
348 130
    public function generateGitKeep($path)
349
    {
350 130
        $this->filesystem->put($path . '/.gitkeep', '');
351 130
    }
352
353
    /**
354
     * Generate the files.
355
     */
356 121
    public function generateFiles()
357
    {
358 121
        foreach ($this->getFiles() as $stub => $file) {
359 121
            $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 121 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 121
                $this->filesystem->makeDirectory($dir, 0775, true);
363
            }
364
365 121
            $this->filesystem->put($path, $this->getStubContents($stub));
366
367 121
            $this->console->info("Created : {$path}");
368
        }
369 121
    }
370
371
    /**
372
     * Generate some resources.
373
     */
374 121
    public function generateResources()
375
    {
376 121
        if (GenerateConfigReader::read('seeder')->generate() === true) {
377 120
            $this->console->call('module:make-seed', [
378 120
                'name' => $this->getName(),
379 120
                'module' => $this->getName(),
380
                '--master' => true,
381
            ]);
382
        }
383
384 121
        if (GenerateConfigReader::read('provider')->generate() === true) {
385 120
            $this->console->call('module:make-provider', [
386 120
                'name' => $this->getName() . 'ServiceProvider',
387 120
                'module' => $this->getName(),
388
                '--master' => true,
389
            ]);
390 120
            $this->console->call('module:route-provider', [
391 120
                'module' => $this->getName(),
392
            ]);
393
        }
394
395 121
        if (GenerateConfigReader::read('controller')->generate() === true) {
396 120
            $options = $this->type=='api'?['--api'=>true]:[];
397 120
            $this->console->call('module:make-controller', [
398 120
                'controller' => $this->getName() . 'Controller',
399
                'module' => $this->getName(),
400
            ]+$options);
401 121
        }
402
    }
403
404
    /**
405
     * Get the contents of the specified stub file by given stub name.
406
     *
407
     * @param $stub
408
     *
409
     * @return string
410 130
     */
411
    protected function getStubContents($stub)
412 130
    {
413 130
        return (new Stub(
414 130
            '/' . $stub . '.stub',
415
            $this->getReplacement($stub)
416 130
        )
417
        )->render();
418
    }
419
420
    /**
421
     * get the list for the replacements.
422
     */
423
    public function getReplacements()
424
    {
425
        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...
426
    }
427
428
    /**
429
     * Get array replacement for the specified stub.
430
     *
431
     * @param $stub
432
     *
433
     * @return array
434 130
     */
435
    protected function getReplacement($stub)
436 130
    {
437
        $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...
438 130
439 121
        if (!isset($replacements[$stub])) {
440
            return [];
441
        }
442 130
443
        $keys = $replacements[$stub];
444 130
445
        $replaces = [];
446 130
447 130
        if ($stub === 'json' || $stub === 'composer') {
448
            if (in_array('PROVIDER_NAMESPACE', $keys, true) === false) {
449
                $keys[] = 'PROVIDER_NAMESPACE';
450
            }
451 130
        }
452 130
        foreach ($keys as $key) {
453 130
            if (method_exists($this, $method = 'get' . ucfirst(Str::studly(strtolower($key))) . 'Replacement')) {
454
                $replaces[$key] = $this->$method();
455
            } else {
456
                $replaces[$key] = null;
457
            }
458
        }
459 130
460
        return $replaces;
461
    }
462
463
    /**
464
     * Generate the module.json file
465 130
     */
466
    private function generateModuleJsonFile()
467 130
    {
468
        $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...
469 130
470 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...
471
            $this->filesystem->makeDirectory($dir, 0775, true);
472
        }
473 130
474
        $this->filesystem->put($path, $this->getStubContents('json'));
475 130
476 130
        $this->console->info("Created : {$path}");
477
    }
478
479
    /**
480
     * Remove the default service provider that was added in the module.json file
481
     * This is needed when a --plain module was created
482 9
     */
483
    private function cleanModuleJsonFile()
484 9
    {
485
        $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...
486 9
487 9
        $content = $this->filesystem->get($path);
488 9
        $namespace = $this->getModuleNamespaceReplacement();
489
        $studlyName = $this->getStudlyNameReplacement();
490 9
491
        $provider = '"' . $namespace . '\\\\' . $studlyName . '\\\\Providers\\\\' . $studlyName . 'ServiceProvider"';
492 9
493
        $content = str_replace($provider, '', $content);
494 9
495 9
        $this->filesystem->put($path, $content);
496
    }
497
498
    /**
499
     * Get the module name in lower case.
500
     *
501
     * @return string
502 130
     */
503
    protected function getLowerNameReplacement()
504 130
    {
505
        return strtolower($this->getName());
506
    }
507
508
    /**
509
     * Get the module name in studly case.
510
     *
511
     * @return string
512 130
     */
513
    protected function getStudlyNameReplacement()
514 130
    {
515
        return $this->getName();
516
    }
517
518
    /**
519
     * Get replacement for $VENDOR$.
520
     *
521
     * @return string
522 121
     */
523
    protected function getVendorReplacement()
524 121
    {
525
        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...
526
    }
527
528
    /**
529
     * Get replacement for $MODULE_NAMESPACE$.
530
     *
531
     * @return string
532 130
     */
533
    protected function getModuleNamespaceReplacement()
534 130
    {
535
        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...
536
    }
537
538
    /**
539
     * Get replacement for $AUTHOR_NAME$.
540
     *
541
     * @return string
542 121
     */
543
    protected function getAuthorNameReplacement()
544 121
    {
545
        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...
546
    }
547
548
    /**
549
     * Get replacement for $AUTHOR_EMAIL$.
550
     *
551
     * @return string
552 121
     */
553
    protected function getAuthorEmailReplacement()
554 121
    {
555
        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...
556
    }
557 130
558
    protected function getProviderNamespaceReplacement(): string
559 130
    {
560
        return str_replace('\\', '\\\\', GenerateConfigReader::read('provider')->getNamespace());
561
    }
562
}
563