Completed
Push — master ( 1bd818...6fba0f )
by Richard
02:31
created

BeforeAfter::run()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.2
c 0
b 0
f 0
cc 4
eloc 4
nc 4
nop 3
1
<?php
2
namespace Transphporm\Property\ContentPseudo;
3
class BeforeAfter implements \Transphporm\Property\ContentPseudo {
4
    private $insertLocation;
5
    private $content;
6
7
    public function __construct($insertLocation, \Transphporm\Property\Content $content) {
8
        $this->insertLocation = $insertLocation;
9
		$this->content = $content;
10
	}
11
12
    public function run($value, $pseudoArgs, $element) {
13
        foreach ($this->content->getNode($value, $element->ownerDocument) as $node) {
14
			if ($this->insertLocation === "before") $element->insertBefore($node, $element->firstChild);
15
            else if ($this->insertLocation === "after") $element->appendChild($node);
16
		}
17
    }
18
}
19