ComposerHookHandler::onPreUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 6.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use Composer\Package\Package;
4
use Composer\Script\Event;
5
6
$GLOBALS['IP'] = __DIR__ . '/../../';
7
require_once __DIR__ . '/../AutoLoader.php';
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class ComposerHookHandler {
14
15
	public static function onPreUpdate( Event $event ) {
16
		self::handleChangeEvent( $event );
17
	}
18
19
	public static function onPreInstall( Event $event ) {
20
		self::handleChangeEvent( $event );
21
	}
22
23
	private static function handleChangeEvent( Event $event ) {
24
		$package = $event->getComposer()->getPackage();
25
26
		if ( $package instanceof Package ) {
0 ignored issues
show
Bug introduced by
The class Composer\Package\Package does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
27
			$packageModifier = new ComposerPackageModifier(
28
				$package,
29
				new ComposerVersionNormalizer(),
30
				new MediaWikiVersionFetcher()
31
			);
32
33
			$packageModifier->setProvidesMediaWiki();
34
		}
35
	}
36
37
}
38