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.

Response   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 50
c 0
b 0
f 0
wmc 4
lcom 1
cbo 8
ccs 12
cts 14
cp 0.8571
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A withArray() 0 4 1
A withPaginator() 0 16 2
A errorWrongArgsValidator() 0 4 1
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
     * @param int $json_options @link http://php.net/manual/en/function.json-encode.php
27
     * @return ResponseFactory
28
     */
29
    public function withArray(array $array, array $headers = [], $json_options = 0)
30
    {
31
        return response()->json($array, $this->statusCode, $headers, $json_options);
32
    }
33
34
    /**
35
     * Respond with a paginator, and a transformer.
36
     *
37
     * @param LengthAwarePaginator $paginator
38
     * @param callable|\League\Fractal\TransformerAbstract $transformer
39
     * @param string $resourceKey
40
     * @param array $meta
41
     * @return ResponseFactory
42
     */
43 1
    public function withPaginator(LengthAwarePaginator $paginator, $transformer, $resourceKey = null, $meta = [])
44
    {
45 1
        $queryParams = array_diff_key($_GET, array_flip(['page']));
46 1
        $paginator->appends($queryParams);
47
        
48 1
        $resource = new Collection($paginator->items(), $transformer, $resourceKey);
49 1
        $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
50
51 1
        foreach ($meta as $metaKey => $metaValue) {
52 1
            $resource->setMetaValue($metaKey, $metaValue);
53 1
        }
54
55 1
        $rootScope = $this->manager->createData($resource);
56
57 1
        return $this->withArray($rootScope->toArray());
0 ignored issues
show
Bug introduced by
It seems like $rootScope->toArray() targeting League\Fractal\Scope::toArray() can also be of type null; however, EllipseSynergie\ApiRespo...l\Response::withArray() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
58
    }
59
60
    /**
61
     * Generates a Response with a 400 HTTP header and a given message from validator
62
     *
63
     * @param Validator $validator
64
     * @return ResponseFactory
65
     */
66 1
    public function errorWrongArgsValidator(Validator $validator)
67
    {
68 1
        return $this->errorWrongArgs($validator->getMessageBag()->toArray());
69
    }
70
}
71