Completed
Push — dev ( 3ddbd6...175d0e )
by Zach
02:08
created

Creator::outputNothingCreated()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Yarak\Helpers;
4
5
use Yarak\Config\Config;
6
use Yarak\Console\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 Config $config
30
     * @param Output $output
31
     */
32
    public function __construct(Config $config, Output $output)
33
    {
34
        $this->config = $config;
35
        $this->output = $output;
36
    }
37
38
    /**
39
     * Guess a namespace based on a path.
40
     *
41
     * @param string $path
42
     *
43
     * @return string|null
44
     */
45
    protected function guessNamespace($path)
46
    {
47
        if (defined('APP_PATH')) {
48
            $appPathArray = explode('/', APP_PATH);
49
50
            $relativePath = array_diff(explode('/', $path), $appPathArray);
51
52
            array_unshift($relativePath, array_pop($appPathArray));
53
54
            $relativePath = array_map('ucfirst', $relativePath);
55
56
            return implode('\\', $relativePath);
57
        }
58
    }
59
60
    /**
61
     * Set the namespace in the command stub.
62
     *
63
     * @param string $stub
64
     * @param string $namespace
65
     *
66
     * @return string
67
     */
68
    protected function setNamespace($stub, $namespace = null)
69
    {
70
        if ($namespace !== null) {
71
            return str_replace(
72
                'NAMESPACE',
73
                "\nnamespace {$namespace};\n",
74
                $stub
75
            );
76
        }
77
78
        return str_replace('NAMESPACE', '', $stub);
79
    }
80
81
    /**
82
     * Output nothing created message if no all bools are false.
83
     *
84
     * @param array $bools
85
     */
86
    protected function outputNothingCreated(array $bools)
87
    {
88
        foreach ($bools as $bool) {
89
            if ($bool) {
90
                return;
91
            }
92
        }
93
94
        $this->output->writeComment(
95
            'Nothing created. All directories and files already exist.'
96
        );
97
    }
98
}
99