Passed
Push — master ( 9ed903...d03c9f )
by Glynn
02:34
created
src/Engines/WPDB_DB_Delta/DB_Delta_Validator.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
 	 * @param Schema $schema
46 46
 	 * @return bool
47 47
 	 */
48
-	public function validate( Schema $schema ): bool {
48
+	public function validate(Schema $schema): bool {
49 49
 		// Reset errors.
50 50
 		$this->errors = array();
51 51
 
52
-		$this->validate_columns( $schema );
53
-		$this->validate_primary_key( $schema );
54
-		$this->validate_index_columns( $schema );
55
-		$this->validate_foreign_keys( $schema );
52
+		$this->validate_columns($schema);
53
+		$this->validate_primary_key($schema);
54
+		$this->validate_index_columns($schema);
55
+		$this->validate_foreign_keys($schema);
56 56
 
57 57
 		return ! $this->has_errors();
58 58
 	}
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @return bool
73 73
 	 */
74 74
 	public function has_errors(): bool {
75
-		return count( $this->errors ) !== 0;
75
+		return count($this->errors) !== 0;
76 76
 	}
77 77
 
78 78
 	/**
@@ -80,11 +80,11 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @return void
82 82
 	 */
83
-	protected function validate_columns( Schema $schema ): void {
83
+	protected function validate_columns(Schema $schema): void {
84 84
 		$result = array_reduce(
85 85
 			$schema->get_columns(),
86
-			function( array $result, Column $column ): array {
87
-				if ( is_null( $column->get_type() ) ) {
86
+			function(array $result, Column $column): array {
87
+				if (is_null($column->get_type())) {
88 88
 					$result[] = $column;
89 89
 				}
90 90
 				return $result;
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 			array()
93 93
 		);
94 94
 
95
-		if ( count( $result ) !== 0 ) {
95
+		if (count($result) !== 0) {
96 96
 			$this->errors = array_merge(
97 97
 				$this->errors,
98 98
 				array_map(
99
-					function( Column $column ): string {
100
-						return \sprintf( 'Column "%s" has no type defined', $column->get_name() );
99
+					function(Column $column): string {
100
+						return \sprintf('Column "%s" has no type defined', $column->get_name());
101 101
 					},
102 102
 					$result
103 103
 				)
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
 	 * @param \PinkCrab\Table_Builder\Schema $schema
112 112
 	 * @return void
113 113
 	 */
114
-	protected function validate_primary_key( Schema $schema ): void {
114
+	protected function validate_primary_key(Schema $schema): void {
115 115
 
116 116
 		$primary_keys = array_filter(
117 117
 			$schema->get_indexes(),
118
-			function( Index $index ): bool {
118
+			function(Index $index): bool {
119 119
 				return $index->is_primary();
120 120
 			}
121 121
 		);
122 122
 
123
-		if ( count( $primary_keys ) > 1 ) {
124
-			$this->errors[] = \sprintf( '%d Primary keys are defined in schema, only a single primary key can be set.', count( $primary_keys ) );
123
+		if (count($primary_keys) > 1) {
124
+			$this->errors[] = \sprintf('%d Primary keys are defined in schema, only a single primary key can be set.', count($primary_keys));
125 125
 		}
126 126
 	}
127 127
 
@@ -131,21 +131,21 @@  discard block
 block discarded – undo
131 131
 	 * @param \PinkCrab\Table_Builder\Schema $schema
132 132
 	 * @return void
133 133
 	 */
134
-	protected function validate_index_columns( Schema $schema ): void {
134
+	protected function validate_index_columns(Schema $schema): void {
135 135
 		// All defined colum names.
136
-		$column_names = array_keys( $schema->get_columns() );
136
+		$column_names = array_keys($schema->get_columns());
137 137
 
138 138
 		/** @var array<Index> */
139 139
 		$missing_columns = array_filter(
140 140
 			$schema->get_indexes(),
141
-			function( Index $index ) use ( $column_names ): bool {
142
-				return ! in_array( $index->get_column(), $column_names, true );
141
+			function(Index $index) use ($column_names): bool {
142
+				return ! in_array($index->get_column(), $column_names, true);
143 143
 			}
144 144
 		);
145 145
 
146
-		if ( count( $missing_columns ) > 0 ) {
147
-			foreach ( $missing_columns as $missing_column ) {
148
-				$this->errors[] = \sprintf( 'Index column %s not defined as a column in schema', $missing_column->get_column() );
146
+		if (count($missing_columns) > 0) {
147
+			foreach ($missing_columns as $missing_column) {
148
+				$this->errors[] = \sprintf('Index column %s not defined as a column in schema', $missing_column->get_column());
149 149
 			}
150 150
 		}
151 151
 	}
@@ -156,23 +156,23 @@  discard block
 block discarded – undo
156 156
 	 * @param \PinkCrab\Table_Builder\Schema $schema
157 157
 	 * @return void
158 158
 	 */
159
-	public function validate_foreign_keys( Schema $schema ): void {
159
+	public function validate_foreign_keys(Schema $schema): void {
160 160
 		// All defined colum names.
161
-		$column_names = array_keys( $schema->get_columns() );
161
+		$column_names = array_keys($schema->get_columns());
162 162
 
163 163
 		// Missing columns in local table
164 164
 
165 165
 		/** @var array<Foreign_Key> */
166 166
 		$missing_columns = array_filter(
167 167
 			$schema->get_foreign_keys(),
168
-			function( Foreign_Key $foreign_key ) use ( $column_names ): bool {
169
-				return ! in_array( $foreign_key->get_column(), $column_names, true );
168
+			function(Foreign_Key $foreign_key) use ($column_names): bool {
169
+				return ! in_array($foreign_key->get_column(), $column_names, true);
170 170
 			}
171 171
 		);
172 172
 
173
-		if ( count( $missing_columns ) > 0 ) {
174
-			foreach ( $missing_columns as $missing_column ) {
175
-				$this->errors[] = \sprintf( 'Foreign Keys column %s not defined as a column in schema', $missing_column->get_column() );
173
+		if (count($missing_columns) > 0) {
174
+			foreach ($missing_columns as $missing_column) {
175
+				$this->errors[] = \sprintf('Foreign Keys column %s not defined as a column in schema', $missing_column->get_column());
176 176
 			}
177 177
 		}
178 178
 
@@ -181,14 +181,14 @@  discard block
 block discarded – undo
181 181
 		/** @var array<Foreign_Key> */
182 182
 		$missing_references = array_filter(
183 183
 			$schema->get_foreign_keys(),
184
-			function( Foreign_Key $foreign_key ) : bool {
184
+			function(Foreign_Key $foreign_key) : bool {
185 185
 				return $foreign_key->get_reference_table() === null || $foreign_key->get_reference_column() === null;
186 186
 			}
187 187
 		);
188 188
 
189
-		if ( count( $missing_references ) > 0 ) {
190
-			foreach ( $missing_references as $missing_reference ) {
191
-				$this->errors[] = \sprintf( 'Foreign Keys column %s has missing reference table or column details', $missing_reference->get_key_name() );
189
+		if (count($missing_references) > 0) {
190
+			foreach ($missing_references as $missing_reference) {
191
+				$this->errors[] = \sprintf('Foreign Keys column %s has missing reference table or column details', $missing_reference->get_key_name());
192 192
 			}
193 193
 		}
194 194
 	}
Please login to merge, or discard this patch.
src/Builder.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	protected $engine;
40 40
 
41
-	public function __construct( Engine $engine, ?callable $engine_config = null ) {
41
+	public function __construct(Engine $engine, ?callable $engine_config = null) {
42 42
 		$this->engine = $engine_config
43
-			? $engine_config( $engine )
43
+			? $engine_config($engine)
44 44
 			: $engine;
45 45
 	}
46 46
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 * @param Schema $schema
51 51
 	 * @return bool
52 52
 	 */
53
-	public function create_table( Schema $schema ): bool {
54
-		return $this->engine->create_table( $schema );
53
+	public function create_table(Schema $schema): bool {
54
+		return $this->engine->create_table($schema);
55 55
 	}
56 56
 
57 57
 	/**
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	 * @param Schema $schema
61 61
 	 * @return bool
62 62
 	 */
63
-	public function drop_table( Schema $schema ): bool {
64
-		return $this->engine->drop_table( $schema );
63
+	public function drop_table(Schema $schema): bool {
64
+		return $this->engine->drop_table($schema);
65 65
 	}
66 66
 
67 67
 	/**
Please login to merge, or discard this patch.
src/Foreign_Key.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	protected $on_delete = '';
81 81
 
82
-	public function __construct( string $column, ?string $key_name = null ) {
83
-		$this->key_name = $key_name ?? 'fk_' . $column;
82
+	public function __construct(string $column, ?string $key_name = null) {
83
+		$this->key_name = $key_name ?? 'fk_'.$column;
84 84
 		$this->column   = $column;
85 85
 	}
86 86
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @param string $reference_column
92 92
 	 * @return self
93 93
 	 */
94
-	public function reference( string $reference_table, string $reference_column ): self {
94
+	public function reference(string $reference_table, string $reference_column): self {
95 95
 		$this->reference_column = $reference_column;
96 96
 		$this->reference_table  = $reference_table;
97 97
 		return $this;
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @param string $reference_table
105 105
 	 * @return self
106 106
 	 */
107
-	public function reference_table( string $reference_table ): self {
107
+	public function reference_table(string $reference_table): self {
108 108
 		$this->reference_table = $reference_table;
109 109
 		return $this;
110 110
 	}
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 * @param string $reference_column
117 117
 	 * @return self
118 118
 	 */
119
-	public function reference_column( string $reference_column ): self {
119
+	public function reference_column(string $reference_column): self {
120 120
 		$this->reference_column = $reference_column;
121 121
 		return $this;
122 122
 	}
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @param string $action
129 129
 	 * @return self
130 130
 	 */
131
-	public function on_update( string $action ): self {
131
+	public function on_update(string $action): self {
132 132
 		$this->on_update = $action;
133 133
 		return $this;
134 134
 	}
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * @param string $action
142 142
 	 * @return self
143 143
 	 */
144
-	public function on_delete( string $action ): self {
144
+	public function on_delete(string $action): self {
145 145
 		$this->on_delete = $action;
146 146
 		return $this;
147 147
 	}
Please login to merge, or discard this patch.