Completed
Pull Request — master (#69)
by
unknown
01:51
created

Fractal   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A respond() 0 16 3
1
<?php
2
3
namespace Spatie\Fractal;
4
5
use League\Fractal\Manager;
6
use Illuminate\Http\JsonResponse;
7
use Spatie\Fractalistic\Fractal as Fractalistic;
8
9
class Fractal extends Fractalistic
10
{
11
    /** @var \Spatie\Fractal\Response */
12
    protected $response;
13
14
    /** @param \League\Fractal\Manager $manager */
15
    public function __construct(Manager $manager)
16
    {
17
        parent::__construct($manager);
18
19
        $this->response = new Response;
20
    }
21
22
    /**
23
     * Return a new JSON response.
24
     *
25
     * @param  callable|int $callbackOrStatusCode
26
     * @param  array        $headers
0 ignored issues
show
Documentation introduced by
There is no parameter named $headers. Did you maybe mean $callbackOrHeaders?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
27
     *
28
     * @return \Illuminate\Http\JsonResponse
29
     */
30
    public function respond($callbackOrStatusCode = 200, $callbackOrHeaders = [])
31
    {
32
        if (is_callable($callbackOrStatusCode)) {
33
            $callbackOrStatusCode($this->response);
34
        } else {
35
            $this->response->code($callbackOrStatusCode);
36
37
            if (is_callable($callbackOrHeaders)) {
38
                $callbackOrHeaders($this->response);
39
            } else {
40
                $this->response->headers($callbackOrHeaders);
41
            }
42
        }
43
44
        return new JsonResponse($this->createData()->toArray(), $this->response->statusCode(), $this->response->getHeaders());
45
    }
46
}
47