Passed
Pull Request — master (#117)
by Glynn
02:41
created
src/Services/Dice/PinkCrab_Dice.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
64 64
 	 * @param string $id Class name (fully namespaced.)
65 65
 	 * @return object|null
66 66
 	 */
67
-	public function get( string $id ) {
68
-		if ( ! $this->has( $id ) ) {
69
-			throw new DI_Container_Exception( "{$id} not defined in container", 1 );
67
+	public function get(string $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
 block discarded – undo
78 78
 	 * @param string $id Class name (fully namespaced.)
79 79
 	 * @return bool
80 80
 	 */
81
-	public function has( string $id ): bool {
82
-		$from_dice = $this->dice->getRule( $id );
81
+	public function has(string $id): bool {
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Services/Registration/Registration_Service.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 * @param DI_Container $di_container
66 66
 	 * @return self
67 67
 	 */
68
-	public function set_container( DI_Container $di_container ): self {
68
+	public function set_container(DI_Container $di_container): self {
69 69
 		$this->di_container = $di_container;
70 70
 		return $this;
71 71
 	}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @param Hook_Loader $loader
77 77
 	 * @return self
78 78
 	 */
79
-	public function set_loader( Hook_Loader $loader ): self {
79
+	public function set_loader(Hook_Loader $loader): self {
80 80
 		$this->loader = $loader;
81 81
 		return $this;
82 82
 	}
@@ -87,8 +87,8 @@  discard block
 block discarded – undo
87 87
 	 * @param Registration_Middleware $middleware
88 88
 	 * @return self
89 89
 	 */
90
-	public function push_middleware( Registration_Middleware $middleware ): self {
91
-		$this->middleware[ \get_class( $middleware ) ] = $middleware;
90
+	public function push_middleware(Registration_Middleware $middleware): self {
91
+		$this->middleware[\get_class($middleware)] = $middleware;
92 92
 		return $this;
93 93
 	}
94 94
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 	 * @param array<string> $class_list
99 99
 	 * @return self
100 100
 	 */
101
-	public function set_classes( array $class_list ): self {
101
+	public function set_classes(array $class_list): self {
102 102
 		$this->class_list = $class_list;
103 103
 		return $this;
104 104
 	}
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @param string $class
110 110
 	 * @return self
111 111
 	 */
112
-	public function push_class( string $class ): self {
112
+	public function push_class(string $class): self {
113 113
 		$this->class_list[] = $class;
114 114
 		return $this;
115 115
 	}
@@ -121,30 +121,30 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function process(): void {
123 123
 		// Filter all classes, before processing.
124
-		$class_list = apply_filters( Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list );
125
-		foreach ( $this->middleware as $middleware ) {
124
+		$class_list = apply_filters(Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list);
125
+		foreach ($this->middleware as $middleware) {
126 126
 
127 127
 			// Set the container if requested.
128
-			if ( \method_exists( $middleware, 'set_di_container' ) && ! is_null( $this->di_container ) ) {
129
-				$middleware->set_di_container( $this->di_container );
128
+			if (\method_exists($middleware, 'set_di_container') && ! is_null($this->di_container)) {
129
+				$middleware->set_di_container($this->di_container);
130 130
 			}
131 131
 
132 132
 			// Set the hook loader if requested.
133
-			if ( \method_exists( $middleware, 'set_hook_loader' ) && ! is_null( $this->loader ) ) {
134
-				$middleware->set_hook_loader( $this->loader );
133
+			if (\method_exists($middleware, 'set_hook_loader') && ! is_null($this->loader)) {
134
+				$middleware->set_hook_loader($this->loader);
135 135
 			}
136 136
 
137 137
 			// Run middleware setup
138 138
 			$middleware->setup();
139 139
 
140 140
 			// Pass each class to the middleware.
141
-			foreach ( $class_list as $class ) {
141
+			foreach ($class_list as $class) {
142 142
 				// Construct class using container,
143
-				$class_instance = $this->di_container->create( $class );
143
+				$class_instance = $this->di_container->create($class);
144 144
 
145 145
 				// if valid object process via current middleware
146
-				if ( is_object( $class_instance ) ) {
147
-					$middleware->process( $class_instance );
146
+				if (is_object($class_instance)) {
147
+					$middleware->process($class_instance);
148 148
 				}
149 149
 			}
150 150
 
Please login to merge, or discard this patch.
src/Services/View/PHP_Engine.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @param string $base_view_path
54 54
 	 */
55
-	public function __construct( string $base_view_path ) {
56
-		$this->base_view_path = $this->verify_view_path( $base_view_path );
55
+	public function __construct(string $base_view_path) {
56
+		$this->base_view_path = $this->verify_view_path($base_view_path);
57 57
 	}
58 58
 
59 59
 	/**
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param Component_Compiler $compiler
63 63
 	 * @return void
64 64
 	 */
65
-	public function set_component_compiler( Component_Compiler $compiler ): void {
65
+	public function set_component_compiler(Component_Compiler $compiler): void {
66 66
 		$this->component_compiler = $compiler;
67 67
 	}
68 68
 
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
 	 * @param bool $print
75 75
 	 * @return string|void
76 76
 	 */
77
-	public function render( string $view, iterable $data, bool $print = true ) {
78
-		$view = $this->resolve_file_path( $view );
79
-		if ( $print ) {
80
-			print( $this->render_buffer( $view, $data ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
77
+	public function render(string $view, iterable $data, bool $print = true) {
78
+		$view = $this->resolve_file_path($view);
79
+		if ($print) {
80
+			print($this->render_buffer($view, $data)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
81 81
 		} else {
82
-			return $this->render_buffer( $view, $data );
82
+			return $this->render_buffer($view, $data);
83 83
 		}
84 84
 	}
85 85
 
@@ -89,21 +89,21 @@  discard block
 block discarded – undo
89 89
 	 * @param Component $component
90 90
 	 * @return string|void
91 91
 	 */
92
-	public function component( Component $component, bool $print = true ) {
92
+	public function component(Component $component, bool $print = true) {
93 93
 
94 94
 		// Throw exception of no compiler passed.
95
-		if ( ! is_a( $this->component_compiler, Component_Compiler::class ) ) {
96
-			throw new Exception( 'No component compiler passed to PHP_Engine' );
95
+		if ( ! is_a($this->component_compiler, Component_Compiler::class)) {
96
+			throw new Exception('No component compiler passed to PHP_Engine');
97 97
 		}
98 98
 
99 99
 		// Compile the component.
100
-		$compiled = $this->component_compiler->compile( $component );
101
-		$template = $this->maybe_resolve_dot_notation( $compiled->template() );
102
-		$view     = sprintf( '%s%s.php', \DIRECTORY_SEPARATOR, trim( $template ) );
103
-		if ( $print ) {
104
-			print( $this->render_buffer( $view, $compiled->data() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
100
+		$compiled = $this->component_compiler->compile($component);
101
+		$template = $this->maybe_resolve_dot_notation($compiled->template());
102
+		$view     = sprintf('%s%s.php', \DIRECTORY_SEPARATOR, trim($template));
103
+		if ($print) {
104
+			print($this->render_buffer($view, $compiled->data())); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
105 105
 		} else {
106
-			return $this->render_buffer( $view, $compiled->data() );
106
+			return $this->render_buffer($view, $compiled->data());
107 107
 		}
108 108
 	}
109 109
 
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * @param View_Model $view_model
115 115
 	 * @return string|void
116 116
 	 */
117
-	public function view_model( View_Model $view_model, bool $print = true ) {
118
-		return $this->render( $view_model->template(), $view_model->data(), $print );
117
+	public function view_model(View_Model $view_model, bool $print = true) {
118
+		return $this->render($view_model->template(), $view_model->data(), $print);
119 119
 	}
120 120
 
121 121
 	/**
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 	 * @param bool $print
127 127
 	 * @return string|void
128 128
 	 */
129
-	public function partial( string $view, iterable $data = array(), bool $print = true ) {
130
-		if ( $print ) {
131
-			$this->render( $view, $data, $print );
129
+	public function partial(string $view, iterable $data = array(), bool $print = true) {
130
+		if ($print) {
131
+			$this->render($view, $data, $print);
132 132
 		} else {
133
-			return $this->render( $view, $data, $print );
133
+			return $this->render($view, $data, $print);
134 134
 		}
135 135
 	}
136 136
 
@@ -142,27 +142,27 @@  discard block
 block discarded – undo
142 142
 	 * @return string
143 143
 	 * @throws Exception
144 144
 	 */
145
-	private function render_buffer( string $view, iterable $__data ): string {
145
+	private function render_buffer(string $view, iterable $__data): string {
146 146
 
147
-		if ( ! file_exists( $view ) ) {
148
-			throw new Exception( "{$view} doesn't exist" );
147
+		if ( ! file_exists($view)) {
148
+			throw new Exception("{$view} doesn't exist");
149 149
 		}
150 150
 
151 151
 		$output = '';
152 152
 		ob_start();
153 153
 
154 154
 		// Set all the data values a parameters.
155
-		foreach ( $__data as $__key => $__value ) {
156
-			if ( is_string( $__key ) ) {
157
-				${\wp_strip_all_tags( $__key )} = $__value;
155
+		foreach ($__data as $__key => $__value) {
156
+			if (is_string($__key)) {
157
+				${\wp_strip_all_tags($__key)} = $__value;
158 158
 			}
159 159
 
160 160
 			// Unset the key and value.
161
-			unset( $__key, $__value );
161
+			unset($__key, $__value);
162 162
 		}
163 163
 
164 164
 		// Unset the data.
165
-		unset( $__data );
165
+		unset($__data);
166 166
 
167 167
 		include $view;
168 168
 		$output = ob_get_contents();
@@ -176,12 +176,12 @@  discard block
 block discarded – undo
176 176
 	 * @param string $filename
177 177
 	 * @return string
178 178
 	 */
179
-	private function resolve_file_path( string $filename ): string {
180
-		$filename = $this->maybe_resolve_dot_notation( $filename );
179
+	private function resolve_file_path(string $filename): string {
180
+		$filename = $this->maybe_resolve_dot_notation($filename);
181 181
 		return sprintf(
182 182
 			'%s%s.php',
183 183
 			$this->base_view_path,
184
-			trim( $filename )
184
+			trim($filename)
185 185
 		);
186 186
 	}
187 187
 
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
 	 * @param string $filename
192 192
 	 * @return string
193 193
 	 */
194
-	private function maybe_resolve_dot_notation( string $filename ): string {
195
-		if ( endsWith( '.php' )( $filename ) ) {
196
-			$filename = substr( $filename, 0, -4 );
194
+	private function maybe_resolve_dot_notation(string $filename): string {
195
+		if (endsWith('.php')($filename)) {
196
+			$filename = substr($filename, 0, -4);
197 197
 		}
198 198
 
199
-		$parts    = explode( '.', $filename );
200
-		$filename = implode( DIRECTORY_SEPARATOR, $parts );
199
+		$parts    = explode('.', $filename);
200
+		$filename = implode(DIRECTORY_SEPARATOR, $parts);
201 201
 
202 202
 		return $filename;
203 203
 	}
@@ -209,12 +209,12 @@  discard block
 block discarded – undo
209 209
 	 * @return string
210 210
 	 * @throws Exception
211 211
 	 */
212
-	private function verify_view_path( string $path ): string {
213
-		$path = $this->maybe_resolve_dot_notation( $path );
214
-		$path = rtrim( $path, '/' ) . '/';
212
+	private function verify_view_path(string $path): string {
213
+		$path = $this->maybe_resolve_dot_notation($path);
214
+		$path = rtrim($path, '/') . '/';
215 215
 
216
-		if ( ! \is_dir( $path ) ) {
217
-			throw new Exception( "{$path} doesn't exist and cant be used as the base view path." );
216
+		if ( ! \is_dir($path)) {
217
+			throw new Exception("{$path} doesn't exist and cant be used as the base view path.");
218 218
 		}
219 219
 
220 220
 		return $path;
Please login to merge, or discard this patch.
src/Services/View/Component/Component_Compiler.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	private $component_aliases = array();
51 51
 
52 52
 	/** @param array<string, string> $component_aliases */
53
-	public function __construct( string $component_base_path = '', array $component_aliases = array() ) {
53
+	public function __construct(string $component_base_path = '', array $component_aliases = array()) {
54 54
 		$this->component_base_path = $component_base_path;
55
-		$this->component_aliases   = \apply_filters( Hooks::COMPONENT_ALIASES, $component_aliases );
55
+		$this->component_aliases   = \apply_filters(Hooks::COMPONENT_ALIASES, $component_aliases);
56 56
 	}
57 57
 
58 58
 	/**
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 * @param Component $component
62 62
 	 * @return View_Model
63 63
 	 */
64
-	public function compile( Component $component ): View_Model {
65
-		return new View_Model( $this->get_component_path( $component ), $component->get_variables() );
64
+	public function compile(Component $component): View_Model {
65
+		return new View_Model($this->get_component_path($component), $component->get_variables());
66 66
 	}
67 67
 
68 68
 	/**
@@ -71,34 +71,34 @@  discard block
 block discarded – undo
71 71
 	 * @param Component $component
72 72
 	 * @return string
73 73
 	 */
74
-	private function get_component_path( Component $component ): string {
74
+	private function get_component_path(Component $component): string {
75 75
 
76 76
 		// Check aliases.
77
-		$aliases = \apply_filters( Hooks::COMPONENT_ALIASES, $this->component_aliases );
77
+		$aliases = \apply_filters(Hooks::COMPONENT_ALIASES, $this->component_aliases);
78 78
 
79
-		if ( isset( $aliases[ get_class( $component ) ] ) ) {
80
-			return esc_attr( $aliases[ get_class( $component ) ] );
79
+		if (isset($aliases[get_class($component)])) {
80
+			return esc_attr($aliases[get_class($component)]);
81 81
 		}
82 82
 
83
-		$from_annotation = $this->get_annotation( 'view', $component );
83
+		$from_annotation = $this->get_annotation('view', $component);
84 84
 
85 85
 		// If it does have a path defined, use that.
86
-		if ( ! empty( $from_annotation ) ) {
87
-			return \trailingslashit( $this->component_base_path ) . $from_annotation;
86
+		if ( ! empty($from_annotation)) {
87
+			return \trailingslashit($this->component_base_path) . $from_annotation;
88 88
 		}
89 89
 
90 90
 		// If the component has a defined path
91
-		if ( $component->template() ) {
92
-			return \trailingslashit( $this->component_base_path ) . $component->template();
91
+		if ($component->template()) {
92
+			return \trailingslashit($this->component_base_path) . $component->template();
93 93
 		}
94 94
 
95 95
 		// Get path based on class name.
96
-		$reflect    = new \ReflectionClass( $component );
96
+		$reflect    = new \ReflectionClass($component);
97 97
 		$short_name = $reflect->getShortName();
98 98
 		// Add space between capitals, make lowercase and replace underscores with dashes.
99
-		$short_name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '$0', $short_name ) ?? '' );
100
-		$short_name = str_replace( '_', '-', $short_name );
101
-		return \trailingslashit( $this->component_base_path ) . $short_name;
99
+		$short_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '$0', $short_name) ?? '');
100
+		$short_name = str_replace('_', '-', $short_name);
101
+		return \trailingslashit($this->component_base_path) . $short_name;
102 102
 	}
103 103
 
104 104
 	/**
@@ -108,18 +108,18 @@  discard block
 block discarded – undo
108 108
 	 * @param Component $component
109 109
 	 * @return string|null
110 110
 	 */
111
-	private function get_annotation( string $annotation, Component $component ): ?string {
112
-		$reflect = new \ReflectionClass( $component );
111
+	private function get_annotation(string $annotation, Component $component): ?string {
112
+		$reflect = new \ReflectionClass($component);
113 113
 		$comment = $reflect->getDocComment();
114 114
 
115 115
 		// if no comment, return null.
116
-		if ( empty( $comment ) ) {
116
+		if (empty($comment)) {
117 117
 			return null;
118 118
 		}
119 119
 
120 120
 		// Check if the comment contains the annotation "@{$annotation}" using regex.
121 121
 		$pattern = "/@{$annotation}\s+(.*)/";
122
-		preg_match( $pattern, $comment, $matches );
122
+		preg_match($pattern, $comment, $matches);
123 123
 
124 124
 		return $matches[1] ?? null;
125 125
 	}
Please login to merge, or discard this patch.
src/Interfaces/Renderable.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * @param bool $print
36 36
 	 * @return void|string
37 37
 	 */
38
-	public function render( string $view, iterable $data, bool $print = true );
38
+	public function render(string $view, iterable $data, bool $print = true);
39 39
 
40 40
 	/**
41 41
 	 * Renders a component.
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	 * @param Component $component
44 44
 	 * @return string|void
45 45
 	 */
46
-	public function component( Component $component, bool $print = true );
46
+	public function component(Component $component, bool $print = true);
47 47
 
48 48
 	/**
49 49
 	 * Renders a view Model
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @param View_Model $view_model
52 52
 	 * @return string|void
53 53
 	 */
54
-	public function view_model( View_Model $view_model, bool $print = true );
54
+	public function view_model(View_Model $view_model, bool $print = true);
55 55
 
56 56
 	/**
57 57
 	 * Sets the component compiler.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * @param Component_Compiler $compiler
60 60
 	 * @return void
61 61
 	 */
62
-	public function set_component_compiler( Component_Compiler $compiler ): void;
62
+	public function set_component_compiler(Component_Compiler $compiler): void;
63 63
 
64 64
 	/**
65 65
 	 * Returns the base view path.
Please login to merge, or discard this patch.