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
|
|||
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 = ' ') |
|
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) |
|
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 | $pathToTheExampleFile = ( |
||
50 | ($argc > 1) |
||
51 | ? $argv[1] |
||
52 | : __DIR__ . '/server-status?notable.html' |
||
53 | ); |
||
54 | $parserBuilderFactory = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\ParserBuilderFactory(); |
||
55 | $storageBuilder = new \Net\Bazzline\Component\ApacheServerStatusParser\Service\Builder\LocalStorageBuilder(); |
||
56 | |||
57 | $parserBuilder = $parserBuilderFactory->create(); |
||
58 | //end of dependencies |
||
59 | |||
60 | //begin of business logic |
||
61 | PHP_Timer::start(); |
||
62 | |||
63 | $storageBuilder->setPathToTheApacheStatusFileToParseUpfront($pathToTheExampleFile); |
||
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(), |
||
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 |
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.