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/EmbeddedsFactory.php (2 issues)

Labels
Severity

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\RelationsRepository;
6
use Hateoas\Expression\ExpressionEvaluator;
7
use Hateoas\Model\Embedded;
8
use Hateoas\Serializer\ExclusionManager;
9
use JMS\Serializer\SerializationContext;
10
11
/**
12
 * @author Adrien Brault <[email protected]>
13
 */
14
class EmbeddedsFactory
15
{
16
    /**
17
     * @var RelationsRepository
18
     */
19
    private $relationsRepository;
20
21
    /**
22
     * @var ExpressionEvaluator
23
     */
24
    private $expressionEvaluator;
25
26
    /**
27
     * @var ExclusionManager
28
     */
29
    private $exclusionManager;
30
31
    /**
32
     * @param RelationsRepository $relationsRepository
33
     * @param ExpressionEvaluator $expressionEvaluator
34
     * @param ExclusionManager    $exclusionManager
35
     */
36
    public function __construct(
37
        RelationsRepository $relationsRepository,
38
        ExpressionEvaluator $expressionEvaluator,
39
        ExclusionManager $exclusionManager
40
    ) {
41
        $this->relationsRepository = $relationsRepository;
42
        $this->expressionEvaluator = $expressionEvaluator;
43
        $this->exclusionManager    = $exclusionManager;
44
    }
45
    /**
46
     * @param  object               $object
47
     * @param  SerializationContext $context
48
     * @return Embedded[]
49
     */
50
    public function create($object, SerializationContext $context)
51
    {
52
        $embeddeds = array();
53
        foreach ($this->relationsRepository->getRelations($object) as $relation) {
54
            if ($this->exclusionManager->shouldSkipEmbedded($object, $relation, $context)) {
55
                continue;
56
            }
57
58
            $rel  = $this->expressionEvaluator->evaluate($relation->getName(), $object);
59
            $data = $this->expressionEvaluator->evaluate($relation->getEmbedded()->getContent(), $object);
60
            $xmlElementName = $this->expressionEvaluator->evaluate($relation->getEmbedded()->getXmlElementName(), $object);
61
62
            $embeddeds[] = new Embedded($rel, $data, $xmlElementName);
0 ignored issues
show
It seems like $rel defined by $this->expressionEvaluat...on->getName(), $object) on line 58 can also be of type array; however, Hateoas\Model\Embedded::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
It seems like $xmlElementName defined by $this->expressionEvaluat...ElementName(), $object) on line 60 can also be of type array; however, Hateoas\Model\Embedded::__construct() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
63
        }
64
65
        return $embeddeds;
66
    }
67
}
68