NodeList   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 49
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A canHaveContent() 0 8 1
A element() 0 12 2
A getAttributes() 0 10 3
A parseArgs() 0 9 2
1
<?php
2
3
namespace arc\html;
4
5
class NodeList extends \ArrayObject {
6
    use \arc\xml\NodeListTrait {
7
        \arc\xml\NodeListTrait::parseArgs as traitParseArgs;
8
    }
9
10 2
    protected function canHaveContent( $tagName ) {
11
        $cantHaveContent = [
12 2
            'area', 'base', 'basefont', 'br',
13 1
            'col', 'frame', 'hr', 'img', 'input',
14 1
            'isindex', 'link', 'meta', 'param'
15 1
        ];
16 2
        return !in_array( trim( strtolower( $tagName ) ), $cantHaveContent );
17
    }
18
19 2
    protected function element( $tagName, $attributes, $content ) {
20 2
        $tagName =  \arc\html::name( $tagName );
21 2
        $el = '<' . $tagName;
22 2
        $el .= $this->getAttributes( $attributes );
23 2
        if ( $this->canHaveContent( $tagName ) ) {
24 2
            $el .= '>' . self::indent( $content, $this->writer->indent, $this->writer->newLine );
25 2
            $el .= '</' . $tagName . '>';
26 1
        } else {
27 2
            $el .= '>';
28
        }
29 2
        return $el;
30
    }
31
32 2
    protected function getAttributes( $attributes )
33
    {
34 2
        $result = '';
35 2
        if (count( $attributes )) {
36 2
            foreach ($attributes as $name => $value ) {
37 2
                $result .= \arc\html::attribute( $name, $value );
38 1
            }
39 1
        }
40 2
        return $result;
41
    }
42
43 2
    protected function parseArgs( $args ) {
44 2
        if ( is_string($args) ) {
45
            // allows for <input type="radio" checked>
46
            // as \arc\html::input(['type' => 'radio', 'checked']);
47 2
            return [ [ $args => $args ], '' ];
48
        } else {
49 2
            return $this->traitParseArgs($args);
50
        }
51
    }
52
53
}
54