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 (#246)
by Asmir
02:26
created

XmlHalSerializer::acceptDataAndAppend()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 4
1
<?php
2
3
namespace Hateoas\Serializer;
4
5
use Hateoas\Model\Embedded;
6
use Hateoas\Representation\Resource;
7
use JMS\Serializer\SerializationContext;
8
use JMS\Serializer\XmlSerializationVisitor;
9
10
/**
11
 * @author Adrien Brault <[email protected]>
12
 */
13
class XmlHalSerializer implements XmlSerializerInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function serializeLinks(array $links, XmlSerializationVisitor $visitor, SerializationContext $context)
19
    {
20
        foreach ($links as $link) {
21
            if ('self' === $link->getRel()) {
22
                foreach ($link->getAttributes() as $key => $value) {
23
                    $visitor->getCurrentNode()->setAttribute($key, $value);
24
                }
25
26
                $visitor->getCurrentNode()->setAttribute('href', $link->getHref());
27
28
                continue;
29
            }
30
31
            $linkNode = $visitor->getDocument()->createElement('link');
32
            $visitor->getCurrentNode()->appendChild($linkNode);
33
34
            $linkNode->setAttribute('rel', $link->getRel());
35
            $linkNode->setAttribute('href', $link->getHref());
36
37
            foreach ($link->getAttributes() as $attributeName => $attributeValue) {
38
                $linkNode->setAttribute($attributeName, $attributeValue);
39
            }
40
        }
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function serializeEmbeddeds(array $embeddeds, XmlSerializationVisitor $visitor, SerializationContext $context)
47
    {
48
        foreach ($embeddeds as $embedded) {
49
            if ($embedded->getData() instanceof \Traversable || is_array($embedded->getData())) {
50 View Code Duplication
                foreach ($embedded->getData() as $data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
                    $entryNode = $visitor->getDocument()->createElement('resource');
52
53
                    $visitor->getCurrentNode()->appendChild($entryNode);
54
                    $visitor->setCurrentNode($entryNode);
55
                    $visitor->getCurrentNode()->setAttribute('rel', $embedded->getRel());
56
57
                    $this->acceptDataAndAppend($embedded, $data, $visitor, $context);
58
59
                    $visitor->revertCurrentNode();
60
                }
61
62
                continue;
63
            }
64
65
            $entryNode = $visitor->getDocument()->createElement('resource');
66
67
            $visitor->getCurrentNode()->appendChild($entryNode);
68
            $visitor->setCurrentNode($entryNode);
69
            $visitor->getCurrentNode()->setAttribute('rel', $embedded->getRel());
70
71
            $this->acceptDataAndAppend($embedded, $embedded->getData(), $visitor, $context);
72
73
            $visitor->revertCurrentNode();
74
        }
75
    }
76
77 View Code Duplication
    private function acceptDataAndAppend(Embedded $embedded, $data, XmlSerializationVisitor $visitor, SerializationContext $context)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $context->pushPropertyMetadata($embedded->getMetadata());
80
81
        if (null !== $node = $context->accept($data)) {
82
            $visitor->getCurrentNode()->appendChild($node);
83
        }
84
        $context->popPropertyMetadata();
85
    }
86
}
87