Completed
Pull Request — master (#3)
by Luca
01:52
created

DownloadException::downloadError()   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
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Jackal\Downloader\Exception;
4
5
class DownloadException extends \Exception
6
{
7
    /**
8
     * @param string $tempFile
9
     * @return DownloadException
10
     */
11
    public static function tempFileAlreadyExists(string $tempFile) : DownloadException
12
    {
13
        return new DownloadException(sprintf('Temp file "%s" already exists, use force to overwrite', $tempFile));
14
    }
15
16
    /**
17
     * @param string $name
18
     * @return DownloadException
19
     */
20
    public static function alreadyRegistered(string $name) : DownloadException
21
    {
22
        return new DownloadException(sprintf('Downloader with name "%s" is already registered', $name));
23
    }
24
25
    /**
26
     * @param string $destinationFile
27
     * @return DownloadException
28
     */
29
    public static function destinationFileAlreadyExists(string $destinationFile) : DownloadException
30
    {
31
        return new DownloadException(sprintf('Output file "%s" already exists. Use option `overwrite` to force', $destinationFile));
32
    }
33
34
    /**
35
     * @param string $folder
36
     * @return DownloadException
37
     */
38
    public static function cannotCreateDirectory(string $folder) : DownloadException
39
    {
40
        return new DownloadException('Unable to create directory ' . $folder);
41
    }
42
43
    /**
44
     * @param string $message
45
     * @return DownloadException
46
     */
47
    public static function downloadError(string $message) : DownloadException
48
    {
49
        return new DownloadException($message);
50
    }
51
52
    /**
53
     * @param array $selectedFormats
54
     * @param array $available
55
     * @return DownloadException
56
     */
57
    public static function formatNotFound(array $selectedFormats, array $available) : DownloadException
58
    {
59
        return new DownloadException(sprintf(
60
            'Format%s %s is not available. [Available formats are: %s]',
61
            count($selectedFormats) == 1 ? '' : 's',
62
            implode(', ', $selectedFormats),
63
            implode(', ', array_keys($available))
64
        ));
65
    }
66
}
67