Completed
Push — develop ( 844154...ac08d5 )
by David
02:57 queued 11s
created

Assertions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A assert_of_type() 0 14 3
1
<?php
2
/**
3
 * This file provides a set of methods to check values.
4
 *
5
 * The main aim is to provide helpful methods to constructors and methods to validate the incoming arguments.
6
 *
7
 * @author David Riccitelli <[email protected]>
8
 * @package Wordlift
9
 * @since 3.26.0
10
 */
11
12
namespace Wordlift;
13
14
use Exception;
15
16
class Assertions {
17
18
	/**
19
	 * Asserts that the provided value is of the specified type.
20
	 *
21
	 * @param mixed $value The value to test.
22
	 * @param string $type The expected type.
23
	 *
24
	 * @throws Exception
25
	 */
26
	public static function assert_of_type( $value, $type ) {
27
28
		// Check for nulls.
29
		if ( null === $value ) {
30
			throw new Exception( 'Value can`t be null.' );
31
		}
32
33
		// Check for type.
34
		if ( get_class( $value ) !== $type ) {
35
			echo "Value must be a $type.";
36
			throw new Exception( "Value must be a $type." );
37
		}
38
39
	}
40
41
}