Completed
Push — master ( 6e2258...071df3 )
by arto
02:13
created

example/remote/parse_all.php (1 issue)

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 16 and the first side effect is on line 9.

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 JonasRudolph\PHPComponents\StringUtility\Implementation\StringUtility;
7
use Net\Bazzline\Component\ApacheServerStatusParser\DomainModel\ReduceDataAbleToArrayInterface;
8
9
require __DIR__ . '/../../vendor/autoload.php';
10
11
//begin of helper functions
12
/**
13
 * @param array $array
14
 * @param string $prefix
15
 */
16 View Code Duplication
function dumpArray(array $array, $prefix = '  ')
17
{
18
    foreach ($array as $item => $value) {
19
        if ($value instanceof ReduceDataAbleToArrayInterface) {
20
            echo $prefix . $item . PHP_EOL;
21
            dumpArray($value->reduceDataToArray(), str_repeat($prefix, 2));
22
        } else if (is_array($value)) {
23
            echo $prefix . $item . PHP_EOL;
24
            dumpArray($value, str_repeat($prefix, 2));
25
        } else {
26
            echo $prefix . $item . ': ' . $value . PHP_EOL;
27
        }
28
    }
29
}
30
31
/**
32
 * @param array $lines
33
 * @param string $name
34
 */
35 View Code Duplication
function dumpSectionIfThereIsSomeContent(array $lines, $name)
36
{
37
    if (!empty($lines)) {
38
        echo '==== ' . $name .' ====' . PHP_EOL;
39
        echo PHP_EOL;
40
41
        dumpArray($lines);
42
43
        echo PHP_EOL;
44
    }
45
}
46
//end of helper functions
47
48
//begin of dependencies
49
$listOfNameToElapsedTime    = [];
50
$parserBuilderFactory       = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\ParserBuilderFactory();
51
$storageBuilder             = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\RemoteStorageBuilder();
52
$urlToTheExampleFile        = ($argc > 1)
53
    ? $argv[1]
54
    : 'http://testdata.bazzline.net/apache_server_status/index.html';
55
56
$parserBuilder  = $parserBuilderFactory->create();
57
//end of dependencies
58
59
//begin of business logic
60
PHP_Timer::start();
61
62
$storageBuilder->setUrlToTheApacheStatusFileToParseUpfront($urlToTheExampleFile);
63
$storageBuilder->selectParseModeAllUpfront();
64
$storageBuilder->build();
65
66
$listOfNameToElapsedTime['fetching']    = PHP_Timer::secondsToTimeString(
67
    PHP_Timer::stop()
68
);
69
70
$storage    = $storageBuilder->andGetStorageAfterTheBuild();
71
72
dumpSectionIfThereIsSomeContent($storage->getListOfInformation(), 'Information');
73
dumpSectionIfThereIsSomeContent($storage->getListOfDetail(), 'Detail');
74
dumpSectionIfThereIsSomeContent($storage->getListOfScoreboard(), 'Scoreboard');
75
dumpSectionIfThereIsSomeContent($storage->getListOfStatistic(), 'Statistic');
76
77
PHP_Timer::start();
78
79
$parserBuilder->setStorageUpfront($storage);
80
$parserBuilder->build();
81
82
$listOfNameToElapsedTime['parsing']    = PHP_Timer::secondsToTimeString(
83
    PHP_Timer::stop()
84
);
85
86
dumpSectionIfThereIsSomeContent(
87
    $parserBuilder->andGetListOfDetailOrNullAfterwards(),
88
    'Parsed Detail'
89
);
90
91
dumpSectionIfThereIsSomeContent(
92
    [
93
        $parserBuilder->andGetInformationOrNullAfterwards()
94
    ],
95
    'Parsed Information'
96
);
97
98
dumpSectionIfThereIsSomeContent(
99
    [
100
        $parserBuilder->andGetScoreboardOrNullAfterwards()
101
    ],
102
    'Parsed Scoreboard'
103
);
104
105
dumpSectionIfThereIsSomeContent(
106
    [
107
        $parserBuilder->andGetStatisticOrNullAfterwards()
108
    ],
109
    'Parsed Statistic'
110
);
111
112
foreach ($listOfNameToElapsedTime as $name => $elapsedTime) {
113
    echo $name . ' took: ' . $elapsedTime . PHP_EOL;
114
}
115
//end of business logic
116