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

NodeList::parseArgs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 0
cp 0
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
crap 6
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
}