BrandingService::perform()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Zoutapps\Laravel\Backpack\Branding\Services;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Zoutapps\Laravel\Backpack\Branding\Commands\BrandingCommand;
7
use Zoutapps\Laravel\Backpack\Branding\Helper\ShortSyntaxArray;
8
9
class BrandingService
10
{
11
    private $command;
12
    private $filesystem;
13
    private $defaults;
14
15
    public function __construct(BrandingCommand $command)
16
    {
17
        $this->command = $command;
18
        $this->defaults = $this->command->getDefaults('branding');
19
        $this->filesystem = new Filesystem();
20
    }
21
22
    public function perform()
23
    {
24
        $this->writeConfigFile($this->defaults->toArray());
25
26
        return true;
27
    }
28
29
    function writeConfigFile(array $values)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
30
    {
31
        $content = $this->fileContent($values);
32
33
        $path = base_path('config/zoutapps/branding.php');
34
35
        if (!$this->filesystem->isDirectory(base_path('config/zoutapps'))) {
36
            $this->filesystem->makeDirectory(base_path('config/zoutapps'));
37
        }
38
39
        $this->filesystem->put($path, $content);
40
41
        $this->command->info("Config file for Branding facade created at <comment>{$path}</comment>");
42
    }
43
44
    function fileContent($values)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
45
    {
46
        $data = ShortSyntaxArray::parse($values);
47
48
        return <<<FILE
49
<?php
50
51
// Autogenerated config file with zoutapps/laravel-backpack-branding used for Branding Facade
52
53
return {$data};
54
FILE;
55
    }
56
}