Total Complexity | 18 |
Total Lines | 77 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
17 | trait ConsecutivePunctuationCharacterTrait |
||
18 | { |
||
19 | |||
20 | /** |
||
1 ignored issue
–
show
|
|||
21 | * @var array |
||
22 | */ |
||
23 | private $childrenPrefixes = []; |
||
24 | |||
25 | /** |
||
1 ignored issue
–
show
|
|||
26 | * @var array |
||
27 | */ |
||
28 | private $childrenSuffixes = []; |
||
29 | |||
30 | /** |
||
1 ignored issue
–
show
|
|||
31 | * @var array |
||
32 | */ |
||
33 | private $childrenDelimiter = []; |
||
34 | |||
35 | /** |
||
1 ignored issue
–
show
|
|||
36 | * @param $punctuationSign |
||
1 ignored issue
–
show
|
|||
37 | * @param $subject |
||
1 ignored issue
–
show
|
|||
38 | * @return string |
||
1 ignored issue
–
show
|
|||
39 | */ |
||
40 | 92 | public function removeConsecutivePunctuation($punctuationSign, $subject) |
|
41 | { |
||
42 | 92 | if (empty($punctuationSign) || preg_match("/^\s+$/", $punctuationSign)) { |
|
43 | 14 | return $subject; |
|
44 | } |
||
45 | 91 | $pattern = '/' . preg_quote(trim($punctuationSign)) . '{2,}/'; |
|
46 | 91 | if (preg_match($pattern, $subject)) { |
|
47 | 4 | $res = preg_replace($pattern, $punctuationSign, $subject); |
|
48 | 4 | return $res; |
|
49 | } |
||
50 | 89 | return $subject; |
|
51 | } |
||
52 | |||
53 | /** |
||
1 ignored issue
–
show
|
|||
54 | * @param $child |
||
55 | */ |
||
56 | 132 | protected function getChildsAffixesAndDelimiter($child) |
|
57 | { |
||
58 | 132 | if (method_exists($child, "renderPrefix")) { |
|
59 | 131 | if (!empty($child->renderPrefix()) && !in_array($child->renderPrefix(), $this->childrenPrefixes)) { |
|
60 | 36 | $this->childrenPrefixes[] = $child->renderPrefix(); |
|
61 | } |
||
62 | } |
||
63 | 132 | if (method_exists($child, "renderSuffix")) { |
|
64 | 131 | if (!empty($child->renderSuffix()) && !in_array($child->renderSuffix(), $this->childrenSuffixes)) { |
|
65 | 31 | $this->childrenSuffixes[] = $child->renderSuffix(); |
|
66 | } |
||
67 | } |
||
68 | 132 | if (method_exists($child, "getDelimiter")) { |
|
69 | 79 | if (!empty($child->getDelimiter()) && !in_array($child->getDelimiter(), $this->childrenDelimiter)) { |
|
70 | 79 | $this->childrenDelimiter[] = $child->getDelimiter(); |
|
71 | } |
||
72 | } |
||
73 | 132 | } |
|
74 | |||
75 | /** |
||
1 ignored issue
–
show
|
|||
76 | * @param string $string |
||
2 ignored issues
–
show
|
|||
77 | * @return string |
||
1 ignored issue
–
show
|
|||
78 | */ |
||
79 | 136 | protected function removeConsecutiveChars($string) |
|
94 | } |
||
95 | } |