Total Complexity | 6 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | class Utils |
||
16 | { |
||
17 | public static function create( string $class, array $args, string $iface = null ) : object |
||
18 | { |
||
19 | if( class_exists( $class ) === false ) { |
||
20 | throw new \LogicException( sprintf( 'Class "%1$s" not found', $class ), 400 ); |
||
21 | } |
||
22 | |||
23 | $object = new $class( ...$args ); |
||
24 | |||
25 | if( $iface && !( $object instanceof $iface ) ) { |
||
26 | throw new \LogicException( sprintf( 'Class "%1$s" does not implement "%2$s"', $class, $iface ), 400 ); |
||
27 | } |
||
28 | |||
29 | return $object; |
||
30 | } |
||
31 | |||
32 | |||
33 | public static function implements( object $object, string $iface ) : object |
||
40 | } |
||
41 | } |
||
42 |