@@ -18,21 +18,21 @@ discard block |
||
18 | 18 | |
19 | 19 | public static function addMethod(string $class_name, string $name, Closure $fun): void |
20 | 20 | { |
21 | - if(self::isPrototypeable($class_name)){ |
|
22 | - if(!method_exists($class_name, $name)){ |
|
21 | + if (self::isPrototypeable($class_name)) { |
|
22 | + if (!method_exists($class_name, $name)) { |
|
23 | 23 | self::$methods[$class_name] ??= []; |
24 | - if(!isset(self::$methods[$class_name][$name])){ |
|
24 | + if (!isset(self::$methods[$class_name][$name])) { |
|
25 | 25 | self::$methods[$class_name][$name] = $fun; |
26 | 26 | } |
27 | - else{ |
|
27 | + else { |
|
28 | 28 | throw new Exception("Invalid method name provided for class '$class_name': method '$name' is already a Prototype"); |
29 | 29 | } |
30 | 30 | } |
31 | - else{ |
|
31 | + else { |
|
32 | 32 | throw new Exception("Invalid method name provided for class '$class_name': method '$name' already exists"); |
33 | 33 | } |
34 | 34 | } |
35 | - else{ |
|
35 | + else { |
|
36 | 36 | throw new Exception("Invalid class provided: class '$class_name' is not Prototypeable"); |
37 | 37 | } |
38 | 38 | } |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | { |
42 | 42 | $class_name = get_class($obj); |
43 | 43 | self::$methods[$class_name] ??= []; |
44 | - if(isset(self::$methods[$class_name][$name])){ |
|
44 | + if (isset(self::$methods[$class_name][$name])) { |
|
45 | 45 | $closure = self::$methods[$class_name][$name]; |
46 | 46 | return $closure->call($obj, ...$args); |
47 | 47 | } |
48 | - else{ |
|
48 | + else { |
|
49 | 49 | throw new Error("Call to undefined method $class_name::$name()"); |
50 | 50 | } |
51 | 51 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | do { |
56 | 56 | $traits = array_merge(class_uses($class), $traits); |
57 | 57 | } |
58 | - while($class = get_parent_class($class)); |
|
58 | + while ($class = get_parent_class($class)); |
|
59 | 59 | |
60 | 60 | foreach ($traits as $trait) { |
61 | 61 | $traits = array_merge(class_uses($trait), $traits); |
@@ -23,16 +23,13 @@ discard block |
||
23 | 23 | self::$methods[$class_name] ??= []; |
24 | 24 | if(!isset(self::$methods[$class_name][$name])){ |
25 | 25 | self::$methods[$class_name][$name] = $fun; |
26 | - } |
|
27 | - else{ |
|
26 | + } else{ |
|
28 | 27 | throw new Exception("Invalid method name provided for class '$class_name': method '$name' is already a Prototype"); |
29 | 28 | } |
30 | - } |
|
31 | - else{ |
|
29 | + } else{ |
|
32 | 30 | throw new Exception("Invalid method name provided for class '$class_name': method '$name' already exists"); |
33 | 31 | } |
34 | - } |
|
35 | - else{ |
|
32 | + } else{ |
|
36 | 33 | throw new Exception("Invalid class provided: class '$class_name' is not Prototypeable"); |
37 | 34 | } |
38 | 35 | } |
@@ -44,8 +41,7 @@ discard block |
||
44 | 41 | if(isset(self::$methods[$class_name][$name])){ |
45 | 42 | $closure = self::$methods[$class_name][$name]; |
46 | 43 | return $closure->call($obj, ...$args); |
47 | - } |
|
48 | - else{ |
|
44 | + } else{ |
|
49 | 45 | throw new Error("Call to undefined method $class_name::$name()"); |
50 | 46 | } |
51 | 47 | } |
@@ -4,13 +4,13 @@ |
||
4 | 4 | |
5 | 5 | use Closure; |
6 | 6 | |
7 | -trait Prototypeable{ |
|
7 | +trait Prototypeable { |
|
8 | 8 | |
9 | - public function __call(string $name, array $args){ |
|
9 | + public function __call(string $name, array $args) { |
|
10 | 10 | return Prototypes::call($this, $name, $args); |
11 | 11 | } |
12 | 12 | |
13 | - final public static function addMethod(string $name, Closure $fun){ |
|
13 | + final public static function addMethod(string $name, Closure $fun) { |
|
14 | 14 | return Prototypes::addMethod(static::class, $name, $fun); |
15 | 15 | } |
16 | 16 | } |