Completed
Push — master ( e186c7...3eddb7 )
by Josh
19:06
created

EnforceContentModels::generateBooleanRules()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
nc 8
nop 1
dl 0
loc 20
rs 9.2
c 1
b 0
f 0
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2016 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Configurator\RulesGenerators;
9
10
use s9e\TextFormatter\Configurator\Helpers\TemplateForensics;
11
use s9e\TextFormatter\Configurator\RulesGenerators\Interfaces\BooleanRulesGenerator;
12
use s9e\TextFormatter\Configurator\RulesGenerators\Interfaces\TargetedRulesGenerator;
13
14
class EnforceContentModels implements BooleanRulesGenerator, TargetedRulesGenerator
15
{
16
	/**
17
	* @var TemplateForensics
18
	*/
19
	protected $br;
20
21
	/**
22
	* Constructor
23
	*
24
	* Prepares the TemplateForensics for <br/>
25
	*/
26
	public function __construct()
27
	{
28
		$this->br = new TemplateForensics('<br/>');
29
	}
30
31
	/**
32
	* {@inheritdoc}
33
	*/
34
	public function generateBooleanRules(TemplateForensics $src)
35
	{
36
		$rules = [];
37
		if ($src->isTransparent())
38
		{
39
			$rules['isTransparent'] = true;
40
		}
41
		if (!$src->allowsChild($this->br))
42
		{
43
			$rules['preventLineBreaks'] = true;
44
			$rules['suspendAutoLineBreaks'] = true;
45
		}
46
		if (!$src->allowsDescendant($this->br))
47
		{
48
			$rules['disableAutoLineBreaks'] = true;
49
			$rules['preventLineBreaks'] = true;
50
		}
51
52
		return $rules;
53
	}
54
55
	/**
56
	* {@inheritdoc}
57
	*/
58
	public function generateTargetedRules(TemplateForensics $src, TemplateForensics $trg)
59
	{
60
		$rules = [];
61
		if (!$src->allowsChild($trg))
62
		{
63
			$rules[] = 'denyChild';
64
		}
65
		if (!$src->allowsDescendant($trg))
66
		{
67
			$rules[] = 'denyDescendant';
68
		}
69
70
		return $rules;
71
	}
72
}