Passed
Push — main ( e3d1bb...64bec1 )
by
unknown
31:25 queued 12s
created

ArrayFormatter::parse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace BlitzPHP\Formatter;
13
14
/**
15
 * Formateur de données en tableau
16
 */
17
class ArrayFormatter implements FormatterInterface
18
{
19
    /**
20
     * Prend les données fournies et les formate.
21
     *
22
     * @param mixed $data
23
     *
24
     * @return array Données formatées sous forme de tableau ; sinon, un tableau vide
25
     */
26
    public function format($data)
27
    {
28
        if (! is_array($data)) {
29 2
            $data = (array) $data;
30
        }
31
32 2
        $array = [];
33
34
        foreach ($data as $key => $value) {
35 2
            $array[$key] = is_object($value) || is_array($value) ? $this->format($value) : $value;
36
        }
37
38 2
        return $array;
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function parse(string $data): array
45
    {
46 2
        return [$data];
47
    }
48
}
49