@@ -16,11 +16,12 @@
Loading
16 16
17 17
use Exception;
18 18
use Psr\Http\Message\ResponseInterface;
19 +
use UnexpectedValueException;
19 20
20 21
/**
21 22
 * Exception thrown if the parser cannot parse the provider response.
22 23
 */
23 -
class ResponseParsingException extends Exception
24 +
class ResponseParsingException extends UnexpectedValueException
24 25
{
25 26
    /**
26 27
     * @var ResponseInterface
@@ -37,12 +38,14 @@
Loading
37 38
     * @param string $responseBody The response body
38 39
     * @param null $message
39 40
     * @param int $code
41 +
     * @param Exception|null $previous
40 42
     */
41 43
    public function __construct(
42 44
        ResponseInterface $response,
43 45
        $responseBody,
44 46
        $message = null,
45 -
        $code = 0
47 +
        $code = 0,
48 +
        Exception $previous = null
46 49
    ) {
47 50
        $this->response = $response;
48 51
        $this->responseBody = $responseBody;
@@ -51,7 +54,7 @@
Loading
51 54
            $message = sprintf('Cannot parse response body: "%s"', $responseBody);
52 55
        }
53 56
54 -
        parent::__construct($message, $code);
57 +
        parent::__construct($message, $code, $previous);
55 58
    }
56 59
57 60
    /**

@@ -99,15 +99,6 @@
Loading
99 99
     */
100 100
    protected $optionProvider;
101 101
102 -
    /**
103 -
     * If a response body cannot be parsed, a value true of this flag will allow
104 -
     * the response parser to throw a ResponseParsingException containing
105 -
     * the response and the body.
106 -
     *
107 -
     * @var bool
108 -
     */
109 -
    protected $mayThrowResponseParsingException = false;
110 -
111 102
    /**
112 103
     * Constructs an OAuth 2.0 service provider.
113 104
     *
@@ -679,9 +670,7 @@
Loading
679 670
    /**
680 671
     * Parses the response according to its content-type header.
681 672
     *
682 -
     * @throws UnexpectedValueException
683 -
     * @throws ResponseParsingException if the flag $mayThrowResponseParsingException is true and
684 -
     *                                  response body cannot be parsed.
673 +
     * @throws ResponseParsingException if response body cannot be parsed.
685 674
     * @param  ResponseInterface $response
686 675
     * @return array|string
687 676
     */
@@ -702,26 +691,21 @@
Loading
702 691
            return $this->parseJson($content);
703 692
        } catch (UnexpectedValueException $e) {
704 693
            if (strpos($type, 'json') !== false) {
705 -
                throw $this->mayThrowResponseParsingException
706 -
                    ? new ResponseParsingException($response, $content, $e->getMessage(), $e->getCode())
707 -
                    : $e;
694 +
                throw new ResponseParsingException($response, $content, $e->getMessage(), $e->getCode(), $e);
708 695
            }
709 696
710 697
            // for any other content types
711 -
            if ($this->mayThrowResponseParsingException) {
712 -
                // let the calling function decide what to do with the response and its body
713 -
                throw new ResponseParsingException($response, $content, '', 0);
714 -
            } else {
715 -
                if ($response->getStatusCode() == 500) {
716 -
                    throw new UnexpectedValueException(
717 -
                        'An OAuth server error was encountered that did not contain a JSON body',
718 -
                        0,
719 -
                        $e
720 -
                    );
721 -
                }
722 -
723 -
                return $content;
698 +
            if ($response->getStatusCode() == 500) {
699 +
                throw new ResponseParsingException(
700 +
                    $response,
701 +
                    $content,
702 +
                    'An OAuth server error was encountered that did not contain a JSON body',
703 +
                    0,
704 +
                    $e
705 +
                );
724 706
            }
707 +
708 +
            return $content;
725 709
        }
726 710
    }
727 711
Files Complexity Coverage
src 184 100.00%
Project Totals (21 files) 184 100.00%
1
codecov:
2
  require_ci_to_pass: yes
3

4
coverage:
5
  precision: 2
6
  round: down
7
  range: "70...100"
8
  status:
9
    project:
10
      default:
11
        target: auto
12
        threshold: 0%
13
    patch:
14
      default:
15
        target: auto
16
        threshold: 0%
17

18
parsers:
19
  gcov:
20
    branch_detection:
21
      conditional: yes
22
      loop: yes
23
      method: no
24
      macro: no
25

26
comment:
27
  layout: "reach,diff,flags,tree"
28
  behavior: default
29
  require_changes: false
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading