Completed
Pull Request — master (#1)
by ARCANEDEV
01:46
created

Command::getSelectedWorkspace()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php namespace Arcanedev\Assets\Console;
2
3
use Arcanedev\Assets\Exceptions\NotInitiatedException;
4
use Arcanedev\Assets\Helpers\Workspaces;
5
use Illuminate\Pipeline\Pipeline;
6
use Illuminate\Console\Command as BaseCommand;
7
use Illuminate\Support\Facades\File;
8
9
/**
10
 * Class     Command
11
 *
12
 * @package  Arcanedev\Assets\Console
13
 * @author   ARCANEDEV <[email protected]>
14
 *
15
 * @property  \Illuminate\Foundation\Application  $laravel
16
 */
17
abstract class Command extends BaseCommand
18
{
19
    /* -----------------------------------------------------------------
20
     |  Main Methods
21
     | -----------------------------------------------------------------
22
     */
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return mixed
28
     */
29
    abstract public function handle();
30
31
    /* -----------------------------------------------------------------
32
     |  Common Methods
33
     | -----------------------------------------------------------------
34
     */
35
36
    /**
37
     * Create a new pipeline.
38
     *
39
     * @return \Illuminate\Pipeline\Pipeline
40
     */
41
    protected function pipeline()
42
    {
43
        return new Pipeline($this->laravel);
44
    }
45
46
    /**
47
     * Get the passable for the pipeline.
48
     *
49
     * @return array
50
     */
51
    protected function getPassable()
52
    {
53
        $default   = $this->getSelectedWorkspace();
54
        $workspace = Workspaces::get($default);
55
56
        return array_merge(
57
            $workspace,
58
            [
59
                'workspace' => $default,
60
                'public-directory' => config('assets.public-directory', 'public'),
61
            ]
62
        );
63
    }
64
65
    /**
66
     * Check if the assets was initiated.
67
     */
68
    protected function ensureIsInitiated()
69
    {
70
        $default = $this->getSelectedWorkspace();
71
72
        if ( ! File::isDirectory(config("assets.workspaces.{$default}.root-directory")))
73
            NotInitiatedException::throw();
74
    }
75
76
    /**
77
     * Get the default workspace.
78
     *
79
     * @return \Illuminate\Config\Repository|mixed
80
     */
81
    protected function getSelectedWorkspace()
82
    {
83
        return $this->option('workspace') ?: Workspaces::getDefaultName();
84
    }
85
}
86