ChecksEnv::checkEnv()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 4
nop 3
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Acacha\ForgePublish\Commands\Traits;
4
5
/**
6
 * Trait ChecksEnv.
7
 *
8
 * @package Acacha\ForgePublish\Commands\Traits
9
 */
10
trait ChecksEnv
11
{
12
    /**
13
     * Check if a argument/option exists or check for his corresponding ENV VALUE.
14
     *
15
     * @param $option
16
     * @param $env_var
17
     * @param string $type
18
     * @return mixed
19
     */
20
    protected function checkEnv($option, $env_var, $type = 'option')
21
    {
22
        $value = $this->$type($option) ? $this->$type($option) : fp_env($env_var);
23
        if (!$value) {
24
            $this->error("No env var $env_var found. Please run php artisan publish:init");
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...
25
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method checkEnv() 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...
26
        }
27
        return $value;
28
    }
29
}
30