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

Fractal::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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