Creator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 69
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setNamespace() 0 12 2
A outputNothingCreated() 0 12 3
1
<?php
2
3
namespace Yarak\Helpers;
4
5
use Yarak\Config\Config;
6
use Artisanize\Output\Output;
7
8
abstract class Creator
9
{
10
    use Filesystem;
11
12
    /**
13
     * Yarak config.
14
     *
15
     * @var Config
16
     */
17
    protected $config;
18
19
    /**
20
     * Output strategy.
21
     *
22
     * @var Output
23
     */
24
    protected $output;
25
26
    /**
27
     * Construct.
28
     *
29
     * @param Output $output
30
     */
31
    public function __construct(Output $output)
32
    {
33
        $this->output = $output;
34
35
        $this->config = Config::getInstance();
36
    }
37
38
    /**
39
     * Set the namespace in the command stub.
40
     *
41
     * @param string $stub
42
     * @param string $namespace
43
     *
44
     * @return string
45
     */
46
    protected function setNamespace($stub, $namespace = null)
47
    {
48
        if ($namespace !== null) {
49
            return str_replace(
50
                'NAMESPACE',
51
                "\nnamespace {$namespace};\n",
52
                $stub
53
            );
54
        }
55
56
        return str_replace('NAMESPACE', '', $stub);
57
    }
58
59
    /**
60
     * Output nothing created message if no all bools are false.
61
     *
62
     * @param array $bools
63
     */
64
    protected function outputNothingCreated(array $bools)
65
    {
66
        foreach ($bools as $bool) {
67
            if ($bool) {
68
                return;
69
            }
70
        }
71
72
        $this->output->writeComment(
73
            'Nothing created. All directories and files already exist.'
74
        );
75
    }
76
}
77