Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
FormattedRCFeed
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 send
n/a
0 / 0
n/a
0 / 0
0
 notify
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21/**
22 * Base class for RCFeed implementations that use RCFeedFormatter.
23 *
24 * Parameters:
25 *  - formatter: [required] Which RCFeedFormatter class to use.
26 *
27 * @see $wgRCFeeds
28 * @since 1.29
29 */
30abstract class FormattedRCFeed extends RCFeed {
31    private $params;
32
33    /**
34     * @param array $params
35     */
36    public function __construct( array $params ) {
37        $this->params = $params;
38    }
39
40    /**
41     * Send some text to the specified feed.
42     *
43     * @param array $feed The feed, as configured in an associative array
44     * @param string $line The text to send
45     * @return bool Success
46     */
47    abstract public function send( array $feed, $line );
48
49    /**
50     * @param RecentChange $rc
51     * @param string|null $actionComment
52     * @return bool Success
53     */
54    public function notify( RecentChange $rc, $actionComment = null ) {
55        $params = $this->params;
56        /** @var RCFeedFormatter $formatter */
57        $formatter = is_object( $params['formatter'] ) ? $params['formatter'] : new $params['formatter'];
58
59        $line = $formatter->getLine( $params, $rc, $actionComment );
60        if ( !$line ) {
61            // @codeCoverageIgnoreStart
62            // T109544 - If a feed formatter returns null, this will otherwise cause an
63            // error in at least RedisPubSubFeedEngine. Not sure best to handle this.
64            // @phan-suppress-next-line PhanTypeMismatchReturnProbablyReal
65            return;
66            // @codeCoverageIgnoreEnd
67        }
68        return $this->send( $params, $line );
69    }
70}