Completed
Push — master ( 510176...179035 )
by Josh
04:14
created

BooleanFunctions::parseFalse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2019 The s9e Authors
6
* @license   http://www.opensource.org/licenses/mit-license.php The MIT License
7
*/
8
namespace s9e\TextFormatter\Configurator\RendererGenerators\PHP\XPathConvertor\Convertors;
9
10
class BooleanFunctions extends AbstractConvertor
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 8
	public function getMatchers(): array
16
	{
17
		return [
18 8
			'Boolean:BooleanParam'  => 'boolean \\( ((?&Parameter)) \\)',
19
			'Boolean:False'         => 'false \\( \\)',
20
			'Boolean:HasAttribute'  => 'boolean \\( ((?&Attribute)) \\)',
21
			'Boolean:HasAttributes' => 'boolean \\( @\\* \\)',
22
			'Boolean:Not'           => [
23
				// Only try matching generic not() invocations after special cases fail
24
				'order'  => 100,
25
				'regexp' => 'not \\( ((?&Boolean)|(?&Comparison)|(?&And)|(?&Or)) \\)'
26
			],
27
			'Boolean:NotAttribute'  => 'not \\( ((?&Attribute)) \\)',
28
			'Boolean:NotParam'      => 'not \\( ((?&Parameter)) \\)',
29
			'Boolean:True'          => 'true \\( \\)'
30
		];
31
	}
32
33
	/**
34
	* Convert a call to boolean() with a param
35
	*
36
	* @param  string $expr
37
	* @return string
38
	*/
39 1
	public function parseBooleanParam($expr)
40
	{
41 1
		return $this->recurse($expr) . "!==''";
42
	}
43
44
	/**
45
	* Convert a call to false()
46
	*
47
	* @param  string $expr
48
	* @return string
49
	*/
50 1
	public function parseFalse()
51
	{
52 1
		return 'false';
53
	}
54
55
	/**
56
	* Convert a call to boolean() with an attribute
57
	*
58
	* @param  string $expr
59
	* @return string
60
	*/
61 1
	public function parseHasAttribute($expr)
62
	{
63 1
		$attrName = $this->getAttributeName($expr);
64
65 1
		return '$node->hasAttribute(' . var_export($attrName, true) . ')';
66
	}
67
68
	/**
69
	* Convert a call to boolean(@*)
70
	*
71
	* @return string
72
	*/
73 1
	public function parseHasAttributes()
74
	{
75 1
		return '$node->attributes->length';
76
	}
77
78
	/**
79
	* Convert a call to not() with a boolean expression
80
	*
81
	* @param  string $expr
82
	* @return string
83
	*/
84 1
	public function parseNot($expr)
85
	{
86 1
		return '!(' . $this->recurse($expr) . ')';
87
	}
88
89
	/**
90
	* Convert a call to not() with an attribute
91
	*
92
	* @param  string $expr
93
	* @return string
94
	*/
95 1
	public function parseNotAttribute($expr)
96
	{
97 1
		$attrName = $this->getAttributeName($expr);
98
99 1
		return '!$node->hasAttribute(' . var_export($attrName, true) . ')';
100
	}
101
102
	/**
103
	* Convert a call to not() with a param
104
	*
105
	* @param  string $expr
106
	* @return string
107
	*/
108 1
	public function parseNotParam($expr)
109
	{
110 1
		return $this->recurse($expr) . "===''";
111
	}
112
113
	/**
114
	* Convert a call to true()
115
	*
116
	* @return string
117
	*/
118 1
	public function parseTrue()
119
	{
120 1
		return 'true';
121
	}
122
}