Passed
Pull Request — master (#79)
by Glynn
05:50
created
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,5 +59,5 @@  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
 }
Please login to merge, or discard this patch.
src/Services/View/Component/Component.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,14 +34,14 @@
 block discarded – undo
34 34
 	 */
35 35
 	public function get_variables(): array {
36 36
 		// Get all Private, public and protected properties.
37
-		$reflect = new \ReflectionClass( get_class( $this ) );
37
+		$reflect = new \ReflectionClass(get_class($this));
38 38
 		$vars    = array();
39 39
 
40
-		foreach ( $reflect->getProperties( \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PROTECTED )
40
+		foreach ($reflect->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PROTECTED)
41 41
 			as $var
42 42
 		) {
43
-			$var->setAccessible( true );
44
-			$vars[ $var->getName() ] = $var->getValue( $this );
43
+			$var->setAccessible(true);
44
+			$vars[$var->getName()] = $var->getValue($this);
45 45
 		}
46 46
 
47 47
 		return $vars;
Please login to merge, or discard this patch.
src/Services/View/Component/Component_Compiler.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 	private $component_aliases = array();
50 50
 
51 51
 	/** @param array<string, string> $component_aliases */
52
-	public function __construct( string $component_base_path = '', array $component_aliases = array() ) {
52
+	public function __construct(string $component_base_path = '', array $component_aliases = array()) {
53 53
 		$this->component_base_path = $component_base_path;
54 54
 		$this->component_aliases   = $component_aliases;
55 55
 	}
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	 * @param Component $component
61 61
 	 * @return View_Model
62 62
 	 */
63
-	public function compile( Component $component ): View_Model {
64
-		return new View_Model( $this->get_component_path( $component ), $component->get_variables() );
63
+	public function compile(Component $component): View_Model {
64
+		return new View_Model($this->get_component_path($component), $component->get_variables());
65 65
 	}
66 66
 
67 67
 	/**
@@ -70,32 +70,32 @@  discard block
 block discarded – undo
70 70
 	 * @param Component $component
71 71
 	 * @return string
72 72
 	 */
73
-	private function get_component_path( Component $component ): string {
73
+	private function get_component_path(Component $component): string {
74 74
 
75 75
 		// Check aliases.
76
-		if ( isset( $this->component_aliases[ get_class( $component ) ] ) ) {
77
-			return esc_html( $this->component_aliases[ get_class( $component ) ] );
76
+		if (isset($this->component_aliases[get_class($component)])) {
77
+			return esc_html($this->component_aliases[get_class($component)]);
78 78
 		}
79 79
 
80
-		$from_annotation = $this->get_annotation( 'view', $component );
80
+		$from_annotation = $this->get_annotation('view', $component);
81 81
 		// If it does have a path defined, use that.
82
-		if ( ! empty( $from_annotation ) ) {
83
-			return \trailingslashit( $this->component_base_path ) . $from_annotation;
82
+		if ( ! empty($from_annotation)) {
83
+			return \trailingslashit($this->component_base_path) . $from_annotation;
84 84
 		}
85 85
 
86 86
 		// If the component has a defined path
87
-		if ( $component->template() ) {
88
-			return \trailingslashit( $this->component_base_path ) . $component->template();
87
+		if ($component->template()) {
88
+			return \trailingslashit($this->component_base_path) . $component->template();
89 89
 		}
90 90
 
91 91
 		// Get path based on class name.
92
-		$reflect    = new \ReflectionClass( $component );
92
+		$reflect    = new \ReflectionClass($component);
93 93
 		$short_name = $reflect->getShortName();
94 94
 		// Add space between capitals, make lowercase and replace underscores with dashes.
95
-		$short_name = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $short_name ) ?? '' );
96
-		$short_name = str_replace( '_', '-', $short_name );
95
+		$short_name = strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $short_name) ?? '');
96
+		$short_name = str_replace('_', '-', $short_name);
97 97
 
98
-		return \trailingslashit( $this->component_base_path ) . $short_name;
98
+		return \trailingslashit($this->component_base_path) . $short_name;
99 99
 	}
100 100
 
101 101
 	/**
@@ -105,18 +105,18 @@  discard block
 block discarded – undo
105 105
 	 * @param Component $component
106 106
 	 * @return string|null
107 107
 	 */
108
-	private function get_annotation( string $annotation, Component $component ): ?string {
109
-		$reflect = new \ReflectionClass( $component );
108
+	private function get_annotation(string $annotation, Component $component): ?string {
109
+		$reflect = new \ReflectionClass($component);
110 110
 		$comment = $reflect->getDocComment();
111 111
 
112 112
 		// if no comment, return null.
113
-		if ( empty( $comment ) ) {
113
+		if (empty($comment)) {
114 114
 			return null;
115 115
 		}
116 116
 
117 117
 		// If comment contains the annotation, return the value.
118
-		return strpos( $comment, "@{$annotation}" ) !== false
119
-			? $this->extract_annotation_value( $comment, $annotation )
118
+		return strpos($comment, "@{$annotation}") !== false
119
+			? $this->extract_annotation_value($comment, $annotation)
120 120
 			: null;
121 121
 	}
122 122
 
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
 	 * @param string $annotation
128 128
 	 * @return string|null
129 129
 	 */
130
-	private function extract_annotation_value( string $comment, string $annotation ): ?string {
130
+	private function extract_annotation_value(string $comment, string $annotation): ?string {
131 131
 		$pattern = "/@{$annotation}\s+(.*)/";
132
-		preg_match( $pattern, $comment, $matches );
132
+		preg_match($pattern, $comment, $matches);
133 133
 		return $matches[1] ?? null;
134 134
 	}
135 135
 
Please login to merge, or discard this patch.
src/Services/View/PHP_Engine.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @param string $base_view_path
53 53
 	 */
54
-	public function __construct( string $base_view_path ) {
55
-		$this->base_view_path = $this->verify_view_path( $base_view_path );
54
+	public function __construct(string $base_view_path) {
55
+		$this->base_view_path = $this->verify_view_path($base_view_path);
56 56
 	}
57 57
 
58 58
 	/**
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * @param Component_Compiler $compiler
62 62
 	 * @return void
63 63
 	 */
64
-	public function set_component_compiler( Component_Compiler $compiler ): void {
64
+	public function set_component_compiler(Component_Compiler $compiler): void {
65 65
 		$this->component_compiler = $compiler;
66 66
 	}
67 67
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 	 * @param bool $print
74 74
 	 * @return string|void
75 75
 	 */
76
-	public function render( string $view, iterable $data, bool $print = true ) {
76
+	public function render(string $view, iterable $data, bool $print = true) {
77 77
 
78
-		if ( $print ) {
79
-			print( $this->render_buffer( $view, $data ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
78
+		if ($print) {
79
+			print($this->render_buffer($view, $data)); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
80 80
 		} else {
81
-			return $this->render_buffer( $view, $data );
81
+			return $this->render_buffer($view, $data);
82 82
 		}
83 83
 	}
84 84
 
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
 	 * @param Component $component
89 89
 	 * @return string|void
90 90
 	 */
91
-	public function component( Component $component, bool $print = true ) {
91
+	public function component(Component $component, bool $print = true) {
92 92
 
93 93
 		// Throw exception of no compiler passed.
94
-		if ( ! is_a( $this->component_compiler, Component_Compiler::class ) ) {
95
-			throw new Exception( 'No component compiler passed to PHP_Engine' );
94
+		if ( ! is_a($this->component_compiler, Component_Compiler::class)) {
95
+			throw new Exception('No component compiler passed to PHP_Engine');
96 96
 		}
97 97
 
98 98
 		// Compile the component.
99
-		$compiled = $this->component_compiler->compile( $component );
100
-		return $this->render( $compiled->template(), $compiled->data(), $print );
99
+		$compiled = $this->component_compiler->compile($component);
100
+		return $this->render($compiled->template(), $compiled->data(), $print);
101 101
 	}
102 102
 
103 103
 
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 	 * @param View_Model $view_model
108 108
 	 * @return string|void
109 109
 	 */
110
-	public function view_model( View_Model $view_model, bool $print = true ) {
111
-		return $this->render( $view_model->template(), $view_model->data(), $print );
110
+	public function view_model(View_Model $view_model, bool $print = true) {
111
+		return $this->render($view_model->template(), $view_model->data(), $print);
112 112
 	}
113 113
 
114 114
 	/**
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
 	 * @param bool $print
120 120
 	 * @return string|void
121 121
 	 */
122
-	public function partial( string $view, iterable $data = array(), bool $print = true ) {
123
-		if ( $print ) {
124
-			$this->render( $view, $data, $print );
122
+	public function partial(string $view, iterable $data = array(), bool $print = true) {
123
+		if ($print) {
124
+			$this->render($view, $data, $print);
125 125
 		} else {
126
-			return $this->render( $view, $data, $print );
126
+			return $this->render($view, $data, $print);
127 127
 		}
128 128
 	}
129 129
 
@@ -135,26 +135,26 @@  discard block
 block discarded – undo
135 135
 	 * @return string
136 136
 	 * @throws Exception
137 137
 	 */
138
-	protected function render_buffer( string $view, iterable $__data ): string {
138
+	protected function render_buffer(string $view, iterable $__data): string {
139 139
 
140
-		if ( ! file_exists( $this->resolve_file_path( $view ) ) ) {
141
-			throw new Exception( "{$view} doesn't exist" );
140
+		if ( ! file_exists($this->resolve_file_path($view))) {
141
+			throw new Exception("{$view} doesn't exist");
142 142
 		}
143 143
 
144 144
 		$output = '';
145 145
 		ob_start();
146 146
 
147 147
 		// Set all the data values a parameters.
148
-		foreach ( $__data as $__key => $__value ) {
149
-			if ( is_string( $__key ) ) {
150
-				${\wp_strip_all_tags( $__key )} = $__value;
148
+		foreach ($__data as $__key => $__value) {
149
+			if (is_string($__key)) {
150
+				${\wp_strip_all_tags($__key)} = $__value;
151 151
 			}
152 152
 
153 153
 			// Unset the key and value.
154
-			unset( $__key, $__value, $__data );
154
+			unset($__key, $__value, $__data);
155 155
 		}
156 156
 
157
-		include $this->resolve_file_path( $view );
157
+		include $this->resolve_file_path($view);
158 158
 		$output = ob_get_contents();
159 159
 		ob_end_clean();
160 160
 		return $output ?: '';
@@ -166,10 +166,10 @@  discard block
 block discarded – undo
166 166
 	 * @param string $file
167 167
 	 * @return string
168 168
 	 */
169
-	protected function clean_filename( string $file ): string {
170
-			$file = ltrim( $file, '/' );
171
-			return substr( $file, -4 ) === '.php'
172
-			? substr( $file, 0, -4 )
169
+	protected function clean_filename(string $file): string {
170
+			$file = ltrim($file, '/');
171
+			return substr($file, -4) === '.php'
172
+			? substr($file, 0, -4)
173 173
 			: $file;
174 174
 
175 175
 	}
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
 	 * @param string $filename
181 181
 	 * @return string
182 182
 	 */
183
-	protected function resolve_file_path( string $filename ): string {
183
+	protected function resolve_file_path(string $filename): string {
184 184
 		return sprintf(
185 185
 			'%s%s.php',
186 186
 			$this->base_view_path,
187
-			$this->clean_filename( $filename )
187
+			$this->clean_filename($filename)
188 188
 		);
189 189
 	}
190 190
 
@@ -196,12 +196,12 @@  discard block
 block discarded – undo
196 196
 	 * @return string
197 197
 	 * @throws Exception
198 198
 	 */
199
-	protected function verify_view_path( string $path ): string {
199
+	protected function verify_view_path(string $path): string {
200 200
 
201
-		$path = rtrim( $path, '/' ) . '/';
201
+		$path = rtrim($path, '/') . '/';
202 202
 
203
-		if ( ! \is_dir( $path ) ) {
204
-			throw new Exception( "{$path} doesn't exist and cant be used as the base view path." );
203
+		if ( ! \is_dir($path)) {
204
+			throw new Exception("{$path} doesn't exist and cant be used as the base view path.");
205 205
 		}
206 206
 
207 207
 		return $path;
Please login to merge, or discard this patch.
src/Services/View/View_Model.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
 	private $data = array();
43 43
 
44 44
 	/** @param array<string, mixed> $data */
45
-	public function __construct( string $template, array $data = array() ) {
45
+	public function __construct(string $template, array $data = array()) {
46 46
 		$this->template = $template;
47 47
 		$this->data     = $data;
48 48
 	}
Please login to merge, or discard this patch.
src/Services/View/View.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @param Renderable $engine
63 63
 	 */
64
-	public function __construct( Renderable $engine, Component_Compiler $component_compiler ) {
64
+	public function __construct(Renderable $engine, Component_Compiler $component_compiler) {
65 65
 		$this->engine             = $engine;
66 66
 		$this->component_compiler = $component_compiler;
67 67
 
68 68
 		// Populate engine with compiler.
69
-		$this->engine->set_component_compiler( $component_compiler );
69
+		$this->engine->set_component_compiler($component_compiler);
70 70
 	}
71 71
 
72 72
 	/**
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
 	 * @param bool $print Print or Return the HTML
78 78
 	 * @return string|void
79 79
 	 */
80
-	public function render( string $view, iterable $view_data = array(), bool $print = self::PRINT_VIEW ) {
81
-		return $this->engine->render( $view, $view_data, $print );
80
+	public function render(string $view, iterable $view_data = array(), bool $print = self::PRINT_VIEW) {
81
+		return $this->engine->render($view, $view_data, $print);
82 82
 	}
83 83
 
84 84
 	/**
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 	 * @param bool $print Print or Return the HTML
89 89
 	 * @return string|void
90 90
 	 */
91
-	public function component( Component $component, bool $print = self::PRINT_VIEW ) {
92
-		return $this->engine->component( $component, $print );
91
+	public function component(Component $component, bool $print = self::PRINT_VIEW) {
92
+		return $this->engine->component($component, $print);
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 	 * @param bool $print Print or Return the HTML
100 100
 	 * @return string|void
101 101
 	 */
102
-	public function view_model( View_Model $view_model, bool $print = self::PRINT_VIEW ) {
103
-		return $this->engine->view_model( $view_model, $print );
102
+	public function view_model(View_Model $view_model, bool $print = self::PRINT_VIEW) {
103
+		return $this->engine->view_model($view_model, $print);
104 104
 	}
105 105
 
106 106
 	/**
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 * @param callable $to_buffer
110 110
 	 * @return string
111 111
 	 */
112
-	public static function print_buffer( callable $to_buffer ): string {
112
+	public static function print_buffer(callable $to_buffer): string {
113 113
 		ob_start();
114 114
 		$to_buffer();
115 115
 		$output = ob_get_contents();
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
 	}
@@ -122,32 +122,32 @@  discard block
 block discarded – undo
122 122
 	public function process(): void {
123 123
 
124 124
 		// Filter all classes, before processing.
125
-		$class_list = apply_filters( Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list );
125
+		$class_list = apply_filters(Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list);
126 126
 
127
-		foreach ( $this->middleware as $middleware ) {
127
+		foreach ($this->middleware as $middleware) {
128 128
 
129 129
 			// Set the container if requested.
130
-			if ( is_object( $middleware ) && \method_exists( $middleware, 'set_di_container' ) ) {
131
-				$middleware->set_di_container( $this->di_container );
130
+			if (is_object($middleware) && \method_exists($middleware, 'set_di_container')) {
131
+				$middleware->set_di_container($this->di_container);
132 132
 			}
133 133
 
134 134
 			// Set the hook loader if requested.
135
-			if ( is_object( $middleware ) && \method_exists( $middleware, 'set_hook_loader' ) && ! is_null( $this->loader ) ) {
136
-				$middleware->set_hook_loader( $this->loader );
135
+			if (is_object($middleware) && \method_exists($middleware, 'set_hook_loader') && ! is_null($this->loader)) {
136
+				$middleware->set_hook_loader($this->loader);
137 137
 			}
138 138
 
139 139
 			// Run middleware setup
140 140
 			$middleware->setup();
141 141
 
142 142
 			// Pass each class to the middleware.
143
-			foreach ( $class_list as $class ) {
143
+			foreach ($class_list as $class) {
144 144
 
145 145
 				// Construct class using container,
146
-				$class_instance = $this->di_container->create( $class );
146
+				$class_instance = $this->di_container->create($class);
147 147
 
148 148
 				// if valid object process via current middleware
149
-				if ( is_object( $class_instance ) ) {
150
-					$middleware->process( $class_instance );
149
+				if (is_object($class_instance)) {
150
+					$middleware->process($class_instance);
151 151
 				}
152 152
 			}
153 153
 
Please login to merge, or discard this patch.