LogsErrors   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A finishCommand() 0 18 5
1
<?php
2
3
namespace Imanghafoori\LaravelMicroscope\Traits;
4
5
use Illuminate\Support\Str;
6
use Imanghafoori\LaravelMicroscope\ErrorReporters\ErrorPrinter;
7
8
trait LogsErrors
9
{
10
    /**
11
     * Shows the status of a successful or failed check.
12
     *
13
     * @param  ErrorPrinter  $errorPrinter
14
     */
15
    protected function finishCommand(ErrorPrinter $errorPrinter)
16
    {
17
        $commandName = class_basename($this);
18
        $commandType = Str::after($commandName, 'Check');
19
        $commandType = strtolower($commandType);
20
21
        if (! $errorPrinter->logErrors) {
22
            return;
23
        }
24
25
        if (($errorCount = $errorPrinter->hasErrors()) || $errorPrinter->pended) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $errorPrinter->pended of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
26
            $errorCount && $this->warn(PHP_EOL.$errorCount.' errors found for '.$commandType);
0 ignored issues
show
Bug introduced by
It seems like warn() 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...
27
28
            $errorPrinter->logErrors();
29
        } else {
30
            $this->info(PHP_EOL.'All '.$commandType.' are correct!');
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...
31
        }
32
    }
33
}
34