ChecksSite::checkSite()   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 ChecksSite.
7
 *
8
 * @package Acacha\ForgePublish\Commands\Traits
9
 */
10
trait ChecksSite
11
{
12
    use ItFetchesSites;
13
14
    /**
15
     * Check site.
16
     *
17
     * @return bool
18
     */
19
    protected function checkSite()
20
    {
21
        $sites = $this->fetchSites(fp_env('ACACHA_FORGE_SERVER'));
22
        return in_array(fp_env('ACACHA_FORGE_SITE'), collect($sites)->pluck('id')->toArray());
23
    }
24
25
    /**
26
     * Check site and abort.
27
     *
28
     * @param null $site
29
     */
30
    protected function checkSiteAndAbort($site = null)
31
    {
32
        $site = $site ? $site : fp_env('ACACHA_FORGE_SITE');
33
        if (! $this->checkSite($site)) {
0 ignored issues
show
Unused Code introduced by
The call to ChecksSite::checkSite() has too many arguments starting with $site.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
34
            $this->error('Site ' . $site . '  not valid');
0 ignored issues
show
Bug introduced by
It seems like error() 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...
35
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method checkSiteAndAbort() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
36
        }
37
    }
38
}
39