Completed
Branch master (939199)
by
unknown
39:35
created

includes/changetags/ChangeTagsLogList.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
 * @ingroup Change tagging
20
 */
21
22
/**
23
 * Stores a list of taggable log entries.
24
 * @since 1.25
25
 */
26
class ChangeTagsLogList extends ChangeTagsList {
27
	public function getType() {
28
		return 'logentry';
29
	}
30
31
	/**
32
	 * @param IDatabase $db
33
	 * @return mixed
34
	 */
35
	public function doQuery( $db ) {
36
		$ids = array_map( 'intval', $this->ids );
37
		$queryInfo = DatabaseLogEntry::getSelectQueryData();
38
		$queryInfo['conds'] += [ 'log_id' => $ids ];
39
		$queryInfo['options'] += [ 'ORDER BY' => 'log_id DESC' ];
40
		ChangeTags::modifyDisplayQuery(
41
			$queryInfo['tables'],
42
			$queryInfo['fields'],
43
			$queryInfo['conds'],
44
			$queryInfo['join_conds'],
45
			$queryInfo['options'],
46
			''
47
		);
48
		return $db->select(
49
			$queryInfo['tables'],
50
			$queryInfo['fields'],
51
			$queryInfo['conds'],
52
			__METHOD__,
53
			$queryInfo['options'],
54
			$queryInfo['join_conds']
55
		);
56
	}
57
58
	public function newItem( $row ) {
59
		return new ChangeTagsLogItem( $this, $row );
60
	}
61
62
	/**
63
	 * Add/remove change tags from all the log entries in the list.
64
	 *
65
	 * @param array $tagsToAdd
66
	 * @param array $tagsToRemove
67
	 * @param array $params
68
	 * @param string $reason
69
	 * @param User $user
70
	 * @return Status
71
	 */
72 View Code Duplication
	public function updateChangeTagsOnAll( $tagsToAdd, $tagsToRemove, $params,
73
		$reason, $user ) {
74
75
		// @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
76
		for ( $this->reset(); $this->current(); $this->next() ) {
77
			// @codingStandardsIgnoreEnd
78
			$item = $this->current();
79
			$status = ChangeTags::updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
80
				null, null, $item->getId(), $params, $reason, $user );
81
			// Should only fail on second and subsequent times if the user trips
82
			// the rate limiter
83
			if ( !$status->isOK() ) {
84
				break;
85
			}
86
		}
87
88
		return $status;
0 ignored issues
show
The variable $status does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
89
	}
90
}
91