s7eph4n /
PurgePage
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace PurgePage; |
||
| 4 | |||
| 5 | class PurgePage { |
||
| 6 | |||
| 7 | public static function init() { |
||
| 8 | $GLOBALS['wgExtensionMessagesFiles']['PurgePageMagic'] = __DIR__ . '/PurgePage.magic.php'; |
||
| 9 | } |
||
| 10 | |||
| 11 | public static function registerParserFunction( \Parser &$parser ) { |
||
| 12 | |||
| 13 | $parser->setFunctionHook( 'purge', function ( $parser ) { |
||
| 14 | |||
| 15 | $params = func_get_args(); |
||
| 16 | |||
| 17 | if ( isset( $params[ 0 ] ) && isset( $params[ 1 ] ) ) { |
||
| 18 | $pageName = $params[ 1 ]; |
||
| 19 | } |
||
| 20 | |||
| 21 | $title = \Title::newFromText( $pageName ); |
||
|
0 ignored issues
–
show
|
|||
| 22 | |||
| 23 | if ( $title->isContentPage() && $title->exists() ) { |
||
| 24 | \WikiPage::factory( $title )->doPurge(); |
||
| 25 | } |
||
| 26 | |||
| 27 | } ); |
||
| 28 | } |
||
| 29 | } |
||
| 30 |
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:
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
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: