These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of Zippy. |
||
5 | * |
||
6 | * (c) Alchemy <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | namespace Alchemy\Zippy\Parser; |
||
12 | |||
13 | /** |
||
14 | * This class is responsible of parsing GNUTar command line output |
||
15 | */ |
||
16 | class ZipOutputParser implements ParserInterface |
||
17 | { |
||
18 | const LENGTH = "(\d*)"; |
||
19 | const ISO_DATE = "([0-9]+-[0-9]+-[0-9]+\s+[0-9]+:[0-9]+)"; |
||
20 | const FILENAME = "(.*)"; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private $dateFormat; |
||
26 | |||
27 | /** |
||
28 | * @param string $dateFormat |
||
29 | */ |
||
30 | public function __construct($dateFormat = "Y-m-d H:i") |
||
31 | { |
||
32 | $this->dateFormat = $dateFormat; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @inheritdoc |
||
37 | */ |
||
38 | public function parseFileListing($output) |
||
39 | { |
||
40 | $lines = array_values(array_filter(explode("\n", $output))); |
||
41 | $members = array(); |
||
42 | |||
43 | foreach ($lines as $line) { |
||
44 | $matches = array(); |
||
45 | |||
46 | // 785 2012-10-24 10:39 file |
||
47 | if (!preg_match_all("#" . |
||
48 | self::LENGTH . "\s+" . // match (785) |
||
49 | self::ISO_DATE . "\s+" . // match (2012-10-24 10:39) |
||
50 | self::FILENAME . // match (file) |
||
51 | "#", |
||
52 | $line, $matches, PREG_SET_ORDER |
||
53 | )) { |
||
54 | continue; |
||
55 | } |
||
56 | |||
57 | $chunks = array_shift($matches); |
||
58 | |||
59 | if (4 !== count($chunks)) { |
||
60 | continue; |
||
61 | } |
||
62 | |||
63 | $members[] = array( |
||
64 | 'location' => $chunks[3], |
||
65 | 'size' => $chunks[1], |
||
66 | 'mtime' => \DateTime::createFromFormat($this->dateFormat, $chunks[2]), |
||
67 | 'is_dir' => '/' === substr($chunks[3], -1) |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | return $members; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @inheritdoc |
||
76 | */ |
||
77 | View Code Duplication | public function parseInflatorVersion($output) |
|
78 | { |
||
79 | $lines = array_values(array_filter(explode("\n", $output, 3))); |
||
80 | |||
81 | $chunks = explode(' ', $lines[1], 3); |
||
82 | |||
83 | if (2 > count($chunks)) { |
||
84 | return null; |
||
85 | } |
||
86 | |||
87 | list($name, $version) = $chunks; |
||
0 ignored issues
–
show
|
|||
88 | |||
89 | return $version; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | View Code Duplication | public function parseDeflatorVersion($output) |
|
96 | { |
||
97 | $lines = array_values(array_filter(explode("\n", $output, 2))); |
||
98 | $firstLine = array_shift($lines); |
||
99 | $chunks = explode(' ', $firstLine, 3); |
||
100 | |||
101 | if (2 > count($chunks)) { |
||
102 | return null; |
||
103 | } |
||
104 | |||
105 | list($name, $version) = $chunks; |
||
0 ignored issues
–
show
The assignment to
$name is unused. Consider omitting it like so list($first,,$third) .
This checks looks for assignemnts to variables using the Consider the following code example. <?php
function returnThreeValues() {
return array('a', 'b', 'c');
}
list($a, $b, $c) = returnThreeValues();
print $a . " - " . $c;
Only the variables Instead, the list call could have been. list($a,, $c) = returnThreeValues();
Loading history...
|
|||
106 | |||
107 | return $version; |
||
108 | } |
||
109 | } |
||
110 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.