Skip to content

Commit 97965e6

Browse files
committed
Add more throws and generics
1 parent 008082b commit 97965e6

File tree

7 files changed

+38
-9
lines changed

7 files changed

+38
-9
lines changed

src/Schema/Activation.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Activation {
3232
* Handles the activation of the feature functions.
3333
*
3434
* @since 1.0.0
35+
*
36+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
3537
*/
3638
public static function activate() {
3739
$schema_builder = Config::get_container()->get( Builder::class);
@@ -44,6 +46,8 @@ public static function activate() {
4446
* This method will run once a day (using transients).
4547
*
4648
* @since 1.0.0
49+
*
50+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
4751
*/
4852
public static function init() {
4953
// Check if we ran recently.

src/Schema/Builder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ class Builder {
2121
/**
2222
* StellarWP\DB class.
2323
*
24-
* @var string
24+
* @var class-string<\StellarWP\DB\DB>
2525
*/
2626
protected $db;
2727

2828
/**
2929
* Constructor.
3030
*
31-
* @param string|null $db StellarWP\DB class.
31+
* @param class-string<\StellarWP\DB\DB>|null $db StellarWP\DB class.
3232
* @param object $container Container instance.
3333
*/
3434
public function __construct( $db = null, $container = null ) {
@@ -43,6 +43,8 @@ public function __construct( $db = null, $container = null ) {
4343
*
4444
* @since 1.0.0
4545
*
46+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
47+
*
4648
* @param string|null $group An optional group name to restrict the check to.
4749
*
4850
* @return bool Whether all custom tables exist or not. Does not check custom fields.
@@ -74,6 +76,8 @@ public function all_tables_exist( $group = null ) {
7476
* Trigger actions to drop the custom tables.
7577
*
7678
* @since 1.0.0
79+
*
80+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
7781
*/
7882
public function down() {
7983
/**
@@ -254,6 +258,8 @@ public function register_custom_tables_names() {
254258
*
255259
* @param bool $force Whether to force the creation or update of the tables or not.
256260
*
261+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
262+
*
257263
* @return array<mixed> A list of each creation or update result.
258264
*/
259265
public function up( $force = false ) {
@@ -286,6 +292,8 @@ public function up( $force = false ) {
286292
*
287293
* @since 1.0.0
288294
*
295+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
296+
*
289297
* @return array<mixed> A list of each creation or update result.
290298
*/
291299
public function update_blog_tables() {

src/Schema/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Config {
1515
/**
1616
* StellarWP\DB class.
1717
*
18-
* @var string
18+
* @var class-string<\StellarWP\DB\DB>
1919
*/
2020
private static $db_class;
2121

@@ -35,7 +35,7 @@ public static function get_container() : ContainerInterface {
3535
/**
3636
* Get the StellarWP\DB class.
3737
*
38-
* @return string
38+
* @return class-string<\StellarWP\DB\DB>
3939
*/
4040
public static function get_db() : string {
4141
if ( self::$db_class === null ) {
@@ -75,7 +75,7 @@ public static function set_container( ContainerInterface $container ) {
7575
/**
7676
* Set the StellarWP\DB class.
7777
*
78-
* @param string $db_class StellarWP\DB class.
78+
* @param class-string<\StellarWP\DB\DB> $db_class StellarWP\DB class.
7979
*/
8080
public static function set_db( string $db_class ) {
8181
self::$db_class = $db_class;

src/Schema/Fields/Contracts/Field.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @package StellarWP\Schema\Fields\Contracts
2121
*/
2222
abstract class Field implements Schema_Interface {
23+
2324
/**
2425
* @since 1.0.0
2526
*
@@ -40,7 +41,7 @@ abstract class Field implements Schema_Interface {
4041
protected $container;
4142

4243
/**
43-
* @var string The db class.
44+
* @var class-string<\StellarWP\DB\DB> The db class.
4445
*/
4546
protected $db;
4647

@@ -68,7 +69,7 @@ abstract class Field implements Schema_Interface {
6869
*
6970
* @since 1.0.0
7071
*
71-
* @param string $db StellarWP\DB object.
72+
* @param class-string<\StellarWP\DB\DB>|null $db StellarWP\DB object.
7273
* @param object $container The container to use.
7374
*/
7475
public function __construct( $db = null, $container = null ) {
@@ -178,10 +179,11 @@ public function drop() {
178179
*
179180
* @since 1.0.0
180181
*
182+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
183+
*
181184
* @return bool Whether a set of fields exists in the database or not.
182185
*/
183186
public function exists() {
184-
global $wpdb;
185187
$table_schema = $this->table_schema();
186188

187189
if ( $table_schema === null ) {

src/Schema/Fields/Contracts/Schema_Interface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function after_update( array $results );
3737
*
3838
* @since 1.0.0
3939
*
40+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
41+
*
4042
* @return bool `true` if successful operation, `false` to indicate a failure.
4143
*/
4244
public function drop();

src/Schema/Register.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
* A helper class for registering StellarWP Schema resources.
1212
*/
1313
class Register {
14+
1415
/**
1516
* Register a field schema.
1617
*
1718
* @since 1.0.0
1819
*
1920
* @param string|Fields\Contracts\Field $field Field class.
2021
*
22+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
23+
*
2124
* @return Fields\Contracts\Schema_Interface
2225
*/
2326
public static function field( $field ) {
@@ -46,6 +49,8 @@ public static function field( $field ) {
4649
*
4750
* @param array<mixed> $fields Fields to register.
4851
*
52+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
53+
*
4954
* @return Fields\Collection
5055
*/
5156
public static function fields( array $fields ) {
@@ -63,6 +68,8 @@ public static function fields( array $fields ) {
6368
*
6469
* @param string|Fields\Contracts\Schema_Interface $field Field Schema class.
6570
*
71+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
72+
*
6673
* @return Fields\Contracts\Schema_Interface
6774
*/
6875
public static function remove_field( $field ) {
@@ -89,6 +96,8 @@ public static function remove_field( $field ) {
8996
*
9097
* @param string|Tables\Contracts\Schema_Interface $table Table Schema class.
9198
*
99+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
100+
*
92101
* @return Tables\Contracts\Schema_Interface
93102
*/
94103
public static function remove_table( $table ) {
@@ -115,6 +124,8 @@ public static function remove_table( $table ) {
115124
*
116125
* @param string|Tables\Contracts\Table $table Table class.
117126
*
127+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
128+
*
118129
* @return Tables\Contracts\Schema_Interface
119130
*/
120131
public static function table( $table ) {
@@ -143,6 +154,8 @@ public static function table( $table ) {
143154
*
144155
* @param array<mixed> $tables Tables to register.
145156
*
157+
* @throws \StellarWP\DB\Database\Exceptions\DatabaseQueryException If the query fails.
158+
*
146159
* @return Tables\Collection
147160
*/
148161
public static function tables( array $tables ) {

src/Schema/Tables/Contracts/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ abstract class Table implements Schema_Interface {
6363
*
6464
* @since 1.0.0
6565
*
66-
* @param class-string<\StellarWP\DB\DB> $db StellarWP\DB object.
66+
* @param class-string<\StellarWP\DB\DB>|null $db StellarWP\DB object.
6767
* @param object $container The container to use.
6868
*/
6969
public function __construct( $db = null, $container = null ) {

0 commit comments

Comments
 (0)