Completed
Push — SOLID ( b14133...a3f21e )
by Wouter
02:08
created

JsonToHtml   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toHtml() 0 14 2
1
<?php
2
3
namespace Sioen;
4
5
/**
6
 * Class JsonToHtml
7
 *
8
 * Converts a json object received from Sir Trevor to an html representation
9
 *
10
 * @version 1.1.0
11
 * @author Wouter Sioen <[email protected]>
12
 * @license http://www.opensource.org/licenses/mit-license.php MIT
13
 */
14
class JsonToHtml
15
{
16
    /**
17
     * Converts the outputted json from Sir Trevor to html
18
     *
19
     * @param  string $json
20
     * @return string
21
     */
22
    public function toHtml($json)
23
    {
24
        // convert the json to an associative array
25
        $input = json_decode($json, true);
26
        $html = '';
27
28
        // loop trough the data blocks
29
        foreach ($input['data'] as $block) {
30
            $toHtmlContext = new ToHtmlContext($block['type']);
31
            $html .= $toHtmlContext->getHtml($block['data']);
32
        }
33
34
        return $html;
35
    }
36
}
37