Test Setup Failed
Push — master ( 7e4f66...c742e7 )
by Php Easy Api
03:35
created

Track   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A log() 0 22 5
1
<?php
2
3
namespace Resta\Console\Source\Track;
4
5
use Resta\Console\ConsoleOutputter;
6
use Resta\Console\ConsoleListAccessor;
7
8
class Track extends ConsoleOutputter
9
{
10
    use ConsoleListAccessor;
11
12
    /**
13
     * @var $type
0 ignored issues
show
Documentation Bug introduced by
The doc comment $type at position 0 could not be parsed: Unknown type name '$type' at position 0 in $type.
Loading history...
14
     */
15
    public $type = 'track';
16
17
    /**
18
     * @var $define
0 ignored issues
show
Documentation Bug introduced by
The doc comment $define at position 0 could not be parsed: Unknown type name '$define' at position 0 in $define.
Loading history...
19
     */
20
    public $define = 'returns track information for application';
21
22
    /**
23
     * @var $commandRule
0 ignored issues
show
Documentation Bug introduced by
The doc comment $commandRule at position 0 could not be parsed: Unknown type name '$commandRule' at position 0 in $commandRule.
Loading history...
24
     */
25
    public $commandRule = [];
26
27
    /**
28
     * @return mixed|void
29
     */
30
    public function log()
31
    {
32
        $logger = app()->path()->appLog().''.DIRECTORY_SEPARATOR.''.date('Y').''.DIRECTORY_SEPARATOR.''.date('m').''.DIRECTORY_SEPARATOR.''.date('d').'-access.log';
33
34
        $tailCommand = 'tail -n 1 -f '.escapeshellarg($logger).'';
35
36
        while (@ ob_end_flush()); // end all output buffers if any
37
38
        $proc = popen($tailCommand, 'r');
39
        while (!feof($proc))
0 ignored issues
show
Bug introduced by
It seems like $proc can also be of type false; however, parameter $handle of feof() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        while (!feof(/** @scrutinizer ignore-type */ $proc))
Loading history...
40
        {
41
            $result = fread($proc, 4096);
0 ignored issues
show
Bug introduced by
It seems like $proc can also be of type false; however, parameter $handle of fread() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
            $result = fread(/** @scrutinizer ignore-type */ $proc, 4096);
Loading history...
42
            if(preg_match('@\{(.*)\}@',$result,$output)){
43
                $outputArray = json_decode($output[0],1);
44
                
45
                if(app()->has('track.log')){
46
47
                    $track = app()->get('track.log');
48
                    echo $track($outputArray);
49
                }
50
            }
51
            @ flush();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for flush(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

51
            /** @scrutinizer ignore-unhandled */ @ flush();

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Bug introduced by
Are you sure the usage of flush() is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
52
        }
53
        
54
    }
55
}