Passed
Push — master ( 6783b1...482d87 )
by Gaetano
10:15
created
src/Prototypes.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -28,19 +28,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -35,12 +35,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/Prototypeable.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 namespace skrtdev\Prototypes;
4 4
 
5
-trait Prototypeable{
5
+trait Prototypeable {
6 6
 
7 7
     /**
8 8
      * @param string $name
Please login to merge, or discard this patch.
tests/StaticPrototypesTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
 
40 40
     public function testCanUseNamedArguments(): void
41 41
     {
42
-        DemoClassTest::addStaticMethod('staticMethodWithNamedArguments', function (int $named_argument){
42
+        DemoClassTest::addStaticMethod('staticMethodWithNamedArguments', function(int $named_argument) {
43 43
             return $named_argument;
44 44
         });
45 45
         $this->assertEquals(12, DemoClassTest::staticMethodWithNamedArguments(named_argument: 12));
Please login to merge, or discard this patch.
tests/PrototypesTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
 
45 45
     public function testCanUseNamedArguments(): void
46 46
     {
47
-        DemoClassTest::addMethod('methodWithNamedArguments', function (int $named_argument){
47
+        DemoClassTest::addMethod('methodWithNamedArguments', function(int $named_argument) {
48 48
             return $named_argument;
49 49
         });
50 50
         $this->assertEquals(12, (new DemoClassTest)->methodWithNamedArguments(named_argument: 12));
Please login to merge, or discard this patch.