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-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
|
|||
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
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->selectParseModeDetailOnlyUpfront(); |
||
65 | $storageBuilder->build(); |
||
66 | |||
67 | $listOfNameToElapsedTime['fetching'] = PHP_Timer::secondsToTimeString( |
||
68 | PHP_Timer::stop() |
||
69 | ); |
||
70 | |||
71 | $storage = $storageBuilder->andGetStorageAfterTheBuild(); |
||
72 | |||
73 | dumpSectionIfThereIsSomeContent($storage->getListOfDetail(), 'Detail'); |
||
74 | |||
75 | PHP_Timer::start(); |
||
76 | |||
77 | $parserBuilder->setStorageUpfront($storage); |
||
78 | $parserBuilder->build(); |
||
79 | |||
80 | $listOfNameToElapsedTime['parsing'] = PHP_Timer::secondsToTimeString( |
||
81 | PHP_Timer::stop() |
||
82 | ); |
||
83 | |||
84 | dumpSectionIfThereIsSomeContent( |
||
85 | $parserBuilder->andGetListOfDetailOrNullAfterwards(), |
||
86 | 'Parsed Detail' |
||
87 | ); |
||
88 | |||
89 | foreach ($listOfNameToElapsedTime as $name => $elapsedTime) { |
||
90 | echo $name . ' took: ' . $elapsedTime . PHP_EOL; |
||
91 | } |
||
92 | //end of business logic |
||
93 |
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.