Completed
Push — master ( 1a8c72...81e1ab )
by Marco
12:55
created

StatusCodes   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 2
1
<?php namespace Comodojo\Zip\Base;
2
3
use \ZipArchive;
4
5
/**
6
 * comodojo/zip - ZipArchive toolbox
7
 *
8
 * @package     Comodojo Spare Parts
9
 * @author      Marco Giovinazzi <[email protected]>
10
 * @license     MIT
11
 *
12
 * LICENSE:
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
 * THE SOFTWARE.
21
 */
22
23
class StatusCodes {
24
25
    /**
26
     * Array of well known zip status codes
27
     *
28
     * @const array
29
     */
30
    const ZIP_STATUS_CODES = [
31
        ZipArchive::ER_OK           => 'No error',
32
        ZipArchive::ER_MULTIDISK    => 'Multi-disk zip archives not supported',
33
        ZipArchive::ER_RENAME       => 'Renaming temporary file failed',
34
        ZipArchive::ER_CLOSE        => 'Closing zip archive failed',
35
        ZipArchive::ER_SEEK         => 'Seek error',
36
        ZipArchive::ER_READ         => 'Read error',
37
        ZipArchive::ER_WRITE        => 'Write error',
38
        ZipArchive::ER_CRC          => 'CRC error',
39
        ZipArchive::ER_ZIPCLOSED    => 'Containing zip archive was closed',
40
        ZipArchive::ER_NOENT        => 'No such file',
41
        ZipArchive::ER_EXISTS       => 'File already exists',
42
        ZipArchive::ER_OPEN         => 'Can\'t open file',
43
        ZipArchive::ER_TMPOPEN      => 'Failure to create temporary file',
44
        ZipArchive::ER_ZLIB         => 'Zlib error',
45
        ZipArchive::ER_MEMORY       => 'Malloc failure',
46
        ZipArchive::ER_CHANGED      => 'Entry has been changed',
47
        ZipArchive::ER_COMPNOTSUPP  => 'Compression method not supported',
48
        ZipArchive::ER_EOF          => 'Premature EOF',
49
        ZipArchive::ER_INVAL        => 'Invalid argument',
50
        ZipArchive::ER_NOZIP        => 'Not a zip archive',
51
        ZipArchive::ER_INTERNAL     => 'Internal error',
52
        ZipArchive::ER_INCONS       => 'Zip archive inconsistent',
53
        ZipArchive::ER_REMOVE       => 'Can\'t remove file',
54
        ZipArchive::ER_DELETED      => 'Entry has been deleted'
55
    ];
56
57
    /**
58
     * Get status from zip status code
59
     *
60
     * @param   int $code   ZIP status code
61
     *
62
     * @return  string
63
     */
64
    public static function get(int $code): string {
65
66
        if ( array_key_exists($code, self::ZIP_STATUS_CODES) ) return self::ZIP_STATUS_CODES[$code];
67
68
        else return sprintf('Unknown status %s', $code);
69
70
    }
71
72
}
73