Migration_Exception   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A failed_to_construct_migration() 0 3 1
A none_migration_type() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Custom exceptions when creating Migrations.
7
 *
8
 * @package PinkCrab\Perique\Migration\Plugin_Lifecycle
9
 * @author Glynn Quelch [email protected]
10
 * @since 0.0.1
11
 */
12
13
namespace PinkCrab\Perique\Migration;
14
15
use Exception;
16
use Throwable;
17
18
class Migration_Exception extends Exception {
19
20
	/**
21
	 * Returns an exception if a migration can not constructed with DI.
22
	 * @code 101
23
	 * @return Migration_Exception
24
	 */
25
	public static function failed_to_construct_migration( string $migration_class_name ): Migration_Exception {
26
		$message = \sprintf( 'Failed to construct %s using the DI Container', $migration_class_name );
27
		return new Migration_Exception( $message, 101 );
28
	}
29
30
	/**
31
	 * Returns an exception for a none Migration (string class name or instance) type
32
	 * @code 102
33
	 * @param string $var
34
	 * @return Migration_Exception
35
	 */
36
	public static function none_migration_type( string $var ): Migration_Exception {
37
		$message = \sprintf(
38
			'Only valid Migration Class names can be passed as migrations, "%s" was passed to Perique_Migrations::add_module()',
39
			esc_attr( $var )
40
		);
41
		return new Migration_Exception( $message, 102 );
42
	}
43
}
44