Passed
Pull Request — master (#408)
by
unknown
03:35
created

CronException::taskExecutionFailed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
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 3.0.0
13
 */
14
15
namespace Quantum\Libraries\Cron\Exceptions;
16
17
use Quantum\Libraries\Cron\Enums\ExceptionMessages;
18
19
/**
20
 * Class CronException
21
 * @package Quantum\Libraries\Cron
22
 */
23
class CronException extends \Exception
24
{
25
    /**
26
     * Task not found exception
27
     * @param string $taskName
28
     * @return CronException
29
     */
30
    public static function taskNotFound(string $taskName): CronException
31
    {
32
        return new self(sprintf(ExceptionMessages::TASK_NOT_FOUND, $taskName));
33
    }
34
35
    /**
36
     * Invalid cron expression exception
37
     * @param string $expression
38
     * @return CronException
39
     */
40
    public static function invalidExpression(string $expression): CronException
41
    {
42
        return new self(sprintf(ExceptionMessages::INVALID_EXPRESSION, $expression));
43
    }
44
45
    /**
46
     * Lock acquire failed exception
47
     * @param string $taskName
48
     * @return CronException
49
     */
50
    public static function lockAcquireFailed(string $taskName): CronException
51
    {
52
        return new self(sprintf(ExceptionMessages::LOCK_ACQUIRE_FAILED, $taskName));
53
    }
54
55
    /**
56
     * Task execution failed exception
57
     * @param string $taskName
58
     * @param string $error
59
     * @return CronException
60
     */
61
    public static function taskExecutionFailed(string $taskName, string $error): CronException
62
    {
63
        return new self(sprintf(ExceptionMessages::TASK_EXECUTION_FAILED, $taskName, $error));
64
    }
65
66
    /**
67
     * Invalid task file exception
68
     * @param string $file
69
     * @return CronException
70
     */
71
    public static function invalidTaskFile(string $file): CronException
72
    {
73
        return new self(sprintf(ExceptionMessages::INVALID_TASK_FILE, $file));
74
    }
75
76
    /**
77
     * Cron directory not found exception
78
     * @param string $directory
79
     * @return CronException
80
     */
81
    public static function cronDirectoryNotFound(string $directory): CronException
82
    {
83
        return new self(sprintf(ExceptionMessages::CRON_DIRECTORY_NOT_FOUND, $directory));
84
    }
85
86
    /**
87
     * Lock directory not writable exception
88
     * @param string $directory
89
     * @return CronException
90
     */
91
    public static function lockDirectoryNotWritable(string $directory): CronException
92
    {
93
        return new self(sprintf(ExceptionMessages::LOCK_DIRECTORY_NOT_WRITABLE, $directory));
94
    }
95
}
96