Completed
Pull Request — master (#3)
by Auke
05:08 queued 03:36
created

NodeList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
ccs 16
cts 16
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canHaveContent() 0 8 1
A element() 0 12 2
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 2
    }
9
10 2
    protected function canHaveContent( $tagName ) {
11 2
        $cantHaveContent = [ 
12 2
            'area', 'base', 'basefont', 'br', 
13 2
            'col', 'frame', 'hr', 'img', 'input',
14 2
            'isindex', 'link', 'meta', 'param'
15
        ];
16
        return !in_array( trim( strtolower( $tagName ) ), $cantHaveContent );
17 2
    }
18 2
19 2
    protected function element( $tagName, $attributes, $content ) {
20 2
        $tagName =  $this->writer->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 1
            $el .= '</' . $tagName . '>';
26
        } else {
27 2
            $el .= '>';
28
        }
29
        return $el;
30
    }
31
32
    protected function parseArgs( $args ) {
33
        if ( is_string($args) ) {
34
            // allows for <input type="radio" checked>
35
            // as \arc\html::input(['type' => 'radio', 'checked']);
1 ignored issue
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
36
            return [ [ $args => $args ], '' ];
37
        } else {
38
            return $this->traitParseArgs($args);
39
        }
40
    }
41
42
}