createUnauthorizedException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/*
3
 * This file is part of the FreshCommonApiBundle
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\CommonApiBundle\Helper;
14
15
use Fresh\CommonApiBundle\Exception\ServerInternalErrorException;
16
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
17
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
18
19
/**
20
 * ExceptionHelperTrait.
21
 *
22
 * @author Artem Henvald <[email protected]>
23
 */
24
trait ExceptionHelperTrait
25
{
26
    /**
27
     * @param string          $message
28
     * @param \Exception|null $previous
29
     *
30
     * @return BadRequestHttpException
31
     */
32
    protected function createBadRequestException(string $message = 'Wrong Request', ?\Exception $previous = null): BadRequestHttpException
33
    {
34
        return new BadRequestHttpException($message, $previous);
35
    }
36
37
    /**
38
     * @param string          $message
39
     * @param \Exception|null $previous
40
     *
41
     * @return UnauthorizedHttpException
42
     */
43
    protected function createUnauthorizedException(string $message = 'Invalid Credentials', ?\Exception $previous = null): UnauthorizedHttpException
44
    {
45
        return new UnauthorizedHttpException('Basic realm="My Realm"', $message, $previous);
46
    }
47
48
    /**
49
     * @param string          $message
50
     * @param \Exception|null $previous
51
     *
52
     * @return ServerInternalErrorException
53
     */
54
    protected function createInternalServerErrorException(string $message = 'Internal Server Error', ?\Exception $previous = null): ServerInternalErrorException
55
    {
56
        return new ServerInternalErrorException($message, $previous);
57
    }
58
}
59