Completed
Push — master ( 2083da...14d866 )
by Babak
02:01
created

SmartResponse::message()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 17
nc 2
nop 1
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alive
5
 * Date: 8/23/17
6
 * Time: 6:46 AM
7
 */
8
9
namespace Alive2212\LaravelSmartResponse;
10
11
use App\Resources\Event\EventHandler;
0 ignored issues
show
Bug introduced by
The type App\Resources\Event\EventHandler 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...
12
use App\Resources\Model\ResponseModel;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Alive2212\LaravelSmartResponse\ResponseModel. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
Bug introduced by
The type App\Resources\Model\ResponseModel 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...
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())) {
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