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

UploadError   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getMessageFromUploadError() 0 11 1
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