PushCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 1
b 0
f 0
dl 0
loc 43
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 3
1
<?php
2
3
namespace Arubacao\AssetCdn\Commands;
4
5
use Arubacao\AssetCdn\Finder;
6
use Illuminate\Config\Repository;
7
use Illuminate\Filesystem\FilesystemManager;
8
use Illuminate\Http\File;
9
10
class PushCommand extends BaseCommand
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'asset-cdn:push';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Pushes assets to CDN';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @param Finder $finder
30
     * @param FilesystemManager $filesystemManager
31
     * @param Repository $config
32
     *
33
     * @return void
34
     */
35
    public function handle(Finder $finder, FilesystemManager $filesystemManager, Repository $config)
36
    {
37
        $files = $finder->getFiles();
38
39
        foreach ($files as $file) {
40
            $bool = $filesystemManager
41
                ->disk($config->get('asset-cdn.filesystem.disk'))
42
                ->putFileAs(
43
                    $file->getRelativePath(),
44
                    new File($file->getPathname()),
45
                    $file->getFilename(),
46
                    $config->get('asset-cdn.filesystem.options')
47
                );
48
49
            if (! $bool) {
50
                $this->error("Problem uploading: {$file->getRelativePathname()}");
51
            } else {
52
                $this->info("Successfully uploaded: {$file->getRelativePathname()}");
53
            }
54
        }
55
    }
56
}
57