Completed
Push — master ( d03bbd...580028 )
by Charles
43:02
created

Json25519Parser::parse()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.2
cc 4
eloc 10
nc 1
nop 2
1
<?php
2
3
namespace yrc\components;
4
5
use yii\helpers\Json;
6
use yii\web\JsonParser;
7
use Yii;
8
9
class Json25519Parser extends JsonParser
10
{
11
    /**
12
     * Parses a HTTP request body.
13
     * @param string $rawBody the raw HTTP request body.
14
     * @param string $contentType the content type specified for the request body.
15
     * @return array parameters parsed from the request body
16
     * @throws BadRequestHttpException if the body contains invalid json and [[throwException]] is `true`.
17
     */
18
    public function parse($rawBody, $contentType)
19
    {
20
        var_dump($contentType);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($contentType); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
21
        die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method parse() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
22
        try {
0 ignored issues
show
Unused Code introduced by
try { $parameters = ...} return array(); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
23
            $parameters = Json::decode($rawBody, $this->asArray);
24
            return $parameters === null ? [] : $parameters;
25
        } catch (InvalidParamException $e) {
0 ignored issues
show
Bug introduced by
The class yrc\components\InvalidParamException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
26
            if ($this->throwException) {
27
                throw new BadRequestHttpException('Invalid JSON data in request body: ' . $e->getMessage());
28
            }
29
            return [];
30
        }
31
    }
32
}