Passed
Pull Request — master (#43)
by Arman
03:54
created

FileUploadException::directoryNotExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.5.0
13
 */
14
15
namespace Quantum\Exceptions;
16
17
/**
18
 * Class FileUploadException
19
 * @package Quantum\Exceptions
20
 */
21
class FileUploadException extends \Exception
22
{
23
    /**
24
     * File already exists message
25
     */
26
    const FILE_ALREADY_EXISTS = 'File already exists';
27
28
    /**
29
     * File was not sent with a POST request message
30
     */
31
    const FILE_NOT_UPLOADED = 'The uploaded file was not sent with a POST request';
32
33
    /**
34
     * Directory does not exists message
35
     */
36
    const DIRECTORY_NOT_EXIST = 'Directory `{%1}` does not exists';
37
38
    /**
39
     * Directory is not writable message
40
     */
41
    const DIRECTORY_NOT_WRITABLE = 'Directory `{%1}` not writable';
42
43
    /**
44
     * Upload file not found message
45
     */
46
    const UPLOADED_FILE_NOT_FOUND = 'Cannot find uploaded file identified by key `{%1}`';
47
48
    /**
49
     * Directory can not be created message
50
     */
51
    const DIRECTORY_CANT_BE_CREATED = 'Directory `{%1}` could not be created';
52
53
    /**
54
     * @return \Quantum\Exceptions\FileUploadException
55
     */
56
    public static function fileAlreadyExists(): FileUploadException
57
    {
58
        return new static(self::FILE_ALREADY_EXISTS, E_WARNING);
59
    }
60
61
    /**
62
     * @return \Quantum\Exceptions\FileUploadException
63
     */
64
    public static function fileNotUploaded(): FileUploadException
65
    {
66
        return new static(self::FILE_NOT_UPLOADED, E_WARNING);
67
    }
68
69
    /**
70
     * @param string $name
71
     * @return \Quantum\Exceptions\FileUploadException
72
     */
73
    public static function directoryNotExists(string $name): FileUploadException
74
    {
75
        return new static(_message(self::DIRECTORY_NOT_EXIST, $name), E_WARNING);
76
    }
77
78
    /**
79
     * @param string $name
80
     * @return \Quantum\Exceptions\FileUploadException
81
     */
82
    public static function directoryNotWritable(string $name): FileUploadException
83
    {
84
        return new static(_message(self::DIRECTORY_NOT_WRITABLE, $name), E_WARNING);
85
    }
86
87
    /**
88
     * @param string $name
89
     * @return \Quantum\Exceptions\FileUploadException
90
     */
91
    public static function fileNotFound(string $name): FileUploadException
92
    {
93
        return new static(_message(self::UPLOADED_FILE_NOT_FOUND, $name), E_WARNING);
94
    }
95
}
96