Passed
Push — master ( 26ac52...beb008 )
by Josh
02:35
created

PHP80Functions::parseContains()   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 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php declare(strict_types=1);
2
3
/**
4
* @package   s9e\TextFormatter
5
* @copyright Copyright (c) 2010-2021 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 PHP80Functions extends AbstractConvertor
11
{
12
	/**
13
	* {@inheritdoc}
14
	*/
15 7
	public function getMatchers(): array
16
	{
17
		return [
18 7
			'Boolean:BooleanFunction:Contains'      => 'contains \\( ((?&String)) , ((?&String)) \\)',
19
			'Boolean:BooleanFunction:EndsWith'      => 'ends-with \\( ((?&String)) , ((?&String)) \\)',
20
			'Boolean:BooleanFunction:NotContains'   => 'not \\( contains \\( ((?&String)) , ((?&String)) \\) \\)',
21
			'Boolean:BooleanFunction:NotEndsWith'   => 'not \\( ends-with \\( ((?&String)) , ((?&String)) \\) \\)',
22
			'Boolean:BooleanFunction:NotStartsWith' => 'not \\( starts-with \\( ((?&String)) , ((?&String)) \\) \\)',
23
			'Boolean:BooleanFunction:StartsWith'    => 'starts-with \\( ((?&String)) , ((?&String)) \\)'
24
		];
25
	}
26
27
	/**
28
	* Convert a call to contains()
29
	*
30
	* @param  string $haystack Expression for the haystack part of the call
31
	* @param  string $needle   Expression for the needle part of the call
32
	* @return string
33
	*/
34 1
	public function parseContains(string $haystack, string $needle): string
35
	{
36 1
		return 'str_contains(' . $this->recurse($haystack) . ',' . $this->recurse($needle) . ')';
37
	}
38
39
	/**
40
	* Convert a call to ends-with()
41
	*
42
	* @param  string $string    Expression for the string part of the call
43
	* @param  string $substring Expression for the substring part of the call
44
	* @return string
45
	*/
46 2
	public function parseEndsWith(string $string, string $substring): string
47
	{
48 2
		return 'str_ends_with(' . $this->recurse($string) . ',' . $this->recurse($substring) . ')';
49
	}
50
51
	/**
52
	* Convert a call to not(contains())
53
	*
54
	* @param  string $haystack Expression for the haystack part of the call
55
	* @param  string $needle   Expression for the needle part of the call
56
	* @return string
57
	*/
58 1
	public function parseNotContains(string $haystack, string $needle): string
59
	{
60 1
		return '!str_contains(' . $this->recurse($haystack) . ',' . $this->recurse($needle) . ')';
61
	}
62
63
	/**
64
	* Convert a call to not(ends-with())
65
	*
66
	* @param  string $string    Expression for the string part of the call
67
	* @param  string $substring Expression for the substring part of the call
68
	* @return string
69
	*/
70 1
	public function parseNotEndsWith(string $string, string $substring): string
71
	{
72 1
		return '!str_ends_with(' . $this->recurse($string) . ',' . $this->recurse($substring) . ')';
73
	}
74
75
	/**
76
	* Convert a call to not(starts-with())
77
	*
78
	* @param  string $string    Expression for the string part of the call
79
	* @param  string $substring Expression for the substring part of the call
80
	* @return string
81
	*/
82 1
	public function parseNotStartsWith(string $string, string $substring): string
83
	{
84 1
		return '!str_starts_with(' . $this->recurse($string) . ',' . $this->recurse($substring) . ')';
85
	}
86
87
	/**
88
	* Convert a call to starts-with()
89
	*
90
	* @param  string $string    Expression for the string part of the call
91
	* @param  string $substring Expression for the substring part of the call
92
	* @return string
93
	*/
94 1
	public function parseStartsWith(string $string, string $substring): string
95
	{
96 1
		return 'str_starts_with(' . $this->recurse($string) . ',' . $this->recurse($substring) . ')';
97
	}
98
}