registration_exists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * App initialisation exception.
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\Perique\Exceptions
23
 * @version 0.4.0
24
 */
25
26
namespace PinkCrab\Perique\Exceptions;
27
28
use Exception;
29
30
class App_Initialization_Exception extends Exception {
31
32
	/**
33
	 * Returns an exception if a DI Container is not bound to the app.
34
	 * @code 1
35
	 * @return App_Initialization_Exception
36
	 */
37
	public static function requires_di_container(): App_Initialization_Exception {
38
		$message = 'The Application must be populated with a DI_Container before booting.';
39
		return new App_Initialization_Exception( $message, 1 );
40
	}
41
42
	/**
43
	 * Returns an exception if attempting to overwrite the DI Container.
44
	 * @code 2
45
	 * @return App_Initialization_Exception
46
	 */
47
	public static function di_container_exists(): App_Initialization_Exception {
48
		$message = 'App already contains a DI Container, can not redeclare.';
49
		return new App_Initialization_Exception( $message, 2 );
50
	}
51
52
	/**
53
	 * Returns an exception if the Registration_Service is not defined.
54
	 * @code 3
55
	 * @return App_Initialization_Exception
56
	 */
57
	public static function requires_module_manager(): App_Initialization_Exception {
58
		$message = 'App has not defined Registration Service, this must be set before use.';
59
		return new App_Initialization_Exception( $message, 3 );
60
	}
61
62
	/**
63
	 * Returns an exception if App hasn't been initialised and its getters are accessed
64
	 * @code 4
65
	 * @param string $service The service which has been called without initialising the app.
66
	 * @return App_Initialization_Exception
67
	 */
68
	public static function app_not_initialized( string $service ): App_Initialization_Exception {
69
		$message = "App must be initialised before calling {$service}";
70
		return new App_Initialization_Exception( $message, 4 );
71
	}
72
73
	/**
74
	 * Returns an exception for trying to redefine the App_Config if its already been set.
75
	 * @code 5
76
	 * @return App_Initialization_Exception
77
	 */
78
	public static function app_config_exists(): App_Initialization_Exception {
79
		$message = 'Can not redeclare App_Config as its already set to the application';
80
		return new App_Initialization_Exception( $message, 5 );
81
	}
82
83
	/**
84
	 * Returns an exception for trying to redefine the Registration_Service if its already been set.
85
	 * @code 7
86
	 * @return App_Initialization_Exception
87
	 */
88
	public static function registration_exists(): App_Initialization_Exception {
89
		$message = 'Can not redeclare Registration_Service as its already set to the application';
90
		return new App_Initialization_Exception( $message, 7 );
91
	}
92
93
	/**
94
	 * Returns an exception for trying to boot application without defining required properties
95
	 * @code 6
96
	 * @param array<int,string> $errors
97
	 * @return App_Initialization_Exception
98
	 */
99
	public static function failed_boot_validation( array $errors ): App_Initialization_Exception {
100
		$message = sprintf(
101
			'App failed boot validation : %s',
102
			join( ', ', $errors )
103
		);
104
		return new App_Initialization_Exception( $message, 6 );
105
	}
106
107
	/**
108
	 * Returns an exception for trying to redefine the Loader if its already been set.
109
	 * @code 8
110
	 * @return App_Initialization_Exception
111
	 */
112
	public static function loader_exists(): App_Initialization_Exception {
113
		$message = 'Can not redeclare Loader as its already set to the application';
114
		return new App_Initialization_Exception( $message, 8 );
115
	}
116
117
	/**
118
	 * Returns an exceptions for attempting to set the Module_Manager after its already been defined.
119
	 * @cdde 10
120
	 * @return App_Initialization_Exception
121
	 */
122
	public static function module_manager_exists(): App_Initialization_Exception {
123
		$message = 'Can not redeclare Module_Manager as its already set to the application';
124
		return new App_Initialization_Exception( $message, 10 );
125
	}
126
}
127