Completed
Push — master ( a4ba22...5297ca )
by Glynn
09:37 queued 09:34
created
src/Interfaces/DI_Container.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 * @param array<string, 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
 block discarded – undo
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
 block discarded – undo
53 53
 	 * @param array<mixed> $args
54 54
 	 * @return object|null
55 55
 	 */
56
-	public function create( string $name, array $args = array() ): ?object;
56
+	public function create(string $name, array $args = array()): ?object;
57 57
 }
Please login to merge, or discard this patch.
src/Interfaces/Registration_Middleware.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 	 * @param T $class
38 38
 	 * @return T
39 39
 	 */
40
-	public function process( object $class ): object;
40
+	public function process(object $class): object;
41 41
 
42 42
 	/**
43 43
 	 * Used to for any middleware setup before process is called
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 array $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/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 array $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/Dice/PinkCrab_Dice.php 1 patch
Spacing   +21 added lines, -21 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 ): ?object {
68
-		if ( ! $this->has( $id ) ) {
69
-			throw new DI_Container_Exception( "{$id} not defined in container", 1 );
67
+	public function get(string $id): ?object {
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,8 +125,8 @@  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() ): ?object {
129
-		return $this->dice->create( $name, $args );
128
+	public function create(string $name, array $args = array()): ?object {
129
+		return $this->dice->create($name, $args);
130 130
 	}
131 131
 
132 132
 	/**
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	 * @param string $name
136 136
 	 * @return array<mixed>
137 137
 	 */
138
-	public function getRule( string $name ): ?array {
139
-		return $this->dice->getRule( $name );
138
+	public function getRule(string $name): ?array {
139
+		return $this->dice->getRule($name);
140 140
 	}
141 141
 }
Please login to merge, or discard this patch.
src/Services/Registration/Registration_Service.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	protected DI_Container $di_container;
55 55
 
56
-	public function __construct( DI_Container $di_container ) {
56
+	public function __construct(DI_Container $di_container) {
57 57
 		$this->di_container = $di_container;
58 58
 	}
59 59
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 * @param Registration_Middleware $middleware
64 64
 	 * @return self
65 65
 	 */
66
-	public function push_middleware( Registration_Middleware $middleware ): self {
67
-		$this->middleware[ \get_class( $middleware ) ] = $middleware;
66
+	public function push_middleware(Registration_Middleware $middleware): self {
67
+		$this->middleware[\get_class($middleware)] = $middleware;
68 68
 		return $this;
69 69
 	}
70 70
 
@@ -73,15 +73,15 @@  discard block
 block discarded – undo
73 73
 	 * @template Class_Name of object
74 74
 	 * @param class-string<Class_Name> $class
75 75
 	 */
76
-	public function push_class( string $class ): self {
76
+	public function push_class(string $class): self {
77 77
 		// If the class is already in the list, skip.
78
-		if ( \in_array( $class, $this->class_list, true ) ) {
78
+		if (\in_array($class, $this->class_list, true)) {
79 79
 			return $this;
80 80
 		}
81 81
 
82 82
 		// If $class is not a class, throw exception.
83
-		if ( ! \class_exists( $class ) ) {
84
-			throw Module_Manager_Exception::none_class_string_passed_to_registration( $class );
83
+		if ( ! \class_exists($class)) {
84
+			throw Module_Manager_Exception::none_class_string_passed_to_registration($class);
85 85
 		}
86 86
 
87 87
 		$this->class_list[] = $class;
@@ -95,25 +95,25 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function process(): void {
97 97
 		// Filter all classes, before processing.
98
-		$class_list = apply_filters( Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list );
98
+		$class_list = apply_filters(Hooks::APP_INIT_REGISTRATION_CLASS_LIST, $this->class_list);
99 99
 
100 100
 		// If class list is empty, skip.
101
-		if ( empty( $class_list ) ) {
101
+		if (empty($class_list)) {
102 102
 			return;
103 103
 		}
104 104
 
105
-		foreach ( $this->middleware as $middleware ) {
105
+		foreach ($this->middleware as $middleware) {
106 106
 			// Run middleware setup
107 107
 			$middleware->setup();
108 108
 
109 109
 			// Pass each class to the middleware.
110
-			foreach ( $class_list as $class ) {
110
+			foreach ($class_list as $class) {
111 111
 				// Construct class using container,
112
-				$class_instance = $this->di_container->create( $class );
112
+				$class_instance = $this->di_container->create($class);
113 113
 
114 114
 				// if valid object process via current middleware
115
-				if ( is_object( $class_instance ) ) {
116
-					$middleware->process( $class_instance );
115
+				if (is_object($class_instance)) {
116
+					$middleware->process($class_instance);
117 117
 				}
118 118
 			}
119 119
 
Please login to merge, or discard this patch.
src/Services/Registration/Modules/Hookable_Module.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 * @pram DI_Container $di_container
52 52
 	 * @return void
53 53
 	 */
54
-	public function pre_boot( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {
54
+	public function pre_boot(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {
55 55
 	}
56 56
 
57 57
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 * @pram DI_Container $di_container
64 64
 	 * @return void
65 65
 	 */
66
-	public function pre_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {
66
+	public function pre_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {
67 67
 	}
68 68
 
69 69
 	/**
@@ -74,6 +74,6 @@  discard block
 block discarded – undo
74 74
 	 * @pram DI_Container $di_container
75 75
 	 * @return void
76 76
 	 */
77
-	public function post_register( App_Config $config, Hook_Loader $loader, DI_Container $di_container ): void {
77
+	public function post_register(App_Config $config, Hook_Loader $loader, DI_Container $di_container): void {
78 78
 	}
79 79
 }
Please login to merge, or discard this patch.
src/Services/Registration/Modules/Hookable_Middleware.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@
 block discarded – undo
41 41
 	 * @param object $class
42 42
 	 * @return object
43 43
 	 */
44
-	public function process( object $class ): object {
45
-		if ( in_array( Hookable::class, class_implements( $class ) ?: array(), true ) ) {
44
+	public function process(object $class): object {
45
+		if (in_array(Hookable::class, class_implements($class) ?: array(), true)) {
46 46
 			/** @phpstan-ignore-next-line class must implement register for interface*/
47
-			$class->register( $this->loader );
47
+			$class->register($this->loader);
48 48
 		}
49 49
 		return $class;
50 50
 	}
Please login to merge, or discard this patch.
src/Services/Registration/Module_Manager.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 *
68 68
 	 * @param DI_Container $di_container
69 69
 	 */
70
-	public function __construct( DI_Container $di_container, Registration_Service $registration_service ) {
70
+	public function __construct(DI_Container $di_container, Registration_Service $registration_service) {
71 71
 		$this->di_container = $di_container;
72 72
 
73 73
 		// Create the registration service.
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	 * @param ?callable(Module, ?Registration_Middleware):Module $config
83 83
 	 * @return void
84 84
 	 */
85
-	public function push_module( string $module_name, ?callable $config = null ): void {
86
-		$this->modules[] = array( $module_name, $config );
85
+	public function push_module(string $module_name, ?callable $config = null): void {
86
+		$this->modules[] = array($module_name, $config);
87 87
 	}
88 88
 
89 89
 	/**
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @param class-string $class
93 93
 	 */
94
-	public function register_class( string $class ): void {
95
-		$this->registration_service->push_class( $class );
94
+	public function register_class(string $class): void {
95
+		$this->registration_service->push_class($class);
96 96
 	}
97 97
 
98 98
 	/**
@@ -104,26 +104,26 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	public function register_modules(): void {
106 106
 		// Allow for additional apps to hook into the Module Manager.
107
-		do_action( Hooks::MODULE_MANAGER, $this );
107
+		do_action(Hooks::MODULE_MANAGER, $this);
108 108
 
109
-		foreach ( $this->modules as list($module_name, $config) ) {
109
+		foreach ($this->modules as list($module_name, $config)) {
110 110
 			// Create the instance.
111
-			$module = $this->create_module( $module_name );
111
+			$module = $this->create_module($module_name);
112 112
 
113 113
 			// Create the middleware.
114
-			$middleware = $this->create_middleware( $module );
114
+			$middleware = $this->create_middleware($module);
115 115
 
116 116
 			// If a config is provided, call it.
117
-			if ( ! is_null( $config ) ) {
118
-				$module = $config( $module, $middleware );
117
+			if ( ! is_null($config)) {
118
+				$module = $config($module, $middleware);
119 119
 			}
120 120
 
121 121
 			// Add to the modules and register all hooks.
122
-			$this->register_hooks( $module );
122
+			$this->register_hooks($module);
123 123
 
124 124
 			// Add to the middleware, if provided.
125
-			if ( ! is_null( $middleware ) ) {
126
-				$this->registration_service->push_middleware( $middleware );
125
+			if ( ! is_null($middleware)) {
126
+				$this->registration_service->push_middleware($middleware);
127 127
 			}
128 128
 		}
129 129
 	}
@@ -134,14 +134,14 @@  discard block
 block discarded – undo
134 134
 	 * @param class-string<Module> $module
135 135
 	 * @return Module
136 136
 	 */
137
-	private function create_module( string $module ): Module {
138
-		$instance = $this->di_container->create( $module );
137
+	private function create_module(string $module): Module {
138
+		$instance = $this->di_container->create($module);
139 139
 
140 140
 		// If not an object or not an instance of the module interface, throw.
141
-		if ( ! is_object( $instance )
142
-		|| ! is_a( $instance, Module::class, true )
141
+		if ( ! is_object($instance)
142
+		|| ! is_a($instance, Module::class, true)
143 143
 		) {
144
-			throw Module_Manager_Exception::invalid_module_class_name( $module );
144
+			throw Module_Manager_Exception::invalid_module_class_name($module);
145 145
 		}
146 146
 
147 147
 		return $instance;
@@ -153,27 +153,27 @@  discard block
 block discarded – undo
153 153
 	 * @param Module $module
154 154
 	 * @return Registration_Middleware|null
155 155
 	 */
156
-	private function create_middleware( Module $module ): ?Registration_Middleware {
156
+	private function create_middleware(Module $module): ?Registration_Middleware {
157 157
 		$middleware = $module->get_middleware();
158 158
 
159 159
 		// If no middleware is provided, return null.
160
-		if ( is_null( $middleware ) ) {
160
+		if (is_null($middleware)) {
161 161
 			return null;
162 162
 		}
163 163
 
164 164
 		// If not an object or not an instance of the module interface, throw.
165
-		if ( ! is_a( $middleware, Registration_Middleware::class, true ) ) {
166
-			throw Module_Manager_Exception::invalid_registration_middleware( $middleware );
165
+		if ( ! is_a($middleware, Registration_Middleware::class, true)) {
166
+			throw Module_Manager_Exception::invalid_registration_middleware($middleware);
167 167
 		}
168 168
 
169 169
 		// Create the middleware.
170
-		$middleware = $this->di_container->create( $middleware );
170
+		$middleware = $this->di_container->create($middleware);
171 171
 
172 172
 		// If the middleware is not an object, throw.
173
-		if ( ! is_object( $middleware )
174
-		|| ! is_a( $middleware, Registration_Middleware::class, true )
173
+		if ( ! is_object($middleware)
174
+		|| ! is_a($middleware, Registration_Middleware::class, true)
175 175
 		) {
176
-			throw Module_Manager_Exception::failed_to_create_registration_middleware( $middleware );
176
+			throw Module_Manager_Exception::failed_to_create_registration_middleware($middleware);
177 177
 		}
178 178
 
179 179
 		return $middleware;
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
 	 * @param Module $module
186 186
 	 * @return void
187 187
 	 */
188
-	private function register_hooks( Module $module ): void {
189
-		add_action( Hooks::APP_INIT_PRE_BOOT, array( $module, 'pre_boot' ), 10, 3 );
190
-		add_action( Hooks::APP_INIT_PRE_REGISTRATION, array( $module, 'pre_register' ), 10, 3 );
191
-		add_action( Hooks::APP_INIT_POST_REGISTRATION, array( $module, 'post_register' ), 10, 3 );
188
+	private function register_hooks(Module $module): void {
189
+		add_action(Hooks::APP_INIT_PRE_BOOT, array($module, 'pre_boot'), 10, 3);
190
+		add_action(Hooks::APP_INIT_PRE_REGISTRATION, array($module, 'pre_register'), 10, 3);
191
+		add_action(Hooks::APP_INIT_POST_REGISTRATION, array($module, 'post_register'), 10, 3);
192 192
 	}
193 193
 
194 194
 	/**
Please login to merge, or discard this patch.