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.

EmbeddedsFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A create() 0 19 3
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 Hateoas\Serializer\Metadata\RelationPropertyMetadata;
10
use JMS\Serializer\SerializationContext;
11
12
/**
13
 * @author Adrien Brault <[email protected]>
14
 */
15
class EmbeddedsFactory
16
{
17
    /**
18
     * @var RelationsRepository
19
     */
20
    private $relationsRepository;
21
22
    /**
23
     * @var ExpressionEvaluator
24
     */
25
    private $expressionEvaluator;
26
27
    /**
28
     * @var ExclusionManager
29
     */
30
    private $exclusionManager;
31
32
    /**
33
     * @param RelationsRepository $relationsRepository
34
     * @param ExpressionEvaluator $expressionEvaluator
35
     * @param ExclusionManager    $exclusionManager
36
     */
37
    public function __construct(
38
        RelationsRepository $relationsRepository,
39
        ExpressionEvaluator $expressionEvaluator,
40
        ExclusionManager $exclusionManager
41
    ) {
42
        $this->relationsRepository = $relationsRepository;
43
        $this->expressionEvaluator = $expressionEvaluator;
44
        $this->exclusionManager    = $exclusionManager;
45
    }
46
    /**
47
     * @param  object               $object
48
     * @param  SerializationContext $context
49
     * @return Embedded[]
50
     */
51
    public function create($object, SerializationContext $context)
52
    {
53
        $embeddeds = array();
54
        foreach ($this->relationsRepository->getRelations($object) as $relation) {
55
            if ($this->exclusionManager->shouldSkipEmbedded($object, $relation, $context)) {
56
                continue;
57
            }
58
59
            $rel  = $this->expressionEvaluator->evaluate($relation->getName(), $object);
60
            $data = $this->expressionEvaluator->evaluate($relation->getEmbedded()->getContent(), $object);
61
            $xmlElementName = $this->expressionEvaluator->evaluate($relation->getEmbedded()->getXmlElementName(), $object);
62
63
            $propertyMetadata = new RelationPropertyMetadata($relation->getEmbedded()->getExclusion(), $relation);
64
65
            $embeddeds[] = new Embedded($rel, $data, $propertyMetadata, $xmlElementName);
0 ignored issues
show
Bug introduced by
It seems like $rel defined by $this->expressionEvaluat...on->getName(), $object) on line 59 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...
Bug introduced by
It seems like $xmlElementName defined by $this->expressionEvaluat...ElementName(), $object) on line 61 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...
66
        }
67
68
        return $embeddeds;
69
    }
70
}
71