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

example/remote/parse_all.php (6 issues)

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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2017-01-31
5
 */
6
use Net\Bazzline\Component\ApacheServerStatusParser\DomainModel\ReduceDataAbleToArrayInterface;
7
8
require __DIR__ . '/../../vendor/autoload.php';
9
10
//begin of helper functions
11
/**
12
 * @param array $array
13
 * @param string $prefix
14
 */
15 View Code Duplication
function dumpArray(array $array, $prefix = '  ')
0 ignored issues
show
The function dumpArray() has been defined more than once; this definition is ignored, only the first definition in example/local/parse_all.php (L15-28) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16
{
17
    foreach ($array as $item => $value) {
18
        if ($value instanceof ReduceDataAbleToArrayInterface) {
19
            echo $prefix . $item . PHP_EOL;
20
            dumpArray($value->reduceDataToArray(), str_repeat($prefix, 2));
21
        } else if (is_array($value)) {
22
            echo $prefix . $item . PHP_EOL;
23
            dumpArray($value, str_repeat($prefix, 2));
24
        } else {
25
            echo $prefix . $item . ': ' . $value . PHP_EOL;
26
        }
27
    }
28
}
29
30
/**
31
 * @param array $lines
32
 * @param string $name
33
 */
34 View Code Duplication
function dumpSectionIfThereIsSomeContent(array $lines, $name)
0 ignored issues
show
The function dumpSectionIfThereIsSomeContent() has been defined more than once; this definition is ignored, only the first definition in example/local/parse_all.php (L34-44) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
{
36
    if (!empty($lines)) {
37
        echo '==== ' . $name . ' ====' . PHP_EOL;
38
        echo PHP_EOL;
39
40
        dumpArray($lines);
41
42
        echo PHP_EOL;
43
    }
44
}
45
//end of helper functions
46
47
//begin of dependencies
48
$listOfNameToElapsedTime    = [];
49
$parserBuilderFactory       = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\ParserBuilderFactory();
50
$storageBuilder             = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\RemoteStorageBuilder();
51
$urlToTheExampleFile        = (
52
    ($argc > 1)
53
        ? $argv[1]
54
        : 'http://testdata.bazzline.net/apache_server_status/index.html'
55
);
56
57
$parserBuilder  = $parserBuilderFactory->create();
58
//end of dependencies
59
60
//begin of business logic
61
PHP_Timer::start();
62
63
$storageBuilder->setUrlToTheApacheStatusFileToParseUpfront($urlToTheExampleFile);
64
$storageBuilder->selectParseModeAllUpfront();
65
$storageBuilder->build();
66
67
$listOfNameToElapsedTime['fetching']    = PHP_Timer::secondsToTimeString(
68
    PHP_Timer::stop()
69
);
70
71
$storage    = $storageBuilder->andGetStorageAfterTheBuild();
72
73
dumpSectionIfThereIsSomeContent($storage->getListOfInformation(), 'Information');
74
dumpSectionIfThereIsSomeContent($storage->getListOfDetail(), 'Detail');
75
dumpSectionIfThereIsSomeContent($storage->getListOfScoreboard(), 'Scoreboard');
76
dumpSectionIfThereIsSomeContent($storage->getListOfStatistic(), 'Statistic');
77
78
PHP_Timer::start();
79
80
$parserBuilder->setStorageUpfront($storage);
81
$parserBuilder->build();
82
83
$listOfNameToElapsedTime['parsing']    = PHP_Timer::secondsToTimeString(
84
    PHP_Timer::stop()
85
);
86
87
dumpSectionIfThereIsSomeContent(
88
    $parserBuilder->andGetListOfDetailOrNullAfterwards(),
0 ignored issues
show
It seems like $parserBuilder->andGetLi...etailOrNullAfterwards() targeting Net\Bazzline\Component\A...etailOrNullAfterwards() can also be of type null; however, dumpSectionIfThereIsSomeContent() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
89
    'Parsed Detail'
90
);
91
92
dumpSectionIfThereIsSomeContent(
93
    [
94
        $parserBuilder->andGetInformationOrNullAfterwards()
95
    ],
96
    'Parsed Information'
97
);
98
99
dumpSectionIfThereIsSomeContent(
100
    [
101
        $parserBuilder->andGetScoreboardOrNullAfterwards()
102
    ],
103
    'Parsed Scoreboard'
104
);
105
106
dumpSectionIfThereIsSomeContent(
107
    [
108
        $parserBuilder->andGetStatisticOrNullAfterwards()
109
    ],
110
    'Parsed Statistic'
111
);
112
113
foreach ($listOfNameToElapsedTime as $name => $elapsedTime) {
114
    echo $name . ' took: ' . $elapsedTime . PHP_EOL;
115
}
116
//end of business logic
117