Completed
Pull Request — staging (#840)
by
unknown
19:58
created

InvalidClass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A from_interface() 0 7 1
A not_found() 0 6 1
A mismatch() 0 7 1
1
<?php
2
/**
3
 * YIKES Inc. Easy Mailchimp Forms Plugin.
4
 *
5
 * @package   YIKES\EasyForms
6
 * @author    Freddie Mixell
7
 * @license   GPL2
8
 */
9
10
namespace YIKES\EasyForms\Exception;
11
12
use InvalidArgumentException;
13
14
/**
15
 * Class InvalidClass
16
 *
17
 * @since   %VERSION%
18
 * @package YIKES\EasyForms
19
 */
20
class InvalidClass extends InvalidArgumentException implements Exception {
21
22
	/**
23
	 * Return new instance of this exception when a class does not implement the necessary interface.
24
	 *
25
	 * @since %VERSION%
26
	 *
27
	 * @param string $class     The invalid class name.
28
	 * @param string $interface The interface that the class should implement.
29
	 *
30
	 * @return static
31
	 */
32
	public static function from_interface( $class, $interface ) {
33
		return new static( sprintf(
34
			'The "%s" class must implement the "%s" interface.',
35
			$class,
36
			$interface
37
		) );
38
	}
39
40
	/**
41
	 * Return a new instance of this exception when a class is not found.
42
	 *
43
	 * @since %VERSION%
44
	 *
45
	 * @param string $class The invalid class name.
46
	 *
47
	 * @return static
48
	 */
49
	public static function not_found( $class ) {
50
		return new static( sprintf(
51
			'The class "%s" could not be found.',
52
			$class
53
		) );
54
	}
55
56
	/**
57
	 * Return a new instance of this exception when we expected one class but got another.
58
	 *
59
	 * @since %VERSION%
60
	 *
61
	 * @param string $class    The class name we received.
62
	 * @param string $expected The Class name we expected.
63
	 *
64
	 * @return static
65
	 */
66
	public static function mismatch( $class, $expected ) {
67
		return new static( sprintf(
68
			'Invalid class "%s". The "%s" class was expected.',
69
			$class,
70
			$expected
71
		) );
72
	}
73
}
74