Completed
Pull Request — master (#6)
by
unknown
02:18
created

ImportFileException   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 57
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A unsupported() 0 4 1
A noExtension() 0 4 1
A notExist() 0 4 1
A invalidSyntax() 0 4 2
A noFields() 0 4 1
1
<?php
2
3
namespace Dyrynda\Artisan\Exceptions;
4
5
use Exception;
6
7
class ImportFileException extends Exception
8
{
9
    /**
10
     * File type is unsupported.
11
     *
12
     * @param  string  $type
13
     * @return \Dyrynda\Artisan\Exceptions\ImportFileException
14
     */
15 1
    public static function unsupported($type)
16
    {
17 1
        return new static(strtoupper($type) . " is unsupported at this time");
18
    }
19
20
    /**
21
     * File has no extension
22
     *
23
     * @return \Dyrynda\Artisan\Exceptions\ImportFileException
24
     */
25 1
    public static function noExtension()
26
    {
27 1
        return new static("Filename must contain an extension (Example: import.csv, import.json)");
28
    }
29
30
    /**
31
     * File doesn't exist
32
     *
33
     * @param  string  $path
34
     * @return \Dyrynda\Artisan\Exceptions\ImportFileException
35
     */
36 1
    public static function notExist($path)
37
    {
38 1
        return new static("{$path} does not exist");
39
    }
40
41
    /**
42
     * File syntax is invalid
43
     *
44
     * @param  string  $filename
45
     * @param  string|null  $error
46
     * @return \Dyrynda\Artisan\Exceptions\ImportFileException
47
     */
48
    public static function invalidSyntax($filename, $error = null)
49
    {
50
        return new static("Errors detected in structure of {$filename}" . ($error ? ': ' . $error : ''));
51
    }
52
53
54
    /**
55
     * Unable to get the list of fields/columns from file
56
     *
57
     * @return \Dyrynda\Artisan\Exceptions\ImportFileException
58
     */
59
    public static function noFields()
60
    {
61
        return new static("Could not get a list of fields from the file");
62
    }
63
}
64