Passed
Push — master ( e9611b...a3681d )
by f
13:07
created

BasicDriver::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
1
<?php
2
namespace wapmorgan\UnifiedArchive\Drivers;
3
4
use wapmorgan\UnifiedArchive\ArchiveEntry;
5
use wapmorgan\UnifiedArchive\ArchiveInformation;
6
use wapmorgan\UnifiedArchive\Exceptions\ArchiveExtractionException;
7
use wapmorgan\UnifiedArchive\Exceptions\ArchiveModificationException;
8
use wapmorgan\UnifiedArchive\Exceptions\NonExistentArchiveFileException;
9
use wapmorgan\UnifiedArchive\Exceptions\UnsupportedOperationException;
10
11
abstract class BasicDriver
12
{
13
    const TYPE_EXTENSION = 1;
14
    const TYPE_UTILITIES = 2;
15
    const TYPE_PURE_PHP = 3;
16
17
    const COMPRESSION_NONE = 0;
18
    const COMPRESSION_WEAK = 1;
19
    const COMPRESSION_AVERAGE = 2;
20
    const COMPRESSION_STRONG = 3;
21
    const COMPRESSION_MAXIMUM = 4;
22
23
    const OPEN = 1;
24
    const OPEN_ENCRYPTED = 2;
25
    const OPEN_VOLUMED = 4;
26
27
    const GET_COMMENT = 64;
28
    const EXTRACT_CONTENT = 128;
29
    const STREAM_CONTENT = 256;
30
31
    const APPEND = 4096;
32
    const DELETE = 8192;
33
    const SET_COMMENT = 16384;
34
35
    const CREATE = 1048576;
36
    const CREATE_ENCRYPTED = 2097152;
37
38
    const TYPE = null;
39
40
    /**
41
     * @return string
42
     */
43
    abstract public static function getDescription();
44
45
    /**
46
     * @return bool
47
     */
48
    abstract public static function isInstalled();
49
50
    /**
51
     * @return string
52
     */
53
    abstract public static function getInstallationInstruction();
54
55
    /**
56
     * @return string[]
57
     */
58
    abstract public static function getSupportedFormats();
59
60
    /**
61
     * @param string $format
62
     * @return int[]
63
     */
64
    abstract public static function checkFormatSupport($format);
65
66
    /**
67
     * @param $format
68
     * @return bool
69
     */
70
    public static function canCreateArchive($format)
0 ignored issues
show
Unused Code introduced by
The parameter $format is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

70
    public static function canCreateArchive(/** @scrutinizer ignore-unused */ $format)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        return false;
73
    }
74
75
    /**
76
     * @param array $files
77
     * @param string $archiveFileName
78
     * @param string $archiveFormat
79
     * @param int $compressionLevel
80
     * @param null $password
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $password is correct as it would always require null to be passed?
Loading history...
81
     * @param $fileProgressCallable
82
     * @return int Number of archived files
83
     * @throws UnsupportedOperationException
84
     */
85
    public static function createArchive(
86
        array $files,
0 ignored issues
show
Unused Code introduced by
The parameter $files is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

86
        /** @scrutinizer ignore-unused */ array $files,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
        $archiveFileName,
0 ignored issues
show
Unused Code introduced by
The parameter $archiveFileName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
        /** @scrutinizer ignore-unused */ $archiveFileName,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
        $archiveFormat,
0 ignored issues
show
Unused Code introduced by
The parameter $archiveFormat is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

88
        /** @scrutinizer ignore-unused */ $archiveFormat,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
        $compressionLevel = self::COMPRESSION_AVERAGE,
0 ignored issues
show
Unused Code introduced by
The parameter $compressionLevel is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

89
        /** @scrutinizer ignore-unused */ $compressionLevel = self::COMPRESSION_AVERAGE,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
        $password = null,
0 ignored issues
show
Unused Code introduced by
The parameter $password is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

90
        /** @scrutinizer ignore-unused */ $password = null,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
        $fileProgressCallable = null
0 ignored issues
show
Unused Code introduced by
The parameter $fileProgressCallable is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

91
        /** @scrutinizer ignore-unused */ $fileProgressCallable = null

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
92
    ) {
93
        throw new UnsupportedOperationException();
94
    }
95
96
    /**
97
     * BasicDriver constructor.
98
     * @param string $archiveFileName
99
     * @param string $format
100
     * @param string|null $password Archive password for opening
101
     */
102
    abstract public function __construct($archiveFileName, $format, $password = null);
103
104
    /**
105
     * Returns summary about an archive.
106
     * Called after
107
     * - constructing
108
     * - addFiles()
109
     * - deleteFiles()
110
     * @return ArchiveInformation
111
     */
112
    abstract public function getArchiveInformation();
113
114
    /**
115
     * @return array
116
     */
117
    abstract public function getFileNames();
118
119
    /**
120
     * @param string $fileName
121
     * @return bool
122
     */
123
    abstract public function isFileExists($fileName);
124
125
    /**
126
     * @param string $fileName
127
     * @return ArchiveEntry|false
128
     */
129
    abstract public function getFileData($fileName);
130
131
    /**
132
     * @param string $fileName
133
     * @return string|false
134
     * @throws NonExistentArchiveFileException
135
     */
136
    abstract public function getFileContent($fileName);
137
138
    /**
139
     * @param string $fileName
140
     * @return resource
141
     */
142
    abstract public function getFileStream($fileName);
143
144
    /**
145
     * @param $string
146
     * @return resource
147
     */
148
    public static function wrapStringInStream($string)
149
    {
150
        $resource = fopen('php://temp', 'r+');
151
        fwrite($resource, $string);
152
        rewind($resource);
153
        return $resource;
154
    }
155
156
    /**
157
     * @param string $outputFolder
158
     * @param array  $files
159
     * @return int Number of extracted files
160
     * @throws ArchiveExtractionException
161
     */
162
    abstract public function extractFiles($outputFolder, array $files);
163
164 5
    /**
165
     * @param string $outputFolder
166 5
     * @return int Number of extracted files
167 5
     * @throws ArchiveExtractionException
168 5
     */
169 5
    abstract public function extractArchive($outputFolder);
170
171
    /**
172
     * @param array $files
173
     * @return false|int Number of deleted files
174
     * @throws UnsupportedOperationException
175
     * @throws ArchiveModificationException
176
     */
177
    public function deleteFiles(array $files)
0 ignored issues
show
Unused Code introduced by
The parameter $files is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

177
    public function deleteFiles(/** @scrutinizer ignore-unused */ array $files)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
178
    {
179
        throw new UnsupportedOperationException();
180
    }
181
182
    /**
183
     * @param array $files
184
     * @return int Number of added files
185
     * @throws UnsupportedOperationException
186
     * @throws ArchiveModificationException
187
     */
188
    public function addFiles(array $files)
0 ignored issues
show
Unused Code introduced by
The parameter $files is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

188
    public function addFiles(/** @scrutinizer ignore-unused */ array $files)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
189
    {
190
        throw new UnsupportedOperationException();
191
    }
192
193
    /**
194
     * @param string $inArchiveName
195
     * @param string $content
196
     * @return bool
197
     * @throws UnsupportedOperationException
198
     * @throws ArchiveModificationException
199
     */
200
    abstract public function addFileFromString($inArchiveName, $content);
201
202
    /**
203
     * @return string|null
204
     */
205
    public function getComment()
206
    {
207
        return null;
208
    }
209
210
    /**
211
     * @param string|null $comment
212
     * @return null
213
     */
214
    public function setComment($comment)
0 ignored issues
show
Unused Code introduced by
The parameter $comment is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

214
    public function setComment(/** @scrutinizer ignore-unused */ $comment)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
215
    {
216
        return null;
217
    }
218
}