| Conditions | 5 |
| Paths | 2 |
| Total Lines | 69 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 14 | public function __construct( $values = array() ) { |
||
| 15 | |||
| 16 | global $wp_version; |
||
| 17 | |||
| 18 | $defaults = []; |
||
| 19 | $defaults['twig.options'] = []; |
||
| 20 | $defaults['twig.directories'] = []; |
||
| 21 | |||
| 22 | // This needs to be lazy or theme switchers and alike explode it. |
||
| 23 | $defaults['twig.loader'] = function ( $meadow ) { |
||
| 24 | |||
| 25 | $stylesheet_dir = get_stylesheet_directory(); |
||
|
|
|||
| 26 | $template_dir = get_template_directory(); |
||
| 27 | $calculated_dirs = array( |
||
| 28 | $stylesheet_dir, |
||
| 29 | $template_dir, |
||
| 30 | plugin_dir_path( __DIR__ ) . 'src/twig', |
||
| 31 | ); |
||
| 32 | |||
| 33 | // Enables explicit inheritance from parent theme in child. |
||
| 34 | if ( $stylesheet_dir !== $template_dir ) { |
||
| 35 | $calculated_dirs[] = \dirname( $template_dir ); |
||
| 36 | } |
||
| 37 | |||
| 38 | $directories = array_unique( |
||
| 39 | array_merge( |
||
| 40 | $calculated_dirs, |
||
| 41 | $meadow['twig.directories'] |
||
| 42 | ) |
||
| 43 | ); |
||
| 44 | |||
| 45 | return new \Twig_Loader_Filesystem( $directories ); |
||
| 46 | }; |
||
| 47 | |||
| 48 | $defaults['twig.undefined_function'] = array( __CLASS__, 'undefined_function' ); |
||
| 49 | $defaults['twig.undefined_filter'] = array( __CLASS__, 'undefined_filter' ); |
||
| 50 | |||
| 51 | $defaults['twig.environment'] = function ( $meadow ) { |
||
| 52 | $environment = new \Twig_Environment( $meadow['twig.loader'], $meadow['twig.options'] ); |
||
| 53 | $meadow_extension = new Extension(); |
||
| 54 | $environment->addExtension( $meadow_extension ); |
||
| 55 | $environment->registerUndefinedFunctionCallback( $meadow['twig.undefined_function'] ); |
||
| 56 | $environment->registerUndefinedFilterCallback( $meadow['twig.undefined_filter'] ); |
||
| 57 | |||
| 58 | if ( \defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
||
| 59 | $debug_extension = new \Twig_Extension_Debug(); |
||
| 60 | $environment->addExtension( $debug_extension ); |
||
| 61 | $environment->enableDebug(); |
||
| 62 | } |
||
| 63 | |||
| 64 | return $environment; |
||
| 65 | }; |
||
| 66 | |||
| 67 | if ( version_compare( rtrim( $wp_version, '-src' ), '4.7', '>=' ) ) { |
||
| 68 | |||
| 69 | $defaults['hierarchy'] = function () { |
||
| 70 | return new Type_Template_Hierarchy(); |
||
| 71 | }; |
||
| 72 | } else { |
||
| 73 | |||
| 74 | trigger_error( 'Pre–WP 4.7 implementation of Meadow hierarchy is deprecated and will be removed in 1.0.', E_USER_DEPRECATED ); |
||
| 75 | |||
| 76 | $defaults['hierarchy'] = function () { |
||
| 77 | /** @noinspection PhpDeprecationInspection */ |
||
| 78 | return new Template_Hierarchy(); |
||
| 79 | }; |
||
| 80 | } |
||
| 81 | |||
| 82 | parent::__construct( array_merge( $defaults, $values ) ); |
||
| 83 | } |
||
| 185 | } |