GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 4eabe4...48d5ab )
by Brent
11s
created

TailCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 7
c 3
b 0
f 1
lcom 1
cbo 4
dl 0
loc 58
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B handle() 0 24 2
A findLatestLogFile() 0 12 2
A executeCommand() 0 4 1
A handleClearOption() 0 8 2
1
<?php
2
3
namespace Spatie\Tail;
4
5
use SplFileInfo;
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Facades\File;
8
use Symfony\Component\Process\Process;
9
10
class TailCommand extends Command
11
{
12
    protected $signature = 'tail {--lines=0} {--clear}';
13
14
    protected $description = 'Tail the latest logfile';
15
16
    public function handle()
17
    {
18
        $logDirectory = storage_path('logs');
19
20
        if (! $path = $this->findLatestLogFile($logDirectory)) {
21
            $this->warn("Could not find a log file in `{$logDirectory}`.");
22
23
            return;
24
        }
25
26
        $lines = $this->option('lines');
27
28
        $tailCommand = "tail -f -n {$lines} ".escapeshellarg($path);
29
30
        $this->handleClearOption();
31
32
        (new Process($tailCommand))
33
            ->setTimeout(null)
34
            ->run(function ($type, $line) {
35
                $this->handleClearOption();
36
37
                $this->output->write($line);
38
            });
39
    }
40
41
    protected function findLatestLogFile(string $directory)
42
    {
43
        $logFile = collect(File::allFiles($directory))
44
            ->sortByDesc(function (SplFileInfo $file) {
45
                return $file->getMTime();
46
            })
47
            ->first();
48
49
        return $logFile
50
            ? $logFile->getPathname()
51
            : false;
52
    }
53
54
    protected function handleClearOption()
55
    {
56
        if (! $this->option('clear')) {
57
            return;
58
        }
59
60
        $this->output->write(sprintf("\033\143\e[3J"));
61
    }
62
63
    protected function executeCommand($command)
0 ignored issues
show
Unused Code introduced by
The parameter $command is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        $output = $this->output;
0 ignored issues
show
Unused Code introduced by
$output 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...
66
    }
67
}
68