ZipInfo   A
last analyzed

Complexity

Total Complexity 33

Size/Duplication

Total Lines 246
Duplicated Lines 0 %

Test Coverage

Coverage 75.86%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 67
c 1
b 0
f 1
dl 0
loc 246
ccs 66
cts 87
cp 0.7586
rs 9.76
wmc 33

23 Methods

Rating   Name   Duplication   Size   Complexity  
A isFolder() 0 3 1
A getEncryptionMethod() 0 5 2
A __construct() 0 3 1
A isEncrypted() 0 3 1
A getMethodName() 0 3 1
B __toString() 0 22 7
A getSize() 0 3 1
A getName() 0 3 1
A getCompressionLevel() 0 3 1
A getEncryptionMethodName() 0 3 1
A getCompressedSize() 0 3 1
A getMtime() 0 3 1
A getCtime() 0 5 2
A getCompressionMethod() 0 3 1
A getMethod() 0 3 1
A getPlatform() 0 3 1
A getAttributes() 0 11 2
A getComment() 0 3 1
A getVersion() 0 3 1
A getAtime() 0 5 2
A toArray() 0 20 1
A getCrc() 0 3 1
A getPlatformName() 0 3 1
1
<?php
2
3
namespace PhpZip\Model;
4
5
use PhpZip\Constants\ZipCompressionMethod;
6
use PhpZip\Constants\ZipEncryptionMethod;
7
use PhpZip\Constants\ZipPlatform;
8
use PhpZip\Util\FileAttribUtil;
9
use PhpZip\Util\FilesUtil;
10
11
/**
12
 * Zip info.
13
 *
14
 * @author Ne-Lexa [email protected]
15
 * @license MIT
16
 *
17
 * @deprecated Use ZipEntry
18
 */
19
class ZipInfo
20
{
21
    /** @var ZipEntry */
22
    private $entry;
23
24
    /**
25
     * ZipInfo constructor.
26
     *
27
     * @param ZipEntry $entry
28
     */
29 38
    public function __construct(ZipEntry $entry)
30
    {
31 38
        $this->entry = $entry;
32 38
    }
33
34
    /**
35
     * @param ZipEntry $entry
36
     *
37
     * @return string
38
     *
39
     * @deprecated Use {@see ZipPlatform::getPlatformName()}
40
     */
41 1
    public static function getPlatformName(ZipEntry $entry)
42
    {
43 1
        return ZipPlatform::getPlatformName($entry->getExtractedOS());
44
    }
45
46
    /**
47
     * @return string
48
     */
49 3
    public function getName()
50
    {
51 3
        return $this->entry->getName();
52
    }
53
54
    /**
55
     * @return bool
56
     */
57 5
    public function isFolder()
58
    {
59 5
        return $this->entry->isDirectory();
60
    }
61
62
    /**
63
     * @return int
64
     */
65 2
    public function getSize()
66
    {
67 2
        return $this->entry->getUncompressedSize();
68
    }
69
70
    /**
71
     * @return int
72
     */
73 1
    public function getCompressedSize()
74
    {
75 1
        return $this->entry->getCompressedSize();
76
    }
77
78
    /**
79
     * @return int
80
     */
81 1
    public function getMtime()
82
    {
83 1
        return $this->entry->getMTime()->getTimestamp();
84
    }
85
86
    /**
87
     * @return int|null
88
     */
89 1
    public function getCtime()
90
    {
91 1
        $ctime = $this->entry->getCTime();
92
93 1
        return $ctime === null ? null : $ctime->getTimestamp();
94
    }
95
96
    /**
97
     * @return int|null
98
     */
99 1
    public function getAtime()
100
    {
101 1
        $atime = $this->entry->getATime();
102
103 1
        return $atime === null ? null : $atime->getTimestamp();
104
    }
105
106
    /**
107
     * @return string
108
     */
109 1
    public function getAttributes()
110
    {
111 1
        $externalAttributes = $this->entry->getExternalAttributes();
112
113 1
        if ($this->entry->getCreatedOS() === ZipPlatform::OS_UNIX) {
114
            $permission = (($externalAttributes >> 16) & 0xFFFF);
115
116
            return FileAttribUtil::getUnixMode($permission);
117
        }
118
119 1
        return FileAttribUtil::getDosMode($externalAttributes);
120
    }
121
122
    /**
123
     * @return bool
124
     */
125 13
    public function isEncrypted()
126
    {
127 13
        return $this->entry->isEncrypted();
128
    }
129
130
    /**
131
     * @return string|null
132
     */
133 1
    public function getComment()
134
    {
135 1
        return $this->entry->getComment();
136
    }
137
138
    /**
139
     * @return int
140
     */
141 1
    public function getCrc()
142
    {
143 1
        return $this->entry->getCrc();
144
    }
145
146
    /**
147
     * @return string
148
     *
149
     * @deprecated use \PhpZip\Model\ZipInfo::getMethodName()
150
     */
151 1
    public function getMethod()
152
    {
153 1
        return $this->getMethodName();
154
    }
155
156
    /**
157
     * @return string
158
     */
159 14
    public function getMethodName()
160
    {
161 14
        return ZipCompressionMethod::getCompressionMethodName($this->entry->getCompressionMethod());
162
    }
163
164
    /**
165
     * @return string
166
     */
167 8
    public function getEncryptionMethodName()
168
    {
169 8
        return ZipEncryptionMethod::getEncryptionMethodName($this->entry->getEncryptionMethod());
170
    }
171
172
    /**
173
     * @return string
174
     */
175 1
    public function getPlatform()
176
    {
177 1
        return ZipPlatform::getPlatformName($this->entry->getExtractedOS());
178
    }
179
180
    /**
181
     * @return int
182
     */
183 1
    public function getVersion()
184
    {
185 1
        return $this->entry->getExtractVersion();
186
    }
187
188
    /**
189
     * @return int|null
190
     */
191 4
    public function getEncryptionMethod()
192
    {
193 4
        $encryptionMethod = $this->entry->getEncryptionMethod();
194
195 4
        return $encryptionMethod === ZipEncryptionMethod::NONE ? null : $encryptionMethod;
196
    }
197
198
    /**
199
     * @return int|null
200
     */
201 11
    public function getCompressionLevel()
202
    {
203 11
        return $this->entry->getCompressionLevel();
204
    }
205
206
    /**
207
     * @return int
208
     */
209 1
    public function getCompressionMethod()
210
    {
211 1
        return $this->entry->getCompressionMethod();
212
    }
213
214
    /**
215
     * @return array
216
     */
217 1
    public function toArray()
218
    {
219
        return [
220 1
            'name' => $this->getName(),
221 1
            'folder' => $this->isFolder(),
222 1
            'size' => $this->getSize(),
223 1
            'compressed_size' => $this->getCompressedSize(),
224 1
            'modified' => $this->getMtime(),
225 1
            'created' => $this->getCtime(),
226 1
            'accessed' => $this->getAtime(),
227 1
            'attributes' => $this->getAttributes(),
228 1
            'encrypted' => $this->isEncrypted(),
229 1
            'encryption_method' => $this->getEncryptionMethod(),
230 1
            'encryption_method_name' => $this->getEncryptionMethodName(),
231 1
            'comment' => $this->getComment(),
232 1
            'crc' => $this->getCrc(),
233 1
            'method_name' => $this->getMethodName(),
234 1
            'compression_method' => $this->getCompressionMethod(),
235 1
            'platform' => $this->getPlatform(),
236 1
            'version' => $this->getVersion(),
237
        ];
238
    }
239
240
    /**
241
     * @return string
242
     */
243
    public function __toString()
244
    {
245
        $ctime = $this->entry->getCTime();
246
        $atime = $this->entry->getATime();
247
        $comment = $this->getComment();
248
249
        return __CLASS__ . ' {'
250
            . 'Name="' . $this->getName() . '", '
251
            . ($this->isFolder() ? 'Folder, ' : '')
252
            . 'Size="' . FilesUtil::humanSize($this->getSize()) . '"'
253
            . ', Compressed size="' . FilesUtil::humanSize($this->getCompressedSize()) . '"'
254
            . ', Modified time="' . $this->entry->getMTime()->format(\DATE_W3C) . '", '
255
            . ($ctime !== null ? 'Created time="' . $ctime->format(\DATE_W3C) . '", ' : '')
256
            . ($atime !== null ? 'Accessed time="' . $atime->format(\DATE_W3C) . '", ' : '')
257
            . ($this->isEncrypted() ? 'Encrypted, ' : '')
258
            . ($comment !== null ? 'Comment="' . $comment . '", ' : '')
0 ignored issues
show
introduced by
The condition $comment !== null is always true.
Loading history...
259
            . (!empty($this->crc) ? 'Crc=0x' . dechex($this->crc) . ', ' : '')
0 ignored issues
show
Bug Best Practice introduced by
The property crc does not exist on PhpZip\Model\ZipInfo. Did you maybe forget to declare it?
Loading history...
260
            . 'Method name="' . $this->getMethodName() . '", '
261
            . 'Attributes="' . $this->getAttributes() . '", '
262
            . 'Platform="' . $this->getPlatform() . '", '
263
            . 'Version=' . $this->getVersion()
264
            . '}';
265
    }
266
}
267