Failed Conditions
Push — master ( bea035...793b2f )
by Adrien
17:10 queued 55s
created

UploadError::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Upload;
6
7
use Exception;
8
use GraphQL\Error\Error;
9
10
final class UploadError extends Error
11
{
12 8
    public function __construct(int $uploadError)
13
    {
14 8
        parent::__construct('File upload: ' . $this->getMessageFromUploadError($uploadError));
15
    }
16
17 8
    private function getMessageFromUploadError(int $uploadError): string
18
    {
19 8
        return match ($uploadError) {
20 8
            UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
21 8
            UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the upload',
22 8
            UPLOAD_ERR_FORM_SIZE => 'The file exceeds the `MAX_FILE_SIZE` directive that was specified in the HTML form',
23 8
            UPLOAD_ERR_INI_SIZE => 'The file exceeds the `upload_max_filesize` of ' . Utility::toMebibyte(Utility::getUploadMaxFilesize()),
24 8
            UPLOAD_ERR_NO_FILE => 'No file was uploaded',
25 8
            UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',
26 8
            UPLOAD_ERR_PARTIAL => 'The file was only partially uploaded',
27 8
            default => throw new Exception('Unsupported UPLOAD_ERR_* constant value: ' . $uploadError),
28 8
        };
29
    }
30
}
31