Completed
Push — master ( af77e8...7d9d07 )
by Zack
11s
created

Frontend_Request::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 15
ccs 0
cts 8
cp 0
crap 12
rs 9.4285
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 14 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
namespace GV;
3
4
/** If this file is called directly, abort. */
5
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6
	die();
7
}
8
9
/**
10
 * The default Request class.
11
 *
12
 * Finds out what Views are being requested.
13
 */
14
class Frontend_Request extends Request {
15
	/**
16
	 * Bootstrap.
17
	 *
18
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
19
	 */
20
	public function __construct() {
21
		add_action( 'wp', array( $this, 'parse' ), 12 );
22
		parent::__construct();
23
	}
24
25
	/**
26
	 * Parse the current WordPress context around the $post global.
27
	 *
28
	 * Called by the `wp` hook.
29
	 *
30
	 * @param \WP $wp The WordPress environment class. Unused.
31
	 *
32
	 * @internal
33
	 * @return void
34
	 */
35
	public function parse( $wp = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $wp is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
		/** Nothing to do in an administrative context. */
37
		if ( $this->is_admin() ) {
38
			return;
39
		}
40
41
		/** The post might either be a gravityview, or contain gravityview shortcodes. */
42
		global $post;
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...
43
44
		if ( ! $post instanceof \WP_Post ) {
0 ignored issues
show
Bug introduced by
The class WP_Post 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...
45
			$this->views = new View_Collection();
46
		} else {
47
			$this->views = View_Collection::from_post( $post );
48
		}
49
	}
50
51
	/**
52
	 * Check if WordPress is_admin(), and make sure not DOING_AJAX.
53
	 *
54
	 * @todo load-(scripts|styles).php return true for \is_admin()!
55
	 *
56
	 * @api
57
	 * @since future
58
	 *
59
	 * @return bool Pure is_admin or not?
60
	 */
61 1
	public function is_admin() {
62 1
		$doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false;
63 1
		return is_admin() && ! $doing_ajax;
64
	}
65
}
66