Passed
Push — main ( bbf0bf...cabb5e )
by ikechukwu
03:53
created

TestsCommand::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 17
rs 9.9666
1
<?php
2
3
namespace Ikechukwukalu\Sanctumauthstarter\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Support\Str;
8
use Symfony\Component\Finder\SplFileInfo;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class TestsCommand extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'sas:tests';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Scaffold the tests';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @return void
31
     */
32
    public function handle()
33
    {
34
        if (! is_dir($directory = base_path('tests/Feature'))) {
35
            mkdir($directory, 0755, true);
36
        }
37
38
        $filesystem = new Filesystem;
39
40
        collect($filesystem->allFiles(__DIR__.'/stubs/Tests'))
0 ignored issues
show
Bug introduced by
$filesystem->allFiles(__DIR__ . '/stubs/Tests') of type Symfony\Component\Finder\SplFileInfo[] is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        collect(/** @scrutinizer ignore-type */ $filesystem->allFiles(__DIR__.'/stubs/Tests'))
Loading history...
41
            ->each(function (SplFileInfo $file) use ($filesystem) {
42
                $filesystem->copy(
43
                    $file->getPathname(),
44
                    base_path('tests/Feature/'.Str::replaceLast('.stub', '.php', $file->getFilename()))
45
                );
46
            });
47
48
        $this->components->info('Tests scaffolding generated successfully.');
49
    }
50
}
51