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
Push — master ( 1978d2...e2f699 )
by William
03:55
created

src/Hateoas/Factory/LinkFactory.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Hateoas\Factory;
4
5
use Hateoas\Configuration\Relation;
6
use Hateoas\Configuration\Route;
7
use Hateoas\Expression\ExpressionEvaluator;
8
use Hateoas\Model\Link;
9
use Hateoas\UrlGenerator\UrlGeneratorRegistry;
10
11
/**
12
 * @author Adrien Brault <[email protected]>
13
 */
14
class LinkFactory
15
{
16
    /**
17
     * @var ExpressionEvaluator
18
     */
19
    private $expressionEvaluator;
20
21
    /**
22
     * @var UrlGeneratorRegistry
23
     */
24
    private $urlGeneratorRegistry;
25
26
    /**
27
     * @param ExpressionEvaluator  $expressionEvaluator
28
     * @param UrlGeneratorRegistry $urlGeneratorRegistry
29
     */
30
    public function __construct(ExpressionEvaluator $expressionEvaluator, UrlGeneratorRegistry $urlGeneratorRegistry)
31
    {
32
        $this->expressionEvaluator  = $expressionEvaluator;
33
        $this->urlGeneratorRegistry = $urlGeneratorRegistry;
34
    }
35
36
    /**
37
     * @param object   $object
38
     * @param Relation $relation
39
     *
40
     * @return Link
41
     */
42
    public function createLink($object, Relation $relation)
43
    {
44
        $rel =  $this->expressionEvaluator->evaluate($relation->getName(), $object);
45
        $href = $relation->getHref();
46
47
        if ($href instanceof Route) {
48
            if (!$this->urlGeneratorRegistry->hasGenerators()) {
49
                throw new \RuntimeException('You cannot use a route without an url generator.');
50
            }
51
52
            $name       = $this->expressionEvaluator->evaluate($href->getName(), $object);
53
            $parameters = is_array($href->getParameters())
54
                ? $this->expressionEvaluator->evaluateArray($href->getParameters(), $object)
55
                : $this->expressionEvaluator->evaluate($href->getParameters(), $object)
56
            ;
57
            $isAbsolute = $this->expressionEvaluator->evaluate($href->isAbsolute(), $object);
0 ignored issues
show
$href->isAbsolute() is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
59
            if (!is_array($parameters)) {
60
                throw new \RuntimeException(
61
                    sprintf(
62
                        'The route parameters should be an array, %s given. Maybe you forgot to wrap the expression in expr(...).',
63
                        gettype($parameters)
64
                    )
65
                );
66
            }
67
68
            $href = $this->urlGeneratorRegistry
69
                ->get($href->getGenerator())
70
                ->generate($name, $parameters, $isAbsolute)
0 ignored issues
show
$isAbsolute is of type array|string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
            ;
72
        } else {
73
            $href = $this->expressionEvaluator->evaluate($href, $object);
74
        }
75
76
        $attributes = $this->expressionEvaluator->evaluateArray($relation->getAttributes(), $object);
77
78
        return new Link($rel, $href, $attributes);
79
    }
80
}
81