Completed
Push — master ( da6adc...c42001 )
by arto
02:03
created

local/check_if_a_request_is_still_running.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2017-04-26
5
 */
6
7
require __DIR__ . '/../../vendor/autoload.php';
8
9
if ($argc < 2) {
10
    echo 'Invalid number of arguments provided.' . PHP_EOL;
11
    echo 'Usage:' . PHP_EOL;
12
    echo '    ' . basename(__FILE__) . ' <int: pid> [<string: uri path> [<string: path to the example file>]]' . PHP_EOL;
13
14
    exit(1);
15
}
16
//begin of dependencies
17
$foundNoMatchingDetail          = true;
18
$listOfPidToUriPathWithQuery    = [];
19
$pathToTheExampleFile           = (
20
    ($argc > 3)
21
        ? $argv[3]
22
        : __DIR__ . '/server-status?notable.html'
23
);
24
$parserBuilderFactory           = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\ParserBuilderFactory();
25
$pid                            = $argv[1];
26
$stringUtility                  = new \JonasRudolph\PHPComponents\StringUtility\Implementation\StringUtility();
27
$storageBuilder                 = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\LocalStorageBuilder();
28
$uriPath                        = (
29
($argc > 2)
30
    ? $argv[2]
31
    : ''
32
);
33
//end of dependencies
34
35
//begin of business logic
36
$parserBuilder      = $parserBuilderFactory->create();
37
$uriPathProvided    = (strlen($uriPath) > 0);
38
39
$storageBuilder->setPathToTheApacheStatusFileToParseUpfront($pathToTheExampleFile);
40
$storageBuilder->selectParseModeDetailOnlyUpfront();
41
$storageBuilder->build();
42
43
$storage = $storageBuilder->andGetStorageAfterTheBuild();
44
45
$parserBuilder->setStorageUpfront($storage);
46
$parserBuilder->build();
47
48
$listOfDetail = $parserBuilder->andGetListOfDetailOrNullAfterwards();
49
50
foreach ($listOfDetail as $detail) {
0 ignored issues
show
The expression $listOfDetail of type null|array<integer,objec...er\DomainModel\Detail>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
51
    $listOfPidToUriPathWithQuery[$detail->pid()] = $detail->uriPathWithQuery();
52
53
    if ($detail->pid() == $pid) {
54
        if ($uriPathProvided) {
55
            if ($stringUtility->startsWith($detail->uriPathWithQuery(), $uriPath)) {
56
                $foundNoMatchingDetail = false;
57
58
                echo ':: Found a request with the pid: "' . $pid . '".' . PHP_EOL;
59
                echo ':: Found a request where the uri path with query starts with: "' . $uriPath . '".' . PHP_EOL;
60
                echo ':: Uri path with query' . PHP_EOL;
61
                echo $detail->uriPathWithQuery() . PHP_EOL;
62
            }
63
        } else {
64
            $foundNoMatchingDetail = false;
65
66
            echo ':: Found a request with the pid: "' . $pid . '".' . PHP_EOL;
67
            echo ':: Uri path with query' . PHP_EOL;
68
            echo $detail->uriPathWithQuery() . PHP_EOL;
69
        }
70
    }
71
}
72
73
if ($foundNoMatchingDetail) {
74
    echo ':: Dumping list of available requests.' . PHP_EOL;
75
    echo PHP_EOL;
76
    echo 'pid' . "\t" . 'uri path with query' . PHP_EOL;
77
    echo '--------------------------------' . PHP_EOL;
78
79
    foreach ($listOfPidToUriPathWithQuery as $pid => $uriPathWithQuery) {
80
        echo $pid . "\t" . $uriPathWithQuery . PHP_EOL;
81
    }
82
}
83
//end of business logic