@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | use Exception, ReflectionClass; |
| 16 | 16 | |
| 17 | -trait ClassLoader{ |
|
| 17 | +trait ClassLoader { |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Instances an object of $class/$type with an arbitrary number of $params |
@@ -27,51 +27,51 @@ discard block |
||
| 27 | 27 | * @return mixed of type $type |
| 28 | 28 | * @throws \Exception |
| 29 | 29 | */ |
| 30 | - public function loadClass(string $class, string $type = null, ...$params){ |
|
| 30 | + public function loadClass(string $class, string $type = null, ...$params) { |
|
| 31 | 31 | $type = $type ?? $class; |
| 32 | 32 | |
| 33 | - try{ |
|
| 33 | + try { |
|
| 34 | 34 | $reflectionClass = new ReflectionClass($class); |
| 35 | 35 | $reflectionType = new ReflectionClass($type); |
| 36 | 36 | } |
| 37 | - catch(Exception $e){ |
|
| 37 | + catch (Exception $e) { |
|
| 38 | 38 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
| 42 | - if($reflectionType->isTrait()){ |
|
| 42 | + if ($reflectionType->isTrait()) { |
|
| 43 | 43 | throw new TraitException($class.' cannot be an instance of trait '.$type); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if($reflectionClass->isAbstract()){ |
|
| 46 | + if ($reflectionClass->isAbstract()) { |
|
| 47 | 47 | throw new TraitException('cannot instance abstract class '.$class); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - if($reflectionClass->isTrait()){ |
|
| 50 | + if ($reflectionClass->isTrait()) { |
|
| 51 | 51 | throw new TraitException('cannot instance trait '.$class); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if($class !== $type){ |
|
| 54 | + if ($class !== $type) { |
|
| 55 | 55 | |
| 56 | - if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){ |
|
| 56 | + if ($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)) { |
|
| 57 | 57 | throw new TraitException($class.' does not implement '.$type); |
| 58 | 58 | } |
| 59 | - elseif(!$reflectionClass->isSubclassOf($type)) { |
|
| 59 | + elseif (!$reflectionClass->isSubclassOf($type)) { |
|
| 60 | 60 | throw new TraitException($class.' does not inherit '.$type); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - try{ |
|
| 65 | + try { |
|
| 66 | 66 | $object = $reflectionClass->newInstanceArgs($params); |
| 67 | 67 | |
| 68 | - if(!$object instanceof $type){ |
|
| 68 | + if (!$object instanceof $type) { |
|
| 69 | 69 | throw new TraitException('how did u even get here?'); // @codeCoverageIgnore |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | return $object; |
| 73 | 73 | } |
| 74 | - catch(Exception $e){ |
|
| 74 | + catch (Exception $e) { |
|
| 75 | 75 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -33,8 +33,7 @@ discard block |
||
| 33 | 33 | try{ |
| 34 | 34 | $reflectionClass = new ReflectionClass($class); |
| 35 | 35 | $reflectionType = new ReflectionClass($type); |
| 36 | - } |
|
| 37 | - catch(Exception $e){ |
|
| 36 | + } catch(Exception $e){ |
|
| 38 | 37 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
| 39 | 38 | } |
| 40 | 39 | |
@@ -55,8 +54,7 @@ discard block |
||
| 55 | 54 | |
| 56 | 55 | if($reflectionType->isInterface() && !$reflectionClass->implementsInterface($type)){ |
| 57 | 56 | throw new TraitException($class.' does not implement '.$type); |
| 58 | - } |
|
| 59 | - elseif(!$reflectionClass->isSubclassOf($type)) { |
|
| 57 | + } elseif(!$reflectionClass->isSubclassOf($type)) { |
|
| 60 | 58 | throw new TraitException($class.' does not inherit '.$type); |
| 61 | 59 | } |
| 62 | 60 | |
@@ -70,8 +68,7 @@ discard block |
||
| 70 | 68 | } |
| 71 | 69 | |
| 72 | 70 | return $object; |
| 73 | - } |
|
| 74 | - catch(Exception $e){ |
|
| 71 | + } catch(Exception $e){ |
|
| 75 | 72 | throw new TraitException('ClassLoader: '.$e->getMessage()); |
| 76 | 73 | } |
| 77 | 74 | |