gravityview /
GravityView
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
|
|||
| 2 | namespace GV; |
||
| 3 | |||
| 4 | /** If this file is called directly, abort. */ |
||
| 5 | if ( ! defined( 'GRAVITYVIEW_DIR' ) ) |
||
|
0 ignored issues
–
show
|
|||
| 6 | die(); |
||
| 7 | |||
| 8 | /** |
||
| 9 | * The default Request class. |
||
| 10 | * |
||
| 11 | * Parses and transforms an end-request for a view to a View |
||
| 12 | * in a default frontend, WP_Query-based WordPress context. |
||
| 13 | */ |
||
| 14 | final 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 Please refer to the PHP core documentation on constructors. Loading history...
|
|||
| 19 | */ |
||
| 20 | public function __construct() { |
||
| 21 | add_action( 'wp', array( $this, 'parse' ) ); |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Parse the current WordPress context around the $post global. |
||
| 26 | * |
||
| 27 | * Called by the `wp` hook. |
||
| 28 | * |
||
| 29 | * @param \WP $wp The WordPress environment class. Unused. |
||
| 30 | * |
||
| 31 | * @internal |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | public function parse( $wp = null ) { |
||
|
0 ignored issues
–
show
|
|||
| 35 | /** Nothing to do in an administrative context. */ |
||
| 36 | if ( $this->is_admin() ) { |
||
| 37 | return; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** The post might either be a gravityview, or contain gravityview shortcodes. */ |
||
| 41 | 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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
| 42 | |||
| 43 | if ( ! $post instanceof \WP_Post ) { |
||
|
0 ignored issues
–
show
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 dependenciesPHP Analyzer uses your Are you sure this class is defined by one of your dependencies, or did you maybe
not list a dependency in either the 2. Missing use statementPHP does not complain about undefined classes in if ($x instanceof DoesNotExist) {
// Do something.
}
If you have not tested against this specific condition, such errors might go unnoticed. Loading history...
|
|||
| 44 | $this->views = new View_Collection(); |
||
| 45 | } else { |
||
| 46 | $this->views = View_Collection::from_post( $post ); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Check if WordPress is_admin(), and make sure not DOING_AJAX. |
||
| 52 | * |
||
| 53 | * @todo load-(scripts|styles).php return true for \is_admin()! |
||
| 54 | * |
||
| 55 | * @api |
||
| 56 | * @since future |
||
| 57 | * |
||
| 58 | * @return bool Pure is_admin or not? |
||
| 59 | */ |
||
| 60 | public function is_admin() { |
||
| 61 | $doing_ajax = defined( 'DOING_AJAX' ) ? DOING_AJAX : false; |
||
| 62 | return is_admin() && ! $doing_ajax; |
||
| 63 | } |
||
| 64 | } |
||
| 65 |
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.