@@ -28,19 +28,19 @@ discard block |
||
| 28 | 28 | * @throws Exception |
| 29 | 29 | */ |
| 30 | 30 | protected static function validateClassMethod(string $class_name, string $name): void{ |
| 31 | - if(self::isPrototypeable($class_name)){ |
|
| 31 | + if (self::isPrototypeable($class_name)) { |
|
| 32 | 32 | self::$methods[$class_name] ??= []; |
| 33 | 33 | self::$static_methods[$class_name] ??= []; |
| 34 | - if(!method_exists($class_name, $name)){ |
|
| 35 | - if(self::classHasPrototypeMethod($class_name, $name)){ |
|
| 34 | + if (!method_exists($class_name, $name)) { |
|
| 35 | + if (self::classHasPrototypeMethod($class_name, $name)) { |
|
| 36 | 36 | throw new Exception("Invalid method name provided for class '$class_name': method '$name' is already a Prototype"); |
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | - else{ |
|
| 39 | + else { |
|
| 40 | 40 | throw new Exception("Invalid method name provided for class '$class_name': method '$name' already exists"); |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | - else{ |
|
| 43 | + else { |
|
| 44 | 44 | throw new Exception("Invalid class provided: class '$class_name' is not Prototypeable"); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | protected static function normalizeCallable($callable): Closure |
| 52 | 52 | { |
| 53 | - if(!($callable instanceof Closure)){ |
|
| 53 | + if (!($callable instanceof Closure)) { |
|
| 54 | 54 | $callable = Closure::fromCallable($callable); |
| 55 | 55 | } |
| 56 | 56 | return $callable; |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | $class_name = get_class($obj); |
| 93 | 93 | self::$methods[$class_name] ??= []; |
| 94 | - if(isset(self::$methods[$class_name][$name])){ |
|
| 94 | + if (isset(self::$methods[$class_name][$name])) { |
|
| 95 | 95 | $closure = self::$methods[$class_name][$name]; |
| 96 | 96 | return $closure->call($obj, ...$args); |
| 97 | 97 | } |
| 98 | - else{ |
|
| 98 | + else { |
|
| 99 | 99 | throw new Error("Call to undefined method $class_name::$name()"); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | public static function callStatic(string $class_name, string $name, array $args) |
| 110 | 110 | { |
| 111 | 111 | self::$static_methods[$class_name] ??= []; |
| 112 | - if(isset(self::$static_methods[$class_name][$name])){ |
|
| 112 | + if (isset(self::$static_methods[$class_name][$name])) { |
|
| 113 | 113 | $closure = self::$static_methods[$class_name][$name]; |
| 114 | 114 | return ($closure->bindTo(null, $class_name))(...$args); |
| 115 | 115 | } |
| 116 | - else{ |
|
| 116 | + else { |
|
| 117 | 117 | throw new Error("Call to undefined static method $class_name::$name()"); |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -145,14 +145,14 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | protected static function getClassTraits(string $class): array |
| 147 | 147 | { |
| 148 | - if(!class_exists($class)){ |
|
| 148 | + if (!class_exists($class)) { |
|
| 149 | 149 | throw new Exception("Class $class does not exist"); |
| 150 | 150 | } |
| 151 | 151 | $traits = []; |
| 152 | 152 | do { |
| 153 | 153 | $traits = array_merge(class_uses($class), $traits); |
| 154 | 154 | } |
| 155 | - while($class = get_parent_class($class)); |
|
| 155 | + while ($class = get_parent_class($class)); |
|
| 156 | 156 | |
| 157 | 157 | foreach ($traits as $trait) { |
| 158 | 158 | $traits = array_merge(class_uses($trait), $traits); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | final public static function addMethod(...$_): void |
| 179 | 179 | { |
| 180 | - throw new Exception('Adding normal method to '. static::class . ' does not make sense. Did you mean addStaticMethod?'); |
|
| 180 | + throw new Exception('Adding normal method to '.static::class.' does not make sense. Did you mean addStaticMethod?'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | } |
@@ -35,12 +35,10 @@ discard block |
||
| 35 | 35 | if(self::classHasPrototypeMethod($class_name, $name)){ |
| 36 | 36 | throw new Exception("Invalid method name provided for class '$class_name': method '$name' is already a Prototype"); |
| 37 | 37 | } |
| 38 | - } |
|
| 39 | - else{ |
|
| 38 | + } else{ |
|
| 40 | 39 | throw new Exception("Invalid method name provided for class '$class_name': method '$name' already exists"); |
| 41 | 40 | } |
| 42 | - } |
|
| 43 | - else{ |
|
| 41 | + } else{ |
|
| 44 | 42 | throw new Exception("Invalid class provided: class '$class_name' is not Prototypeable"); |
| 45 | 43 | } |
| 46 | 44 | } |
@@ -94,8 +92,7 @@ discard block |
||
| 94 | 92 | if(isset(self::$methods[$class_name][$name])){ |
| 95 | 93 | $closure = self::$methods[$class_name][$name]; |
| 96 | 94 | return $closure->call($obj, ...$args); |
| 97 | - } |
|
| 98 | - else{ |
|
| 95 | + } else{ |
|
| 99 | 96 | throw new Error("Call to undefined method $class_name::$name()"); |
| 100 | 97 | } |
| 101 | 98 | } |
@@ -112,8 +109,7 @@ discard block |
||
| 112 | 109 | if(isset(self::$static_methods[$class_name][$name])){ |
| 113 | 110 | $closure = self::$static_methods[$class_name][$name]; |
| 114 | 111 | return ($closure->bindTo(null, $class_name))(...$args); |
| 115 | - } |
|
| 116 | - else{ |
|
| 112 | + } else{ |
|
| 117 | 113 | throw new Error("Call to undefined static method $class_name::$name()"); |
| 118 | 114 | } |
| 119 | 115 | } |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace skrtdev\Prototypes; |
| 4 | 4 | |
| 5 | -trait Prototypeable{ |
|
| 5 | +trait Prototypeable { |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * @param string $name |