Completed
Push — master ( 28450e...59b254 )
by Tom
01:40
created

BeforeAfter::after()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 2
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
		$this->{$this->insertLocation}($value, $element);
14
	}
15
16
	private function before($value, $element) {
17
		$currentFirst = $element->firstChild;
18
19
		foreach ($this->content->getNode($value, $element->ownerDocument) as $node) {
20
			$element->insertBefore($node, $currentFirst);
21
		}
22
	}
23
24
	private function after($value, $element) {
25
		foreach ($this->content->getNode($value, $element->ownerDocument) as $node) {
26
			$element->appendChild($node);
27
		}
28
	}
29
}
30