Conditions | 4 |
Paths | 3 |
Total Lines | 13 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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 | } |
||
42 |