-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomRule.php
More file actions
66 lines (59 loc) · 1.59 KB
/
CustomRule.php
File metadata and controls
66 lines (59 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Bit&Black TypoRules.
*
* @author Tobias Köngeter
* @copyright Copyright © Bit&Black
* @link https://www.bitandblack.com
* @license MIT
*/
namespace BitAndBlack\TypoRules\Rule;
use BitAndBlack\TypoRules\Documentation\Configuration;
use BitAndBlack\TypoRules\Documentation\Description;
/**
* This class doesn't contain a predefined rule per default.
* You can use it to define your custom search and replace patterns by your own.
*/
#[Description(
<<<'DESCRIPTION'
An empty rule that can be configured completely by yourself. It allows you to define your own patterns using the two setter methods and stay in the spirit of this library:
```php
$customRule = new CustomRule();
$customRule
->setSearchPattern('\s+/')
->setReplacePattern('\s')
;
```
DESCRIPTION
)]
class CustomRule extends AbstractRule implements RuleInterface
{
public static function create(): self
{
return new self();
}
/**
* Defines the search pattern.
*
* @param string $searchPattern
* @return $this
*/
#[Configuration('Define the search pattern.')]
public function setSearchPattern(string $searchPattern): self
{
$this->searchPattern = $searchPattern;
return $this;
}
/**
* Defines the replacement pattern.
*
* @param string $replacePattern
* @return $this
*/
#[Configuration('Define the replacement pattern.')]
public function setReplacePattern(string $replacePattern): self
{
$this->replacePattern = $replacePattern;
return $this;
}
}