Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.48% covered (success)
90.48%
19 / 21
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RCFeed
90.48% covered (success)
90.48%
19 / 21
50.00% covered (danger)
50.00%
1 / 2
11.10
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 notify
n/a
0 / 0
n/a
0 / 0
0
 factory
90.00% covered (success)
90.00%
18 / 20
0.00% covered (danger)
0.00%
0 / 1
10.10
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 * @see $wgRCFeeds
23 * @since 1.29
24 */
25abstract class RCFeed {
26    /**
27     * @param array $params
28     */
29    public function __construct( array $params = [] ) {
30    }
31
32    /**
33     * Dispatch the recent changes notification.
34     *
35     * @param RecentChange $rc
36     * @param string|null $actionComment
37     * @return bool Success
38     */
39    abstract public function notify( RecentChange $rc, $actionComment = null );
40
41    /**
42     * @param array $params
43     * @return RCFeed
44     */
45    final public static function factory( array $params ): RCFeed {
46        if ( !isset( $params['class'] ) ) {
47            if ( !isset( $params['uri'] ) ) {
48                throw new InvalidArgumentException( 'RCFeeds must have a class set' );
49            }
50            if ( strpos( $params['uri'], 'udp:' ) === 0 ) {
51                $params['class'] = UDPRCFeedEngine::class;
52            } elseif ( strpos( $params['uri'], 'redis:' ) === 0 ) {
53                $params['class'] = RedisPubSubFeedEngine::class;
54            } else {
55                global $wgRCEngines;
56                wfDeprecated( '$wgRCFeeds without class', '1.38' );
57                $scheme = parse_url( $params['uri'], PHP_URL_SCHEME );
58                if ( !$scheme ) {
59                    throw new InvalidArgumentException( "Invalid RCFeed uri: {$params['uri']}" );
60                }
61                if ( !isset( $wgRCEngines[$scheme] ) ) {
62                    throw new InvalidArgumentException( "Unknown RCFeed engine: $scheme" );
63                }
64                $params['class'] = $wgRCEngines[$scheme];
65            }
66        }
67
68        $class = $params['class'];
69        if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $class ) ) {
70            return $class;
71        }
72        if ( !class_exists( $class ) ) {
73            throw new InvalidArgumentException( "Unknown class '$class'." );
74        }
75        return new $class( $params );
76    }
77}