Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
9 / 10
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
NamedConditionHelper
90.00% covered (success)
90.00%
9 / 10
66.67% covered (warning)
66.67%
2 / 3
7.05
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
 isNamed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 getExpression
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
4.03
1<?php
2
3namespace MediaWiki\RecentChanges\ChangesListQuery;
4
5use MediaWiki\User\TempUser\TempUserConfig;
6use stdClass;
7use Wikimedia\Rdbms\IExpression;
8use Wikimedia\Rdbms\IReadableDatabase;
9
10/**
11 * Shared code between the named and experience filter conditions
12 *
13 * @internal For use by ChangesListQuery
14 * @since 1.45
15 * @ingroup RecentChanges
16 */
17class NamedConditionHelper {
18    public function __construct(
19        private TempUserConfig $tempUserConfig
20    ) {
21    }
22
23    /**
24     * Determine whether a result row contains a named user
25     *
26     * @param stdClass $row
27     * @return bool
28     */
29    public function isNamed( stdClass $row ) {
30        return $row->rc_user && !$this->tempUserConfig->isTempName( $row->rc_user_text );
31    }
32
33    /**
34     * @param IReadableDatabase $dbr
35     * @param bool $isNamed
36     * @return IExpression
37     */
38    public function getExpression( IReadableDatabase $dbr, bool $isNamed ) {
39        $expr = $dbr->expr( 'actor_user', $isNamed ? '!=' : '=', null );
40        if ( !$this->tempUserConfig->isKnown() ) {
41            return $expr;
42        }
43        if ( $isNamed ) {
44            return $expr->andExpr( $this->tempUserConfig->getMatchCondition( $dbr,
45                'actor_name', IExpression::NOT_LIKE ) );
46        } else {
47            return $expr->orExpr( $this->tempUserConfig->getMatchCondition( $dbr,
48                'actor_name', IExpression::LIKE ) );
49        }
50    }
51
52}