DelegatesController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 25
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the EasyWeChatComposer.
7
 *
8
 * (c) 张铭阳 <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace EasyWeChatComposer\Laravel\Http\Controllers;
15
16
use EasyWeChatComposer\Delegation\Hydrate;
17
use EasyWeChatComposer\Encryption\DefaultEncrypter;
18
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Throwable;
20
21
class DelegatesController
22
{
23
    /**
24
     * @param \Illuminate\Http\Request                        $request
25
     * @param \EasyWeChatComposer\Encryption\DefaultEncrypter $encrypter
26
     *
27
     * @return \Illuminate\Http\Response
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
     */
29
    public function __invoke(Request $request, DefaultEncrypter $encrypter)
30
    {
31
        try {
32
            $data = json_decode($encrypter->decrypt($request->get('encrypted')), true);
33
34
            $hydrate = new Hydrate($data);
35
36
            $response = $hydrate->handle();
37
38
            return response()->json([
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
            return /** @scrutinizer ignore-call */ response()->json([
Loading history...
39
                'response_type' => get_class($response),
0 ignored issues
show
Bug introduced by
$response of type array is incompatible with the type object expected by parameter $object of get_class(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
                'response_type' => get_class(/** @scrutinizer ignore-type */ $response),
Loading history...
40
                'response' => $encrypter->encrypt($response->getBodyContents()),
41
            ]);
42
        } catch (Throwable $t) {
43
            return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('exception'...e' => $t->getMessage()) returns the type array<string,string> which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
44
                'exception' => get_class($t),
45
                'message' => $t->getMessage(),
46
            ];
47
        }
48
    }
49
}
50