PossibleEmails   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPossibleEmails() 0 12 2
A checkGit() 0 9 2
1
<?php
2
3
namespace Acacha\ForgePublish\Commands\Traits;
4
5
use Illuminate\Support\Facades\File;
6
7
/**
8
 * Trait PossibleEmails
9
 *
10
 * @package Acacha\ForgePublish\Commands\Traits
11
 */
12
trait PossibleEmails
13
{
14
15
    /**
16
     * Get possible emails
17
     *
18
     * @return array
19
     */
20
    protected function getPossibleEmails()
21
    {
22
        $this->checkGit();
23
        $github_email = null;
0 ignored issues
show
Unused Code introduced by
$github_email 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...
24
        $github_email = str_replace(array("\r", "\n"), '', shell_exec('git config user.email'));
25
26
        if (filter_var($github_email, FILTER_VALIDATE_EMAIL)) {
27
            return [ $github_email ];
28
        } else {
29
            return [];
30
        }
31
    }
32
33
    /**
34
     * Check git.
35
     */
36
    protected function checkGit()
37
    {
38
        if (File::exists('/usr/bin/git')) {
39
            return;
40
        }
41
        $this->info('Git not found in your system');
0 ignored issues
show
Bug introduced by
It seems like info() 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...
42
        $this->info('Installing git with sudo apt-get install git');
0 ignored issues
show
Bug introduced by
It seems like info() 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...
43
        passthru('sudo apt-get install git');
44
    }
45
}
46