1 | <?php |
||
8 | class Content implements \Transphporm\Property { |
||
9 | private $contentPseudo = []; |
||
10 | private $formatter; |
||
11 | |||
12 | public function __construct(\Transphporm\Hook\Formatter $formatter) { |
||
13 | $this->formatter = $formatter; |
||
14 | } |
||
15 | |||
16 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
||
17 | if (!$this->shouldRun($element)) return false; |
||
18 | |||
19 | $values = $this->formatter->format($values, $rules); |
||
20 | |||
21 | if (!$this->processPseudo($values, $element, $pseudoMatcher)) { |
||
22 | //Remove the current contents |
||
23 | $this->removeAllChildren($element); |
||
24 | //Now make a text node |
||
25 | if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
||
26 | else $this->appendContent($element, $values); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | private function shouldRun($element) { |
||
37 | |||
38 | private function getContentMode($rules) { |
||
41 | |||
42 | public function addContentPseudo($name, ContentPseudo $contentPseudo) { |
||
43 | $this->contentPseudo[$name] = $contentPseudo; |
||
45 | |||
46 | private function processPseudo($value, $element, $pseudoMatcher) { |
||
55 | |||
56 | public function getNode($node, $document) { |
||
66 | |||
67 | private function convertNode($node, $document) { |
||
82 | |||
83 | |||
84 | private function replaceContent($element, $content) { |
||
99 | |||
100 | private function replaceCachedContent($element) { |
||
109 | |||
110 | // $doc->preserveWhiteSpace = false should fix this but it doesn't |
||
111 | // Remove extra whitespace created by removeChild to avoid the cache growing 1 byte every time it's reloaded |
||
112 | // This may need to be moved in future, anywhere elements are being removed and files are cached may need to apply this fix |
||
113 | private function fixPreserveWhitespacRemoveChild($element) { |
||
118 | |||
119 | private function appendContent($element, $content) { |
||
124 | |||
125 | private function removeAllChildren($element) { |
||
128 | } |
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.