Completed
Push — master ( 883013...4a27e9 )
by Babak
03:04
created

SmartResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 25
rs 10
c 1
b 1
f 0
wmc 4
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: Alive...
6
 * Date: 8/23/17
7
 * Time: 6:46 AM
8
 */
9
10
namespace Alive2212\LaravelSmartResponse\SmartResponse;
11
12
use Alive2212\LaravelSmartResponse\ResponseModel;
13
14
class SmartResponse
15
{
16
    /**
17
     * @param ResponseModel $response
18
     * @return \Illuminate\Http\JsonResponse
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\JsonResponse 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
     */
20
    public static function response(ResponseModel $response)
21
    {
22
        $header = array(
23
            'Content-Type' => 'application/json; charset=UTF-8',
24
            'charset' => 'utf-8'
25
        );
26
        if (!is_null($response->getError())) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $response->getError() targeting Alive2212\LaravelSmartRe...sponseModel::getError() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
introduced by
The condition is_null($response->getError()) is always true.
Loading history...
27
            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

27
            return /** @scrutinizer ignore-call */ response()->json([
Loading history...
28
                'status' => $response->getStatus(),
29
                'data' => $response->getData()->count() ? $response->getData() : null,
30
                'message' => $response->getMessage(),
31
                'error_code' => $response->getError(),
32
            ], $response->getstatusCode(), $header, JSON_UNESCAPED_UNICODE);
33
        } else {
34
            return response()->json([
35
                'status' => $response->getStatus(),
36
                'data' => $response->getData()->count() ? $response->getData() : null,
37
                'message' => $response->getMessage(),
38
            ], $response->getStatusCode(), $header, JSON_UNESCAPED_UNICODE);
39
        }
40
    }
41
}
42
43