Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
RegexFilterRule
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 createAlias
n/a
0 / 0
n/a
0 / 0
0
 getExpression
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMainGroup
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Wikispeech\Segment\TextFilter;
4
5/**
6 * @file
7 * @ingroup Extensions
8 * @license GPL-2.0-or-later
9 */
10
11/**
12 * @since 0.1.10
13 */
14abstract class RegexFilterRule implements FilterRule {
15
16    /** @var string Regular expression */
17    private $expression;
18
19    /** @var int|string Group in $expression matching rule */
20    private $mainGroup;
21
22    /**
23     * @since 0.1.10
24     * @param string $expression
25     * @param int|string $mainGroup
26     */
27    public function __construct(
28        string $expression,
29        $mainGroup
30    ) {
31        $this->expression = $expression;
32        $this->mainGroup = $mainGroup;
33    }
34
35    /**
36     * Translates matched text according to the rules of the implementation.
37     *
38     * @todo If this returned an array of {@link FilterPart} instead of the alias string value,
39     *  then the response could represent multiple tokens. In some cases this would make for
40     *  better highlighting. E.g. 2002-2020 would then become three distinct tokens:
41     *  [ "two thousand two", "to", "two thousand twenty" ],
42     *  rather than the single composite token
43     *  "two thousand two to two thousand twenty".
44     *  It would however require a bit of refactoring.
45     *
46     * @since 0.1.10
47     * @param array $matches Matching groups produced by preg_match
48     * @return string|null Null if matches does not contain text that follow rules of this method.
49     */
50    abstract public function createAlias( array $matches ): ?string;
51
52    /**
53     * @since 0.1.10
54     * @return string
55     */
56    public function getExpression(): string {
57        return $this->expression;
58    }
59
60    /**
61     * @since 0.1.10
62     * @return int|string
63     */
64    public function getMainGroup() {
65        return $this->mainGroup;
66    }
67
68}