• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mpyw / laravel-file-errors / 4401972525

pending completion
4401972525

push

github

mpyw
chore: 🤖 Drop stale version support

24 of 24 relevant lines covered (100.0%)

9.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/UploadError.php
1
<?php
2

3
namespace Mpyw\LaravelFileErrors;
4

5
use Illuminate\Http\UploadedFile;
6

7
/**
8
 * Class UploadedError
9
 */
10
class UploadError
11
{
12
    // errors
13
    public const ERR_OK = UPLOAD_ERR_OK;
14
    public const ERR_INI_SIZE = UPLOAD_ERR_INI_SIZE;
15
    public const ERR_FORM_SIZE = UPLOAD_ERR_FORM_SIZE;
16
    public const ERR_PARTIAL = UPLOAD_ERR_PARTIAL;
17
    public const ERR_NO_FILE = UPLOAD_ERR_NO_FILE;
18
    public const ERR_NO_TMP_DIR = UPLOAD_ERR_NO_TMP_DIR;
19
    public const ERR_CANT_WRITE = UPLOAD_ERR_CANT_WRITE;
20
    public const ERR_EXTENSION = UPLOAD_ERR_EXTENSION;
21
    public const ERR_UNKNOWN = -1;
22

23
    // titles
24
    public const TITLE_OK = '';
25
    public const TITLE_INI_SIZE = 'ini_size';
26
    public const TITLE_FORM_SIZE = 'form_size';
27
    public const TITLE_PARTIAL = 'partial';
28
    public const TITLE_NO_FILE = 'no_file';
29
    public const TITLE_NO_TMP_DIR = 'no_tmp_dir';
30
    public const TITLE_CANT_WRITE = 'cant_write';
31
    public const TITLE_EXTENSION = 'extension';
32
    public const TITLE_UNKNOWN = 'unknown';
33

34
    public const MAP = [
35
        self::ERR_OK => self::TITLE_OK,
36
        self::ERR_INI_SIZE => self::TITLE_INI_SIZE,
37
        self::ERR_FORM_SIZE => self::TITLE_FORM_SIZE,
38
        self::ERR_PARTIAL => self::TITLE_PARTIAL,
39
        self::ERR_NO_FILE => self::TITLE_NO_FILE,
40
        self::ERR_NO_TMP_DIR => self::TITLE_NO_TMP_DIR,
41
        self::ERR_CANT_WRITE => self::TITLE_CANT_WRITE,
42
        self::ERR_EXTENSION => self::TITLE_EXTENSION,
43
        self::ERR_UNKNOWN => self::TITLE_UNKNOWN,
44
    ];
45

46
    /**
47
     * UploadedFileError constructor.
48
     */
49
    public function __construct(protected int $code, protected string $title)
50
    {
51
    }
24✔
52

53
    public function getCode(): int
54
    {
55
        return $this->code;
15✔
56
    }
57

58
    public function getTitle(): string
59
    {
60
        return $this->title;
24✔
61
    }
62

63
    public function __toString(): string
64
    {
65
        return $this->getTitle();
9✔
66
    }
67

68
    public static function fromCode(int $code): static
69
    {
70
        return isset(static::MAP[$code])
12✔
71
            ? new static($code, static::MAP[$code])
9✔
72
            : static::unknown();
12✔
73
    }
74

75
    public static function fromTitle(string $title): static
76
    {
77
        static $map;
6✔
78

79
        if (!$map) {
6✔
80
            $map = array_flip(static::MAP);
3✔
81
        }
82

83
        return isset($map[$title])
6✔
84
            ? new static($map[$title], $title)
3✔
85
            : static::unknown();
6✔
86
    }
87

88
    public static function fromFile(UploadedFile $file): static
89
    {
90
        return static::fromCode($file->getError());
6✔
91
    }
92

93
    public static function unknown(): static
94
    {
95
        return new static(static::ERR_UNKNOWN, static::TITLE_UNKNOWN);
9✔
96
    }
97
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc