Completed
Pull Request — master (#91)
by Timothée
07:01
created

RequestServerErrorVoter::shouldCatchThrowable()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 8
rs 9.2
cc 4
eloc 5
nc 4
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Tolerance package.
5
 *
6
 * (c) Samuel ROZE <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tolerance\Bridge\PhpHttp;
13
14
use Psr\Http\Message\ResponseInterface;
15
use Tolerance\Operation\Exception\PromiseException;
16
use Tolerance\Operation\ExceptionCatcher\ThrowableCatcherVoter;
17
18 View Code Duplication
final class RequestServerErrorVoter implements ThrowableCatcherVoter
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function shouldCatch(\Exception $e)
24
    {
25
        return $this->shouldCatchThrowable($e);
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function shouldCatchThrowable($throwable)
32
    {
33
        return !$throwable instanceof PromiseException
34
            || $throwable->isRejected()
35
            || !$throwable->getValue() instanceof ResponseInterface
36
            || $throwable->getValue()->getStatusCode() >= 500
37
        ;
38
    }
39
}
40