Completed
Push — master ( d9941c...4857d0 )
by
unknown
09:50
created

kmm-shield.php (4 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
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 30 and the first side effect is on line 19.

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
 * Plugin Name: KMM Shield
4
 * Description: This is a short description of what the plugin does.
5
 * Plugin URI:  http://github.com/KroneMultiMedia/plugin-shield
6
 * Version:     v9.9.9
7
 * Author:      Krone.at
8
 * Author URI:  http://www.krone.at
9
 * Licence:     MIT
10
 * Text Domain: kmm-shield
11
 * Domain Path: /languages
12
 */
13
14
namespace KMM\Shield;
15
16
use KMM\Shield\Core;
17
18
if ( ! function_exists( 'add_filter' ) ) {
19
	return;
20
}
21
22
23
/**
24
 * Ensure that autoload is already loaded or loads it if available.
25
 *
26
 * @param string $class_name
27
 *
28
 * @return bool
29
 */
30
function ensure_class_loaded( $class_name ) {
31
32
	$class_exists   = class_exists( $class_name );
33
	$autoload_found = file_exists( __DIR__ . '/vendor/autoload.php' );
34
35
	// If the class does not exist, and the vendor file is there
36
	// maybe the plugin was installed separately via Composer, let's try to load autoload
37
	if ( ! $class_exists && $autoload_found ) {
38
		@require_once __DIR__ . '/vendor/autoload.php';
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
39
	}
40
41
	return $class_exists || ( $autoload_found && class_exists( $class_name ) );
42
}
43
44
// Exit if classes are not available
45
if ( ! ensure_class_loaded( __NAMESPACE__ . '\Core' ) ) {
46
	return;
47
}
48
49
add_action( 'plugins_loaded', __NAMESPACE__ . '\main' );
50
51
52
/**
53
 * @wp-hook plugins_loaded
54
 */
55
function main() {
56
	new Core();
57
58
	if ( is_admin() ) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
59
		// Backend
60
61
		// TODO: register your backend-code here...
62
63
	} else {
0 ignored issues
show
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
64
		// Frontend
65
66
		// TODO: register frontend-code here...
67
	}
68
69
}
70