Completed
Push — master ( 96dcc8...b3268d )
by Marcel
16s
created

NotificationTableCommand::__construct()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 22
ccs 0
cts 21
cp 0
rs 8.9197
cc 4
eloc 15
nc 4
nop 2
crap 20
1
<?php
2
3
namespace Illuminate\Notifications\Console;
4
5
use ReflectionClass;
6
use InvalidArgumentException;
7
use Illuminate\Console\Command;
8
use Illuminate\Filesystem\Filesystem;
9
10
class NotificationTableCommand extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'notifications:table';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a migration for the notifications table';
25
26
    /**
27
     * The filesystem instance.
28
     *
29
     * @var \Illuminate\Filesystem\Filesystem
30
     */
31
    protected $files;
32
33
    /**
34
     * @var mixed
35
     */
36
    protected $composer;
37
38
    /**
39
     * Create a new notifications table command instance.
40
     *
41
     * @param  \Illuminate\Filesystem\Filesystem  $files
42
     * @param  mixed $composer
43
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
44
     */
45
    public function __construct(Filesystem $files, $composer)
46
    {
47
        parent::__construct();
48
49
        $this->files = $files;
50
        $composerClass = 'Illuminate\Support\Composer';
51
        if (class_exists('Illuminate\Foundation\Composer')) {
52
            $composerClass = 'Illuminate\Foundation\Composer';
53
        }
54
        $reflection = new ReflectionClass($composerClass);
55
        if (!is_object($composer) || !$reflection->isInstance($composer)) {
56
            throw new InvalidArgumentException(
57
                sprintf(
58
                    'Argument 2 passed to %s::%s must be an instance of %s',
59
                    __CLASS__,
60
                    __FUNCTION__,
61
                    $composerClass
62
                )
63
            );
64
        }
65
        $this->composer = $composer;
66
    }
67
68
    /**
69
     * Execute the console command.
70
     *
71
     * @return void
72
     */
73
    public function fire()
74
    {
75
        $fullPath = $this->createBaseMigration();
76
77
        $this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/notifications.stub'));
78
79
        $this->info('Migration created successfully!');
80
81
        $this->composer->dumpAutoloads();
82
    }
83
84
    /**
85
     * Create a base migration file for the notifications.
86
     *
87
     * @return string
88
     */
89
    protected function createBaseMigration()
90
    {
91
        $name = 'create_notifications_table';
92
93
        $path = $this->laravel->databasePath().'/migrations';
0 ignored issues
show
Bug introduced by
The method databasePath() does not exist on Illuminate\Contracts\Foundation\Application. Did you maybe mean basePath()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
94
95
        return $this->laravel['migration.creator']->create($name, $path);
96
    }
97
}
98