PublishDomain::defaultDomain()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 96.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Acacha\ForgePublish\Commands;
4
5
use Acacha\ForgePublish\Parser\ForgePublishRCParser;
6
7
/**
8
 * Class PublishDomain.
9
 *
10
 * @package Acacha\ForgePublish\Commands
11
 */
12
class PublishDomain extends SaveEnvVariable
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'publish:domain {domain?}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Save acacha forge domain';
27
28
    /**
29
     * ForgePublishRCParser
30
     *
31
     * @var ForgePublishRCParser
32
     */
33
    protected $parser;
34
35
    /**
36
     * SaveEnvVariable constructor.
37
     *
38
     */
39
    public function __construct(ForgePublishRCParser $parser)
40
    {
41
        parent::__construct();
42
        $this->parser = $parser;
43
    }
44
45
    /**
46
     * Env var to set.
47
     *
48
     * @return mixed
49
     */
50
    protected function envVar()
51
    {
52
        return 'ACACHA_FORGE_DOMAIN';
53
    }
54
55
    /**
56
     * Argument key.
57
     *
58
     * @return mixed
59
     */
60
    protected function argKey()
61
    {
62
        return 'domain';
63
    }
64
65
    /**
66
     * Question text.
67
     *
68
     * @return mixed
69
     */
70
    protected function questionText()
71
    {
72
        return 'Acacha forge domain?';
73
    }
74
75
    /**
76
     * Default proposed value when asking.
77
     *
78
     */
79
    protected function default()
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
80
    {
81
        return $default = fp_env('ACACHA_FORGE_DOMAIN') ? fp_env('ACACHA_FORGE_DOMAIN') : $this->defaultDomain();
0 ignored issues
show
Unused Code introduced by
$default is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $default.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
82
    }
83
84
    /**
85
     * Default domain.
86
     *
87
     * @return string
88
     */
89
    protected function defaultDomain()
90
    {
91
        if ($suffix = $this->parser->getDomainSuffix()) {
92
            return strtolower(camel_case(basename(getcwd()))) . '.' . $suffix;
93
        }
94
        return '';
95
    }
96
}
97