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

includes/actions/DeleteAction.php (2 issues)

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
 * Handle page deletion
4
 *
5
 * Copyright © 2012 Timo Tijhof
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20
 *
21
 * @file
22
 * @ingroup Actions
23
 * @author Timo Tijhof
24
 */
25
26
/**
27
 * Handle page deletion
28
 *
29
 * This is a wrapper that will call Article::delete().
30
 *
31
 * @ingroup Actions
32
 */
33 View Code Duplication
class DeleteAction extends FormlessAction {
0 ignored issues
show
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
35
	public function getName() {
36
		return 'delete';
37
	}
38
39
	public function onView() {
40
		return null;
41
	}
42
43
	public function show() {
44
		$this->useTransactionalTimeLimit();
45
46
		$out = $this->getOutput();
47
		if ( $this->getContext()->getConfig()->get( 'UseMediaWikiUIEverywhere' ) ) {
48
			$out->addModuleStyles( [
49
				'mediawiki.ui.input',
50
				'mediawiki.ui.checkbox',
51
			] );
52
		}
53
		$this->addHelpLink( 'Help:Sysop deleting and undeleting' );
54
		$this->page->delete();
0 ignored issues
show
The method delete does only exist in Article and CategoryPage and ImagePage, but not in Page and WikiPage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
55
	}
56
57
	public function doesWrites() {
58
		return true;
59
	}
60
}
61