@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param array<string, array<mixed>> $rule |
37 | 37 | * @return DI_Container |
38 | 38 | */ |
39 | - public function addRule( string $name, array $rule ): DI_Container; |
|
39 | + public function addRule(string $name, array $rule): DI_Container; |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Add multiple rules |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param array<string, array<mixed>> $rules |
45 | 45 | * @return DI_Container |
46 | 46 | */ |
47 | - public function addRules( array $rules ): DI_Container; |
|
47 | + public function addRules(array $rules): DI_Container; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * Create an instance of a class, with optional parameters. |
@@ -53,5 +53,5 @@ discard block |
||
53 | 53 | * @param array<mixed> $args |
54 | 54 | * @return object|null |
55 | 55 | */ |
56 | - public function create( string $name, array $args = array() ); |
|
56 | + public function create(string $name, array $args = array()); |
|
57 | 57 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * @param object $class |
34 | 34 | * @return object |
35 | 35 | */ |
36 | - public function process( $class ); |
|
36 | + public function process($class); |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Used to for any middleware setup before process is called |
@@ -31,5 +31,5 @@ |
||
31 | 31 | * @param Hook_Loader $loader |
32 | 32 | * @return void |
33 | 33 | */ |
34 | - public function register( Hook_Loader $loader ): void; |
|
34 | + public function register(Hook_Loader $loader): void; |
|
35 | 35 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | * @param DI_Container $container |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - public function set_di_container( DI_Container $container ): void { |
|
44 | + public function set_di_container(DI_Container $container): void { |
|
45 | 45 | $this->di_container = $container; |
46 | 46 | } |
47 | 47 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | * @param App_Config $app_config |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - public function set_app_config( App_Config $app_config ): void { |
|
44 | + public function set_app_config(App_Config $app_config): void { |
|
45 | 45 | $this->app_config = $app_config; |
46 | 46 | } |
47 | 47 | } |
@@ -41,7 +41,7 @@ |
||
41 | 41 | * @param Hook_Loader $container |
42 | 42 | * @return void |
43 | 43 | */ |
44 | - public function set_hook_loader( Hook_Loader $hook_loader ): void { |
|
44 | + public function set_hook_loader(Hook_Loader $hook_loader): void { |
|
45 | 45 | $this->loader = $hook_loader; |
46 | 46 | } |
47 | 47 | } |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @param string $base_view_path |
43 | 43 | */ |
44 | - public function __construct( string $base_view_path ) { |
|
45 | - $this->base_view_path = $this->verify_view_path( $base_view_path ); |
|
44 | + public function __construct(string $base_view_path) { |
|
45 | + $this->base_view_path = $this->verify_view_path($base_view_path); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | * @param iterable<string, mixed> $data |
53 | 53 | * @return string|void |
54 | 54 | */ |
55 | - public function render( string $view, iterable $data, bool $print = true ) { |
|
56 | - if ( $print ) { |
|
57 | - print( $this->render_buffer( $view, $data ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
55 | + public function render(string $view, iterable $data, bool $print = true) { |
|
56 | + if ($print) { |
|
57 | + print($this->render_buffer($view, $data)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
58 | 58 | } else { |
59 | - return $this->render_buffer( $view, $data ); |
|
59 | + return $this->render_buffer($view, $data); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | |
@@ -68,11 +68,11 @@ discard block |
||
68 | 68 | * @param bool $print |
69 | 69 | * @return string|void |
70 | 70 | */ |
71 | - public function partial( string $view, iterable $data = array(), bool $print = true ) { |
|
72 | - if ( $print ) { |
|
73 | - $this->render( $view, $data, $print ); |
|
71 | + public function partial(string $view, iterable $data = array(), bool $print = true) { |
|
72 | + if ($print) { |
|
73 | + $this->render($view, $data, $print); |
|
74 | 74 | } else { |
75 | - return $this->render( $view, $data, $print ); |
|
75 | + return $this->render($view, $data, $print); |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | * @return string |
85 | 85 | * @throws Exception |
86 | 86 | */ |
87 | - protected function render_buffer( string $view, iterable $data ): string { |
|
87 | + protected function render_buffer(string $view, iterable $data): string { |
|
88 | 88 | |
89 | - if ( ! file_exists( $this->resolve_file_path( $view ) ) ) { |
|
90 | - throw new Exception( "{$view} doesn't exist" ); |
|
89 | + if ( ! file_exists($this->resolve_file_path($view))) { |
|
90 | + throw new Exception("{$view} doesn't exist"); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $output = ''; |
94 | 94 | ob_start(); |
95 | 95 | |
96 | 96 | // Set all the data values a parameters. |
97 | - foreach ( $data as $key => $value ) { |
|
98 | - if ( is_string( $key ) ) { |
|
99 | - ${\wp_strip_all_tags( $key )} = $value; |
|
97 | + foreach ($data as $key => $value) { |
|
98 | + if (is_string($key)) { |
|
99 | + ${\wp_strip_all_tags($key)} = $value; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - include $this->resolve_file_path( $view ); |
|
103 | + include $this->resolve_file_path($view); |
|
104 | 104 | $output = ob_get_contents(); |
105 | 105 | ob_end_clean(); |
106 | 106 | return $output ?: ''; |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | * @param string $file |
113 | 113 | * @return string |
114 | 114 | */ |
115 | - protected function clean_filename( string $file ): string { |
|
116 | - $file = ltrim( $file, '/' ); |
|
117 | - return substr( $file, -4 ) === '.php' |
|
118 | - ? substr( $file, 0, -4 ) |
|
115 | + protected function clean_filename(string $file): string { |
|
116 | + $file = ltrim($file, '/'); |
|
117 | + return substr($file, -4) === '.php' |
|
118 | + ? substr($file, 0, -4) |
|
119 | 119 | : $file; |
120 | 120 | |
121 | 121 | } |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | * @param string $filename |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - protected function resolve_file_path( string $filename ): string { |
|
129 | + protected function resolve_file_path(string $filename): string { |
|
130 | 130 | return sprintf( |
131 | 131 | '%s%s.php', |
132 | 132 | $this->base_view_path, |
133 | - $this->clean_filename( $filename ) |
|
133 | + $this->clean_filename($filename) |
|
134 | 134 | ); |
135 | 135 | } |
136 | 136 | |
@@ -142,12 +142,12 @@ discard block |
||
142 | 142 | * @return string |
143 | 143 | * @throws Exception |
144 | 144 | */ |
145 | - protected function verify_view_path( string $path ): string { |
|
145 | + protected function verify_view_path(string $path): string { |
|
146 | 146 | |
147 | - $path = rtrim( $path, '/' ) . '/'; |
|
147 | + $path = rtrim($path, '/') . '/'; |
|
148 | 148 | |
149 | - if ( ! \is_dir( $path ) ) { |
|
150 | - throw new Exception( "{$path} doesn't exist and cant be used as the base view path." ); |
|
149 | + if ( ! \is_dir($path)) { |
|
150 | + throw new Exception("{$path} doesn't exist and cant be used as the base view path."); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return $path; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param Renderable $engine |
52 | 52 | */ |
53 | - public function __construct( Renderable $engine ) { |
|
53 | + public function __construct(Renderable $engine) { |
|
54 | 54 | $this->engine = $engine; |
55 | 55 | } |
56 | 56 | |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | * @param bool $print |
63 | 63 | * @return string|void |
64 | 64 | */ |
65 | - public function render( string $view, iterable $view_data = array(), bool $print = true ) { |
|
66 | - if ( $print ) { |
|
67 | - $this->engine->render( $view, $view_data, self::PRINT_VIEW ); |
|
65 | + public function render(string $view, iterable $view_data = array(), bool $print = true) { |
|
66 | + if ($print) { |
|
67 | + $this->engine->render($view, $view_data, self::PRINT_VIEW); |
|
68 | 68 | } else { |
69 | - return $this->engine->render( $view, $view_data, self::RETURN_VIEW ); |
|
69 | + return $this->engine->render($view, $view_data, self::RETURN_VIEW); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param callable $to_buffer |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public static function print_buffer( callable $to_buffer ): string { |
|
79 | + public static function print_buffer(callable $to_buffer): string { |
|
80 | 80 | ob_start(); |
81 | 81 | $to_buffer(); |
82 | 82 | $output = ob_get_contents(); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param Dice $dice |
45 | 45 | */ |
46 | - public function __construct( Dice $dice ) { |
|
46 | + public function __construct(Dice $dice) { |
|
47 | 47 | $this->dice = $dice; |
48 | 48 | } |
49 | 49 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * @param Dice $dice |
54 | 54 | * @return self |
55 | 55 | */ |
56 | - public static function withDice( Dice $dice ): self { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
57 | - return new PinkCrab_Dice( $dice ); |
|
56 | + public static function withDice(Dice $dice): self { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
57 | + return new PinkCrab_Dice($dice); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * @param string $id Class name (fully namespaced.) |
65 | 65 | * @return object|null |
66 | 66 | */ |
67 | - public function get( $id ) { |
|
68 | - if ( ! $this->has( $id ) ) { |
|
69 | - throw new DI_Container_Exception( "{$id} not defined in container", 1 ); |
|
67 | + public function get($id) { |
|
68 | + if ( ! $this->has($id)) { |
|
69 | + throw new DI_Container_Exception("{$id} not defined in container", 1); |
|
70 | 70 | } |
71 | - return $this->create( $id ); |
|
71 | + return $this->create($id); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -78,21 +78,21 @@ discard block |
||
78 | 78 | * @param string $id Class name (fully namespaced.) |
79 | 79 | * @return bool |
80 | 80 | */ |
81 | - public function has( $id ) { |
|
82 | - $from_dice = $this->dice->getRule( $id ); |
|
81 | + public function has($id) { |
|
82 | + $from_dice = $this->dice->getRule($id); |
|
83 | 83 | // If set in global rules. |
84 | - if ( array_key_exists( 'substitutions', $from_dice ) |
|
85 | - && array_key_exists( $id, $from_dice['substitutions'] ) ) { |
|
84 | + if (array_key_exists('substitutions', $from_dice) |
|
85 | + && array_key_exists($id, $from_dice['substitutions'])) { |
|
86 | 86 | return true; |
87 | 87 | } |
88 | 88 | |
89 | 89 | // If set with a replacement instance. |
90 | - if ( array_key_exists( 'instanceOf', $from_dice ) ) { |
|
90 | + if (array_key_exists('instanceOf', $from_dice)) { |
|
91 | 91 | return true; |
92 | 92 | } |
93 | 93 | |
94 | 94 | // Checks if the class exists |
95 | - return class_exists( $id ); |
|
95 | + return class_exists($id); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | * @param array<string, string|object|mixed[]> $rule |
103 | 103 | * @return PinkCrab_Dice |
104 | 104 | */ |
105 | - public function addRule( string $name, array $rule ): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
106 | - $this->dice = $this->dice->addRule( $name, $rule ); |
|
105 | + public function addRule(string $name, array $rule): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
106 | + $this->dice = $this->dice->addRule($name, $rule); |
|
107 | 107 | return $this; |
108 | 108 | } |
109 | 109 | |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | * @param array<string, mixed[]> $rules |
114 | 114 | * @return PinkCrab_Dice |
115 | 115 | */ |
116 | - public function addRules( array $rules ): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
117 | - $this->dice = $this->dice->addRules( apply_filters( Hooks::APP_INIT_SET_DI_RULES, $rules ) ); |
|
116 | + public function addRules(array $rules): DI_Container { // phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid |
|
117 | + $this->dice = $this->dice->addRules(apply_filters(Hooks::APP_INIT_SET_DI_RULES, $rules)); |
|
118 | 118 | return $this; |
119 | 119 | } |
120 | 120 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @param array<mixed> $args |
126 | 126 | * @return object|null |
127 | 127 | */ |
128 | - public function create( string $name, array $args = array() ) { |
|
129 | - return $this->dice->create( $name, $args ); |
|
128 | + public function create(string $name, array $args = array()) { |
|
129 | + return $this->dice->create($name, $args); |
|
130 | 130 | } |
131 | 131 | } |