BackpackBaseConfigService   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 22.95 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 14
loc 61
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A perform() 14 14 2
A escape() 0 4 1
A old() 0 4 1
A search() 0 4 1
A replace() 0 3 1
A __construct() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Zoutapps\Laravel\Backpack\Branding\Services;
4
5
use Zoutapps\Laravel\Backpack\Branding\Commands\BrandingCommand;
6
use Zoutapps\Laravel\Backpack\Branding\Traits\ValueReplacerTrait;
7
8
class BackpackBaseConfigService
9
{
10
    use ValueReplacerTrait;
11
12
    private $command;
13
14
    private $keys = [
0 ignored issues
show
Unused Code introduced by
The property $keys is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
        "project_name",
16
        "logo_lg",
17
        "logo_mini",
18
        "developer_name",
19
        "developer_link",
20
        "show_powered_by",
21
        "skin",
22
        "default_date_format",
23
        "default_datetime_format",
24
        "route_prefix",
25
    ];
26
27
    public function __construct(BrandingCommand $command, $file)
28
    {
29
        $this->command = $command;
30
        $this->file = $file;
31
        $this->appends = false;
32
        $this->defaults= collect(collect($this->command->getDefaults('config'))->get('backpack_base'));
33
    }
34
35 View Code Duplication
    public function perform()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        if (file_exists($this->file) === false) {
38
            $this->command->error('You don\'t have a the backpack base config file.');
39
            return false;
40
        }
41
42
        $this->command->info('Please provide your base config values:');
43
44
        $this->applyValues();
45
46
        //$user_model_fqn
47
        return true;
48
    }
49
50
    protected function escape($value)
51
    {
52
        return "'".$value."'";
53
    }
54
55
    protected function old($key)
56
    {
57
        return $this->escape(config('backpack.base:'.$key));
58
    }
59
60
    protected function search($key, $old)
0 ignored issues
show
Unused Code introduced by
The parameter $old is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62
        return '/^[ ]*'.preg_quote("'{$key}'").'[ ]*'.preg_quote("=>").'.*$/m';
63
    }
64
65
    protected function replace($key, $value) {
66
        return "    '".$key."' => ". $value . ",";
67
    }
68
}