ZipExtensionReader::available()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Meta Reader package.
5
 *
6
 * (c) Stephan Wentz <[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
12
namespace Temp\MetaReader;
13
14
use Temp\MetaReader\Value\MetaValue;
15
use Temp\MetaReader\Value\ValueBag;
16
17
/**
18
 * Zip extension reader.
19
 *
20
 * @author Stephan Wentz <[email protected]>
21
 */
22
class ZipExtensionReader implements ReaderInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function available()
28
    {
29 1
        return extension_loaded('zip');
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 2
    public function supports($filename)
36
    {
37 2
        $zip = new \ZipArchive();
38 2
39
        return $zip->open($filename) === true;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44 2
     */
45
    public function read($filename)
46 2
    {
47
        $meta = new ValueBag();
48
49 2
        try {
50 2
            $zip = new \ZipArchive();
51
            $result = $zip->open($filename);
52 2
53 1
            if ($result === true) {
54
                if ($zip->comment) {
55
                    $meta->set('zip.comment', new MetaValue($zip->comment));
56
                }
57 1
58 1
                if ($zip->numFiles) {
59 1
                    $meta->set('zip.numFiles', new MetaValue($zip->numFiles));
60
                }
61 1
62
                if ($zip->status) {
63
                    $meta->set('zip.status', new MetaValue($zip->status));
64
                }
65 1
66 1
                $zip->close();
67 2
            }
68
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by Stephan Wentz
Consider adding a comment why this CATCH block is empty.
Loading history...
69
        }
70 2
71
        return $meta;
72
    }
73
}
74