Passed
Push — master ( 125b29...554a92 )
by f
27:06 queued 12:02
created

BasicDriver::addFileFromString()   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 2
dl 0
loc 3
rs 10
ccs 0
cts 1
cp 0
crap 2
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
    static $typeLabels = [
18
        BasicDriver::TYPE_EXTENSION => 'php extension',
19
        BasicDriver::TYPE_UTILITIES => 'utilities + php bridge',
20
        BasicDriver::TYPE_PURE_PHP => 'pure php',
21
    ];
22
23
    const COMPRESSION_NONE = 0;
24
    const COMPRESSION_WEAK = 1;
25
    const COMPRESSION_AVERAGE = 2;
26
    const COMPRESSION_STRONG = 3;
27
    const COMPRESSION_MAXIMUM = 4;
28
29
    const OPEN = 1;
30
    const OPEN_ENCRYPTED = 2;
31
    const OPEN_VOLUMED = 4;
32
33
    const GET_COMMENT = 64;
34
    const EXTRACT_CONTENT = 128;
35
    const STREAM_CONTENT = 256;
36
37
    const APPEND = 4096;
38
    const DELETE = 8192;
39
    const SET_COMMENT = 16384;
40
41
    const CREATE = 1048576;
42
    const CREATE_ENCRYPTED = 2097152;
43
44
    const TYPE = null;
45
46
    /**
47
     * @var string
48
     */
49
    protected $fileName;
50
51
    /**
52
     * @var string
53
     */
54
    protected $format;
55
56
    /**
57
     * @return string
58
     */
59
    abstract public static function getDescription();
60
61
    /**
62
     * @return bool
63
     */
64
    abstract public static function isInstalled();
65
66
    /**
67
     * @return string
68
     */
69
    abstract public static function getInstallationInstruction();
70
71
    /**
72
     * @return string[]
73
     */
74
    abstract public static function getSupportedFormats();
75
76
    /**
77
     * @param string $format
78
     * @return int[]
79
     */
80
    abstract public static function checkFormatSupport($format);
81
82
    /**
83
     * @param $ability
84
     * @return bool
85
     */
86
    public function checkAbility($ability)
87
    {
88
        return in_array($ability, static::checkFormatSupport($this->format), true);
89
    }
90
91
    /**
92
     * @param array $files
93
     * @param string $archiveFileName
94
     * @param string $archiveFormat
95
     * @param int $compressionLevel
96
     * @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...
97
     * @param $fileProgressCallable
98
     * @return int Number of archived files
99
     * @throws UnsupportedOperationException
100
     */
101
    public static function createArchive(
102
        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

102
        /** @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...
103
        $archiveFileName,
104
        $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

104
        /** @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...
105
        $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

105
        /** @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...
106
        $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

106
        /** @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...
107
        $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

107
        /** @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...
108
    ) {
109
        throw new UnsupportedOperationException();
110
    }
111
112
    /**
113
     * BasicDriver constructor.
114
     * @param string $format
115
     * @param string $archiveFileName
116
     * @param string|null $password Archive password for opening
117
     */
118
    public function __construct($archiveFileName, $format, $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

118
    public function __construct($archiveFileName, $format, /** @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...
119
    {
120
        $this->fileName = $archiveFileName;
121
        $this->format = $format;
122
    }
123
124
    /**
125
     * Returns summary about an archive.
126
     * Called after
127
     * - constructing
128
     * - addFiles()
129
     * - deleteFiles()
130
     * @return ArchiveInformation
131
     */
132
    abstract public function getArchiveInformation();
133
134
    /**
135
     * @return array
136
     */
137
    abstract public function getFileNames();
138
139
    /**
140
     * @param string $fileName
141
     * @return bool
142
     */
143
    abstract public function isFileExists($fileName);
144
145
    /**
146
     * @param string $fileName
147
     * @return ArchiveEntry|false
148
     */
149
    abstract public function getFileData($fileName);
150
151
    /**
152
     * @param string $fileName
153
     * @return string|false
154
     * @throws NonExistentArchiveFileException
155
     */
156
    abstract public function getFileContent($fileName);
157
158
    /**
159
     * @param string $fileName
160
     * @return resource
161
     */
162
    abstract public function getFileStream($fileName);
163
164 5
    /**
165
     * @param $string
166 5
     * @return resource
167 5
     */
168 5
    public static function wrapStringInStream($string)
169 5
    {
170
        $resource = fopen('php://temp', 'r+');
171
        fwrite($resource, $string);
172
        rewind($resource);
173
        return $resource;
174
    }
175
176
    /**
177
     * @param string $outputFolder
178
     * @param array  $files
179
     * @return int Number of extracted files
180
     * @throws ArchiveExtractionException
181
     */
182
    abstract public function extractFiles($outputFolder, array $files);
183
184
    /**
185
     * @param string $outputFolder
186
     * @return int Number of extracted files
187
     * @throws ArchiveExtractionException
188
     */
189
    abstract public function extractArchive($outputFolder);
190
191
    /**
192
     * @param array $files
193
     * @return false|int Number of deleted files
194
     * @throws UnsupportedOperationException
195
     * @throws ArchiveModificationException
196
     */
197
    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

197
    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...
198
    {
199
        throw new UnsupportedOperationException();
200
    }
201
202
    /**
203
     * @param array $files
204
     * @return int Number of added files
205
     * @throws UnsupportedOperationException
206
     * @throws ArchiveModificationException
207
     */
208
    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

208
    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...
209
    {
210
        throw new UnsupportedOperationException();
211
    }
212
213
    /**
214
     * @param string $inArchiveName
215
     * @param string $content
216
     * @return bool
217
     * @throws UnsupportedOperationException
218
     * @throws ArchiveModificationException
219
     */
220
    public function addFileFromString($inArchiveName, $content)
0 ignored issues
show
Unused Code introduced by
The parameter $inArchiveName 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

220
    public function addFileFromString(/** @scrutinizer ignore-unused */ $inArchiveName, $content)

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...
Unused Code introduced by
The parameter $content 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

220
    public function addFileFromString($inArchiveName, /** @scrutinizer ignore-unused */ $content)

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...
221
    {
222
        throw new UnsupportedOperationException();
223
    }
224
225
    /**
226
     * @return string|null
227
     * @throws UnsupportedOperationException
228
     */
229
    public function getComment()
230
    {
231
        throw new UnsupportedOperationException();
232
    }
233
234
    /**
235
     * @param string|null $comment
236
     * @return null
237
     * @throws UnsupportedOperationException
238
     */
239
    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

239
    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...
240
    {
241
        throw new UnsupportedOperationException();
242
    }
243
}