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

BeforeAfter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 3 1
A before() 0 7 2
A after() 0 5 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