Issues (6)

src/Factory.php (2 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Factory for a quick and clean setup.
7
 *
8
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
10
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
15
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
16
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
17
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
18
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
 *
20
 * @author Glynn Quelch <[email protected]>
21
 * @license http://www.opensource.org/licenses/mit-license.html  MIT License
22
 * @package PinkCrab\DB_Migration
23
 */
24
25
namespace PinkCrab\DB_Migration;
26
27
use wpdb;
28
use PinkCrab\Table_Builder\Builder;
29
use PinkCrab\DB_Migration\Log\Migration_Log_Manager;
30
use PinkCrab\Table_Builder\Engines\WPDB_DB_Delta\DB_Delta_Engine;
31
32
class Factory {
33
34
	/**
35
	 * Creates an instace of the manager using wpdb & DB_Delta builder.
36
	 *
37
	 * @param string|null $option_key If no key passed, will use the detault defined in Migration_Log_Manager
38
	 * @param \wpdb|null $wpdb Can pass custom wpdb instance
39
	 * @return Migration_Manager
40
	 */
41
	public static function manager_with_db_delta( ?string $option_key = null, ?\wpdb $wpdb = null ): Migration_Manager {
42
		if ( $wpdb === null ) {
43
			global $wpdb;
44
		}
45
46
		$builder = new Builder( new DB_Delta_Engine( $wpdb ) );
0 ignored issues
show
It seems like $wpdb can also be of type null; however, parameter $wpdb of PinkCrab\Table_Builder\E...a_Engine::__construct() does only seem to accept wpdb, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
		$builder = new Builder( new DB_Delta_Engine( /** @scrutinizer ignore-type */ $wpdb ) );
Loading history...
47
		return new Migration_Manager( $builder, $wpdb, $option_key );
0 ignored issues
show
It seems like $wpdb can also be of type null; however, parameter $wpdb of PinkCrab\DB_Migration\Mi..._Manager::__construct() does only seem to accept wpdb, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
		return new Migration_Manager( $builder, /** @scrutinizer ignore-type */ $wpdb, $option_key );
Loading history...
48
	}
49
50
	/**
51
	 * Returns an instance of the Log Manager with a defined key.
52
	 *
53
	 * If no key passed, will use the detault defined in Migration_Log_Manager
54
	 *
55
	 * @param string|null $option_key
56
	 * @return \PinkCrab\DB_Migration\Log\Migration_Log_Manager
57
	 */
58
	public static function migration_log( ?string $option_key = null ): Migration_Log_Manager {
59
		return new Migration_Log_Manager( $option_key );
60
	}
61
}
62