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 Carbon_Fields; |
||
3 | |||
4 | use Carbon_Fields\Helper\Helper; |
||
5 | |||
6 | # Define root directory |
||
7 | if ( ! defined( __NAMESPACE__ . '\DIR' ) ) { |
||
8 | define( __NAMESPACE__ . '\DIR', __DIR__ ); |
||
9 | } |
||
10 | |||
11 | # Define root URL |
||
12 | if ( ! defined( __NAMESPACE__ . '\URL' ) ) { |
||
13 | $url = \trailingslashit( DIR ); |
||
14 | $count = 0; |
||
15 | |||
16 | # Sanitize directory separator on Windows |
||
17 | $url = str_replace( '\\' ,'/', $url ); |
||
18 | |||
19 | # If installed as a plugin |
||
20 | $wp_plugin_dir = str_replace( '\\' ,'/', WP_PLUGIN_DIR ); |
||
21 | $url = str_replace( $wp_plugin_dir, \plugins_url(), $url, $count ); |
||
22 | |||
23 | if ( $count < 1 ) { |
||
24 | # If anywhere in wp-content |
||
25 | $wp_content_dir = str_replace( '\\' ,'/', WP_CONTENT_DIR ); |
||
26 | $url = str_replace( $wp_content_dir, \content_url(), $url, $count ); |
||
27 | } |
||
28 | |||
29 | if ( $count < 1 ) { |
||
30 | # If anywhere else within the WordPress installation |
||
31 | $wp_dir = str_replace( '\\' ,'/', ABSPATH ); |
||
32 | $url = str_replace( $wp_dir, \site_url( '/' ), $url ); |
||
33 | } |
||
34 | |||
35 | define( __NAMESPACE__ . '\URL', \untrailingslashit( $url ) ); |
||
36 | } |
||
37 | |||
38 | # Initialize helper |
||
39 | global $carbon_fields_helper; |
||
40 | if ( ! isset( $carbon_fields_helper ) ) { |
||
41 | $carbon_fields_helper = new Helper(); |
||
42 | } |
||
43 |
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.