InteractsWithAssignments::askForgeSite()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Acacha\ForgePublish\Commands\Traits;
4
5
/**
6
 * Trait InteractsWithAssignments.
7
 *
8
 * @package Acacha\ForgePublish\Commands\Traits
9
 */
10
trait InteractsWithAssignments
11
{
12
    /**
13
     * Ask assignment.
14
     */
15
    protected function askAssignment()
16
    {
17
        $this->assignments = $this->fetchAssignments();
0 ignored issues
show
Bug introduced by
The property assignments does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
It seems like fetchAssignments() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
18
        $names = collect($this->assignments)->pluck('name')->toArray();
19
        $default = array_search($this->currentAssignment(),$names);
20
        $selected = $this->choice('Assignment?',$names,$default);
0 ignored issues
show
Bug introduced by
It seems like choice() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
21
        return $this->findAssignmentByName($selected)->id;
22
    }
23
24
    /**
25
     * Current assignment
26
     */
27
    protected function currentAssignment() {
28
        if (fp_env('ACACHA_FORGE_ASSIGNMENT')) {
29
            $assignmentFound = collect($this->assignments)->filter(function ($assignment) {
30
                return $assignment->id == fp_env('ACACHA_FORGE_ASSIGNMENT');
31
            })->first();
32
            if ($assignmentFound) return $assignmentFound->name;
33
        }
34
        return null;
35
    }
36
37
    /**
38
     * Find assignment by name.
39
     *
40
     * @param $name
41
     * @return null
42
     */
43
    protected function findAssignmentByName($name)
44
    {
45
        $assignmentFound = collect($this->assignments)->filter(function ($assignment) use ($name) {
46
            return $assignment->name == $name;
47
        })->first();
48
        if ($assignmentFound) return $assignmentFound;
49
        return null;
50
    }
51
52
    /**
53
     * Ask forge site.
54
     *
55
     * @return string
56
     */
57
    protected function askForgeSite()
58
    {
59
        $default = $this->defaultForgeSite();
60
        return $this->ask('Forge site?',$default);
0 ignored issues
show
Bug introduced by
It seems like ask() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
61
    }
62
63
    /**
64
     * Ask forge server.
65
     *
66
     * @return string
67
     */
68
    protected function askForgeServer()
69
    {
70
        $default = $this->defaultForgeServer();
71
        return $this->ask('Forge server?',$default);
0 ignored issues
show
Bug introduced by
It seems like ask() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
72
    }
73
74
    /**
75
     * Default forge site
76
     */
77
    protected function defaultForgeSite()
78
    {
79
        return fp_env('ACACHA_FORGE_SITE') ? fp_env('ACACHA_FORGE_SITE') : null;
80
    }
81
82
    /**
83
     * Default forge server.
84
     */
85
    protected function defaultForgeServer()
86
    {
87
        return fp_env('ACACHA_FORGE_SERVER') ? fp_env('ACACHA_FORGE_SERVER') : null;
88
    }
89
90
    /**
91
     * Ask name.
92
     */
93
    protected function askName()
94
    {
95
        $default = $this->defaultName();
96
        return $this->ask('name?',$default);
0 ignored issues
show
Bug introduced by
It seems like ask() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
97
    }
98
99
    /**
100
     * Ask repository Uri.
101
     */
102
    protected function askRepositoryUri() {
103
        $default = $this->defaultRepositoryUri();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $default is correct as $this->defaultRepositoryUri() (which targets Acacha\ForgePublish\Comm...:defaultRepositoryUri()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
104
        return $this->ask('Repository URI?', $default);
0 ignored issues
show
Bug introduced by
It seems like ask() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
105
    }
106
107
    /**
108
     * Ask repository Uri.
109
     */
110
    protected function askRepositoryType() {
111
        $default = $this->defaultRepositoryType();
112
        return $this->ask('Repository type?', $default);
0 ignored issues
show
Bug introduced by
It seems like ask() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
113
    }
114
115
    /**
116
     * Default repository type.
117
     *
118
     * @return string
119
     */
120
    protected function defaultRepositoryType()
121
    {
122
        return 'github';
123
    }
124
125
    /**
126
     * Default repository URI.
127
     *
128
     * @return null
129
     */
130
    protected function defaultRepositoryUri()
131
    {
132
        return fp_env('ACACHA_FORGE_GITHUB_REPO') ? fp_env('ACACHA_FORGE_GITHUB_REPO') : $this->getRepoFromGithubConfig();
0 ignored issues
show
Bug introduced by
It seems like getRepoFromGithubConfig() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
133
    }
134
135
    /**
136
     * Default name.
137
     *
138
     * @return null|string
139
     */
140
    protected function defaultName()
141
    {
142
        return fp_env('ACACHA_FORGE_DOMAIN') ? fp_env('ACACHA_FORGE_DOMAIN') : strtolower(camel_case(basename(getcwd())));
143
    }
144
}