Completed
Push — master ( 27f709...a3e52e )
by Josh
03:54
created

BooleanOperators::getMatchers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 6
cp 1
rs 9.8333
c 0
b 0
f 0
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 BooleanOperators extends AbstractConvertor
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 80
	public function getMatchers(): array
16
	{
17
		// Create a boolean expression that can start a recursive pattern and a more complete
18
		// expression that can be used in the middle of a pattern
19 80
		$booleanExpr    = '((?&And)|(?&Boolean)|(?&Comparison)|(?&Or))';
20 80
		$booleanStarter = '((?&Boolean)|(?&Comparison))';
21
22
		return [
23 80
			'And'                    => $booleanStarter . ' and ' . $booleanExpr,
24 80
			'Boolean:BooleanSubExpr' => '\\( ' . $booleanExpr . ' \\)',
25 80
			'Or'                     => $booleanStarter . ' or ' . $booleanExpr
26
		];
27
	}
28
29
	/**
30
	* Convert a "and" operation
31
	*
32
	* @param  string $expr1
33
	* @param  string $expr2
34
	* @return string
35
	*/
36 3
	public function parseAnd($expr1, $expr2)
37
	{
38 3
		return $this->recurse($expr1) . '&&' . $this->recurse($expr2);
39
	}
40
41
	/**
42
	* Convert a boolean subexpression
43
	*
44
	* @param  string $expr
45
	* @return string
46
	*/
47 1
	public function parseBooleanSubExpr($expr)
48
	{
49 1
		return '(' . $this->recurse($expr) . ')';
50
	}
51
52
	/**
53
	* Convert a "or" operation
54
	*
55
	* @param  string $expr1
56
	* @param  string $expr2
57
	* @return string
58
	*/
59 2
	public function parseOr($expr1, $expr2)
60
	{
61 2
		return $this->recurse($expr1) . '||' . $this->recurse($expr2);
62
	}
63
}