Passed
Push — master ( e6ce91...429907 )
by MusikAnimal
04:46
created

XtoolsHttpException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 53
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isApi() 0 3 1
A __construct() 0 7 1
A getRedirectUrl() 0 3 1
A getParams() 0 3 1
1
<?php
2
/**
3
 * This file contains only the XtoolsHttpException class.
4
 */
5
6
namespace AppBundle\Exception;
7
8
/**
9
 * An XtoolsHttpException is used to show error messages based on user input and redirect back to a route.
10
 */
11
class XtoolsHttpException extends \RuntimeException
12
{
13
    /** @var string What URL to redirect to. */
14
    protected $redirectUrl;
15
16
    /** @var array The params to pass in with the URL. */
17
    protected $params;
18
19
    /** @var bool Whether the exception was thrown as part of an API request. */
20
    protected $api;
21
22
    /**
23
     * XtoolsHttpException constructor.
24
     * @param string $message
25
     * @param string $redirectUrl
26
     * @param array $params Params to pass in with the redirect URL.
27
     * @param bool $api Whether this is thrown during an API request.
28
     */
29
    public function __construct($message, $redirectUrl, $params = [], $api = false)
30
    {
31
        $this->redirectUrl = $redirectUrl;
32
        $this->params = $params;
33
        $this->api = $api;
34
35
        parent::__construct($message);
36
    }
37
38
    /**
39
     * The URL that should be redirected to.
40
     * @return string
41
     */
42
    public function getRedirectUrl()
43
    {
44
        return $this->redirectUrl;
45
    }
46
47
    /**
48
     * Get the configured parameters, which should be the same parameters parsed from the Request,
49
     * and passed to the $redirectUrl when handled in the ExceptionListener.
50
     * @return array
51
     */
52
    public function getParams()
53
    {
54
        return $this->params;
55
    }
56
57
    /**
58
     * Whether this exception was thrown as part of a request to the API.
59
     * @return bool
60
     */
61
    public function isApi()
62
    {
63
        return $this->api;
64
    }
65
}
66