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.

XmlPresenter::writeXml()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 9
nc 4
nop 2
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 8/03/16
5
 * Time: 22:55.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Api\Problem\Presenter;
12
13
/**
14
 * Class XmlPresenter.
15
 */
16
class XmlPresenter extends BasePresenter implements Presenter
17
{
18
    /**
19
     * @return string
20
     */
21
    public function format()
22
    {
23
        return 'xml';
24
    }
25
26
    /**
27
     * @return string
28
     *
29
     * @throws \Exception
30
     */
31
    public function contents()
32
    {
33
        $rows = $this->buildContent();
34
        $lines = [];
35
        $flattenedLines = $this->writeXml($rows, $lines);
36
37
        return <<<XML
38
<?xml version="1.0" encoding="UTF-8"?>
39
<problem xmlns="urn:ietf:rfc:7807">
40
$flattenedLines
41
</problem>
42
XML;
43
    }
44
45
    /**
46
     * @param array $rows
47
     * @param array $lines
48
     *
49
     * @return string
50
     */
51
    protected function writeXml(array $rows, array $lines = [])
52
    {
53
        foreach ($rows as $key => $value) {
54
            if (\is_array($value)) {
55
                if (\is_numeric($key)) {
56
                    $key = 'item';
57
                }
58
                $lines[] = sprintf("<%s>\n%s\n</%s>", $key, $this->writeXml($value), $key);
59
            } else {
60
                $lines[] = sprintf('<%s>%s</%s>', $key, $value, $key);
61
            }
62
        }
63
64
        return implode(PHP_EOL, $lines);
65
    }
66
}
67