GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#30)
by Steven
04:46
created

Response::withPaginator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.372

Importance

Changes 4
Bugs 0 Features 3
Metric Value
c 4
b 0
f 3
dl 0
loc 16
ccs 3
cts 10
cp 0.3
rs 9.4285
cc 2
eloc 9
nc 2
nop 4
crap 3.372
1
<?php
2
3
namespace EllipseSynergie\ApiResponse\Laravel;
4
5
use EllipseSynergie\ApiResponse\AbstractResponse;
6
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
7
use Illuminate\Contracts\Routing\ResponseFactory;
8
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
9
use Illuminate\Contracts\Validation\Validator;
10
use League\Fractal\Resource\Collection;
11
12
/**
13
 * Class Response
14
 *
15
 * For the full copyright and license information, please view the LICENSE
16
 * file that was distributed with this source code.
17
 *
18
 * @package EllipseSynergie\ApiResponse\Laravel
19
 * @author Maxime Beaudoin <[email protected]>
20
 */
21
class Response extends AbstractResponse
22
{
23
    /**
24
     * @param array $array
25
     * @param array $headers
26
     * @return ResponseFactory
27
     */
28
    public function withArray(array $array, array $headers = [])
29
    {
30
        return response()->json($array, $this->statusCode, $headers);
31
    }
32
33
    /**
34
     * Respond with a paginator, and a transformer.
35
     *
36
     * @param LengthAwarePaginator $paginator
37
     * @param callable|\League\Fractal\TransformerAbstract $transformer
38
     * @param string $resourceKey
39
     * @param array $meta
40
     * @return ResponseFactory
41
     */
42 1
    public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = [])
0 ignored issues
show
Coding Style introduced by
withPaginator uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
43
    {
44 1
        $queryParams = array_diff_key($_GET, array_flip(['page']));
45 1
        $paginator->appends($queryParams);
46
        
47
        $resource = new Collection($paginator->items(), $transformer, $resourceKey);
48
        $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
49
50
        foreach ($meta as $metaKey => $metaValue) {
51
            $resource->setMetaValue($metaKey, $metaValue);
52
        }
53
54
        $rootScope = $this->manager->createData($resource);
55
56
        return $this->withArray($rootScope->toArray());
57
    }
58
59
    /**
60
     * Generates a Response with a 400 HTTP header and a given message from validator
61
     *
62
     * @param Validator $validator
63
     * @return ResponseFactory
64
     */
65 1
    public function errorWrongArgsValidator(Validator $validator)
66
    {
67 1
        return $this->errorWrongArgs($validator->getMessageBag()->toArray());
68
    }
69
}
70