Make   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildClass() 0 4 1
A extendStub() 0 18 1
1
<?php namespace Indatus\Dispatcher\Commands;
2
3
/**
4
 * This file is part of Dispatcher
5
 *
6
 * (c) Ben Kuhl <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
use App;
13
use Config;
14
use Illuminate\Foundation\Console\ConsoleMakeCommand;
15
16
/**
17
 * View a summary for all scheduled artisan commands
18
 * @author Ben Kuhl <[email protected]>
19
 */
20
class Make extends ConsoleMakeCommand
21
{
22
    /**
23
     * The console command name.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'scheduled:make';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Create a new scheduled artisan command';
35
36
    /**
37
     * @param string $name
38
     * @codeCoverageIgnore
39
     */
40
    protected function buildClass($name)
41
    {
42
        return $this->extendStub(parent::buildClass($name));
43
    }
44
45
    /**
46
     * Make sure we're implementing our own class
47
     * @param $stub
48
     * @return string
49
     */
50 1
    protected function extendStub($stub)
51
    {
52
        /** @var \Illuminate\Filesystem\Filesystem $files */
53 1
        $files = App::make('Illuminate\Filesystem\Filesystem');
54 1
        $content = $files->get(__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'command.stub');
55
56
        $replacements = [
57
            'use Illuminate\Console\Command' => "use Indatus\\Dispatcher\\Scheduling\\ScheduledCommand;\n".
58 1
                "use Indatus\\Dispatcher\\Scheduling\\Schedulable;\n".
59 1
                "use Indatus\\Dispatcher\\Drivers\\".ucwords(Config::get('dispatcher::driver'))."\\Scheduler",
60 1
            'extends Command {' => 'extends ScheduledCommand {',
61 1
            'parent::__construct();' => $content,
62 1
        ];
63
64 1
        $stub = str_replace(array_keys($replacements), array_values($replacements), $stub);
65
66 1
        return $stub;
67
    }
68
}
69