| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 10 | ||
| Bugs | 0 | Features | 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 |
||
| 28 | public function register( $container ) { |
||
| 29 | /** @var Container $container */ |
||
| 30 | $namespace = $container[ WPEMERGE_CONFIG_KEY ]['namespace']; |
||
| 31 | |||
| 32 | $this->extendConfig( $container, 'views', [get_stylesheet_directory(), get_template_directory()] ); |
||
| 33 | |||
| 34 | $this->extendConfig( $container, 'view_composers', [ |
||
| 35 | 'namespace' => $namespace . 'ViewComposers\\', |
||
| 36 | ] ); |
||
| 37 | |||
| 38 | $container[ WPEMERGE_VIEW_SERVICE_KEY ] = function ( $c ) { |
||
| 39 | return new ViewService( |
||
| 40 | $c[ WPEMERGE_CONFIG_KEY ]['view_composers'], |
||
| 41 | $c[ WPEMERGE_VIEW_ENGINE_KEY ], |
||
| 42 | $c[ WPEMERGE_HELPERS_HANDLER_FACTORY_KEY ] |
||
| 43 | ); |
||
| 44 | }; |
||
| 45 | |||
| 46 | $container[ WPEMERGE_VIEW_COMPOSE_ACTION_KEY ] = function ( $c ) { |
||
| 47 | return function ( ViewInterface $view ) use ( $c ) { |
||
| 48 | $view_service = $c[ WPEMERGE_VIEW_SERVICE_KEY ]; |
||
| 49 | $view_service->compose( $view ); |
||
| 50 | return $view; |
||
| 51 | }; |
||
| 52 | }; |
||
| 53 | |||
| 54 | $container[ WPEMERGE_VIEW_PHP_VIEW_ENGINE_KEY ] = function ( $c ) { |
||
| 55 | $finder = new PhpViewFilesystemFinder( MixedType::toArray( $c[ WPEMERGE_CONFIG_KEY ]['views'] ) ); |
||
| 56 | return new PhpViewEngine( $c[ WPEMERGE_VIEW_COMPOSE_ACTION_KEY ], $finder ); |
||
| 57 | }; |
||
| 58 | |||
| 59 | $container[ WPEMERGE_VIEW_ENGINE_KEY ] = function ( $c ) { |
||
| 60 | return $c[ WPEMERGE_VIEW_PHP_VIEW_ENGINE_KEY ]; |
||
| 61 | }; |
||
| 62 | |||
| 63 | $app = $container[ WPEMERGE_APPLICATION_KEY ]; |
||
| 64 | $app->alias( 'views', WPEMERGE_VIEW_SERVICE_KEY ); |
||
| 65 | |||
| 66 | $app->alias( 'view', function () use ( $app ) { |
||
| 67 | return call_user_func_array( [$app->views(), 'make'], func_get_args() ); |
||
| 68 | } ); |
||
| 69 | |||
| 70 | $app->alias( 'render', function () use ( $app ) { |
||
| 71 | return call_user_func_array( [$app->views(), 'render'], func_get_args() ); |
||
| 72 | } ); |
||
| 73 | |||
| 74 | $app->alias( 'layoutContent', function () use ( $app ) { |
||
| 75 | /** @var PhpViewEngine $engine */ |
||
| 76 | $engine = $app->resolve( WPEMERGE_VIEW_PHP_VIEW_ENGINE_KEY ); |
||
| 77 | |||
| 78 | echo $engine->getLayoutContent(); |
||
| 79 | } ); |
||
| 89 |