Completed
Pull Request — master (#7)
by Mark A.
02:37
created

DependencyCheck   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B checkVendorExistence() 0 26 3
A initCallback() 0 4 1
1
<?php
2
/**
3
 * Verify that dependencies are present
4
 *
5
 * @copyright (C) 2017  Mark A. Hershberger
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (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
20
 * 02110-1301, USA.
21
 *
22
 * @file
23
 * @ingroup SimpleBatchUpload
24
 */
25
26
namespace SimpleBatchUpload;
27
28
use PHPVersionCheck;
29
30
/**
31
 * Class ExtensionManager
32
 *
33
 * @package SimpleBatchUploadCheck
34
 */
35
class DependencyCheck extends PHPVersionCheck {
36
	/**
37
	 * Displays an error.
38
	 */
39
	function checkVendorExistence() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
40
		global $wgResourceModules, $wgScriptPath, $IP;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
41
		if ( !file_exists( __DIR__ . '/../vendor/autoload.php' ) ) {
42
			if ( !file_exists( "$IP/vendor/blueimp" ) ) {
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $IP instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
43
				$shortText = "SimpleBatchUpload requires some external dependencies." .
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal SimpleBatchUpload requir... external dependencies. does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
44
						   " Please run composer.";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Please run composer. does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
45
46
				$longText = "Error: You are missing some external dependencies.\n"
47
						  . "SimpleBatchUpload has some external dependencies that\n"
48
						  . "need to be installed via composer.";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal need to be installed via composer. does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
49
50
				$longHtml = <<<HTML
51
		MediaWiki now also has some external dependencies that need to be installed via
52
		composer.
53
HTML;
54
55
				$this->triggerError( 'External dependencies', $shortText, $longText,
56
									 $longHtml );
57
			}
58
			// HACK!
59
			$mod = $wgResourceModules['ext.SimpleBatchUpload.jquery-file-upload'];
60
			$mod['localBasePath'] = $IP;
61
			$mod['remoteBasePath'] = $wgScriptPath;
62
			$wgResourceModules['ext.SimpleBatchUpload.jquery-file-upload'] = $mod;
63
		}
64
	}
65
66
	/**
67
	 * Callback hook
68
	 */
69
	public static function initCallback() {
70
		$singleton = new self();
71
		$singleton->checkVendorExistence();
72
	}
73
}
74