Completed
Push — master ( 860664...35ee95 )
by Mohamed
25s
created
src/Application.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -129,29 +129,29 @@
 block discarded – undo
129 129
         return $response instanceof Response ? $response : new Response((string)$response, 200);
130 130
     }
131 131
 
132
-    public function get(string $pattern, Closure|string $callback, ?string $routeName = null): self
132
+    public function get(string $pattern, Closure | string $callback, ?string $routeName = null): self
133 133
     {
134 134
         return $this->mount($pattern, $callback, $routeName, [Request::METHOD_GET]);
135 135
     }
136 136
 
137
-    public function post(string $pattern, Closure|string $callback, ?string $routeName = null): self
137
+    public function post(string $pattern, Closure | string $callback, ?string $routeName = null): self
138 138
     {
139 139
         return $this->mount($pattern, $callback, $routeName, [Request::METHOD_POST]);
140 140
     }
141 141
 
142
-    public function put(string $pattern, Closure|string $callback, ?string $routeName = null): self
142
+    public function put(string $pattern, Closure | string $callback, ?string $routeName = null): self
143 143
     {
144 144
         return $this->mount($pattern, $callback, $routeName, [Request::METHOD_PUT]);
145 145
     }
146 146
 
147
-    public function delete(string $pattern, Closure|string $callback, ?string $routeName = null): self
147
+    public function delete(string $pattern, Closure | string $callback, ?string $routeName = null): self
148 148
     {
149 149
         return $this->mount($pattern, $callback, $routeName, [Request::METHOD_DELETE]);
150 150
     }
151 151
 
152 152
     public function mount(
153 153
         string $pattern,
154
-        Closure|string $callback,
154
+        Closure | string $callback,
155 155
         ?string $routeName = null,
156 156
         array $methods = []
157 157
     ): self {
Please login to merge, or discard this patch.
src/Dispatcher/EventDispatcher.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -29,114 +29,114 @@
 block discarded – undo
29 29
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 30
  */
31 31
 
32
- declare(strict_types=1);
32
+    declare(strict_types=1);
33 33
 
34
- namespace Mabs\Dispatcher;
34
+    namespace Mabs\Dispatcher;
35 35
 
36
- use Closure;
37
- use Psr\Container\ContainerInterface;
36
+    use Closure;
37
+    use Psr\Container\ContainerInterface;
38 38
  
39
- final class EventDispatcher implements EventDispatcherInterface
40
- {
41
-     /** @var array<string, array<array{eventName: string, callback: callable, priority: int}>> */
42
-     private array $listeners = [];
39
+    final class EventDispatcher implements EventDispatcherInterface
40
+    {
41
+        /** @var array<string, array<array{eventName: string, callback: callable, priority: int}>> */
42
+        private array $listeners = [];
43 43
  
44
-     public function __construct(
45
-         private readonly ContainerInterface $container
46
-     ) {}
44
+        public function __construct(
45
+            private readonly ContainerInterface $container
46
+        ) {}
47 47
  
48
-     /**
49
-      * Dispatch an event to all registered listeners
50
-      *
51
-      * @param string $eventName The event to dispatch
52
-      * @param mixed $data Optional data to pass to the event listeners
53
-      * @return $this
54
-      */
55
-     public function dispatch(string $eventName, mixed $data = null): self
56
-     {
57
-         foreach ($this->getListenersByEvent($eventName) as $event) {
58
-             $event['callback']($this->container, $data);
59
-         }
48
+        /**
49
+         * Dispatch an event to all registered listeners
50
+         *
51
+         * @param string $eventName The event to dispatch
52
+         * @param mixed $data Optional data to pass to the event listeners
53
+         * @return $this
54
+         */
55
+        public function dispatch(string $eventName, mixed $data = null): self
56
+        {
57
+            foreach ($this->getListenersByEvent($eventName) as $event) {
58
+                $event['callback']($this->container, $data);
59
+            }
60 60
  
61
-         return $this;
62
-     }
61
+            return $this;
62
+        }
63 63
  
64
-     /**
65
-      * Remove all listeners for a given event
66
-      *
67
-      * @param string $eventName The event name to clear
68
-      * @return $this
69
-      */
70
-     final public function detach(string $eventName): self
71
-     {
72
-         unset($this->listeners[$eventName]);
64
+        /**
65
+         * Remove all listeners for a given event
66
+         *
67
+         * @param string $eventName The event name to clear
68
+         * @return $this
69
+         */
70
+        final public function detach(string $eventName): self
71
+        {
72
+            unset($this->listeners[$eventName]);
73 73
  
74
-         return $this;
75
-     }
74
+            return $this;
75
+        }
76 76
  
77
-     /**
78
-      * Register an event listener
79
-      *
80
-      * @param string $eventName The event to listen for
81
-      * @param callable|array|string $callback The callback to execute
82
-      * @param int $priority The priority (higher numbers execute first)
83
-      * @return $this
84
-      */
85
-     final public function register(
86
-         string $eventName,
87
-         callable|array|string $callback,
88
-         int $priority = 0
89
-     ): self {
90
-         $eventName = trim($eventName);
91
-         $this->listeners[$eventName] ??= [];
77
+        /**
78
+         * Register an event listener
79
+         *
80
+         * @param string $eventName The event to listen for
81
+         * @param callable|array|string $callback The callback to execute
82
+         * @param int $priority The priority (higher numbers execute first)
83
+         * @return $this
84
+         */
85
+        final public function register(
86
+            string $eventName,
87
+            callable|array|string $callback,
88
+            int $priority = 0
89
+        ): self {
90
+            $eventName = trim($eventName);
91
+            $this->listeners[$eventName] ??= [];
92 92
  
93
-         $this->listeners[$eventName][] = [
94
-             'eventName' => $eventName,
95
-             'callback' => $this->normalizeCallback($callback),
96
-             'priority' => $priority
97
-         ];
93
+            $this->listeners[$eventName][] = [
94
+                'eventName' => $eventName,
95
+                'callback' => $this->normalizeCallback($callback),
96
+                'priority' => $priority
97
+            ];
98 98
  
99
-         if (count($this->listeners[$eventName]) > 1) {
100
-             usort(
101
-                 $this->listeners[$eventName],
102
-                 fn(array $a, array $b): int => $b['priority'] <=> $a['priority']
103
-             );
104
-         }
99
+            if (count($this->listeners[$eventName]) > 1) {
100
+                usort(
101
+                    $this->listeners[$eventName],
102
+                    fn(array $a, array $b): int => $b['priority'] <=> $a['priority']
103
+                );
104
+            }
105 105
  
106
-         return $this;
107
-     }
106
+            return $this;
107
+        }
108 108
  
109
-     /**
110
-      * Get all registered listeners
111
-      *
112
-      * @return array<string, array<array{eventName: string, callback: callable, priority: int}>>
113
-      */
114
-     public function getListeners(): array
115
-     {
116
-         return $this->listeners;
117
-     }
109
+        /**
110
+         * Get all registered listeners
111
+         *
112
+         * @return array<string, array<array{eventName: string, callback: callable, priority: int}>>
113
+         */
114
+        public function getListeners(): array
115
+        {
116
+            return $this->listeners;
117
+        }
118 118
  
119
-     /**
120
-      * Get listeners for a specific event
121
-      *
122
-      * @param string $eventName The event name
123
-      * @return array<array{eventName: string, callback: callable, priority: int}>
124
-      */
125
-     public function getListenersByEvent(string $eventName): array
126
-     {
127
-         return $this->listeners[$eventName] ?? [];
128
-     }
119
+        /**
120
+         * Get listeners for a specific event
121
+         *
122
+         * @param string $eventName The event name
123
+         * @return array<array{eventName: string, callback: callable, priority: int}>
124
+         */
125
+        public function getListenersByEvent(string $eventName): array
126
+        {
127
+            return $this->listeners[$eventName] ?? [];
128
+        }
129 129
  
130
-     /**
131
-      * Normalize different callback formats to a callable
132
-      */
133
-     private function normalizeCallback(callable|array|string $callback): callable
134
-     {
135
-         return match (true) {
136
-             is_callable($callback) => $callback,
137
-             is_string($callback) && str_contains($callback, '::') => explode('::', $callback),
138
-             is_string($callback) => fn(ContainerInterface $c) => $c->get($callback),
139
-             default => throw new \InvalidArgumentException('Invalid callback type')
140
-         };
141
-     }
142
- }
143 130
\ No newline at end of file
131
+        /**
132
+         * Normalize different callback formats to a callable
133
+         */
134
+        private function normalizeCallback(callable|array|string $callback): callable
135
+        {
136
+            return match (true) {
137
+                is_callable($callback) => $callback,
138
+                is_string($callback) && str_contains($callback, '::') => explode('::', $callback),
139
+                is_string($callback) => fn(ContainerInterface $c) => $c->get($callback),
140
+                default => throw new \InvalidArgumentException('Invalid callback type')
141
+            };
142
+        }
143
+    }
144 144
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
       */
85 85
      final public function register(
86 86
          string $eventName,
87
-         callable|array|string $callback,
87
+         callable | array | string $callback,
88 88
          int $priority = 0
89 89
      ): self {
90 90
          $eventName = trim($eventName);
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      /**
131 131
       * Normalize different callback formats to a callable
132 132
       */
133
-     private function normalizeCallback(callable|array|string $callback): callable
133
+     private function normalizeCallback(callable | array | string $callback): callable
134 134
      {
135 135
          return match (true) {
136 136
              is_callable($callback) => $callback,
Please login to merge, or discard this patch.
src/Adapter/SessionServiceAdapter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@
 block discarded – undo
59 59
                 $c['session.storage.handler']
60 60
             );
61 61
 
62
-        $container['session'] = function (Container $app): Session {
62
+        $container['session'] = function(Container $app): Session {
63 63
             if (!isset($app['session.storage'])) {
64 64
                 $app['session.storage'] = $app['session.storage.native'];
65 65
             }
Please login to merge, or discard this patch.
src/Container/Container.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -173,21 +173,21 @@
 block discarded – undo
173 173
 
174 174
     public function offsetExists(mixed $offset): bool
175 175
     {
176
-        return $this->has((string) $offset);
176
+        return $this->has((string)$offset);
177 177
     }
178 178
 
179 179
     public function offsetGet(mixed $offset): mixed
180 180
     {
181
-        return $this->get((string) $offset);
181
+        return $this->get((string)$offset);
182 182
     }
183 183
 
184 184
     public function offsetSet(mixed $offset, mixed $value): void
185 185
     {
186
-        $this->set((string) $offset, $value);
186
+        $this->set((string)$offset, $value);
187 187
     }
188 188
 
189 189
     public function offsetUnset(mixed $offset): void
190 190
     {
191
-        $this->unset((string) $offset);
191
+        $this->unset((string)$offset);
192 192
     }
193 193
 }
Please login to merge, or discard this patch.
src/Container/ContainerNotFoundException.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@
 block discarded – undo
29 29
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 30
  */
31 31
 
32
- declare(strict_types=1);
32
+    declare(strict_types=1);
33 33
 
34
- namespace Mabs\Container;
34
+    namespace Mabs\Container;
35 35
 
36
- use Psr\Container\NotFoundExceptionInterface;
36
+    use Psr\Container\NotFoundExceptionInterface;
37 37
 
38 38
 final class ContainerNotFoundException extends \Exception implements NotFoundExceptionInterface {}
39 39
\ No newline at end of file
Please login to merge, or discard this patch.
src/Router/Router.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         $path = $route->path();
90 90
 
91 91
         foreach ($params as $key => $value) {
92
-            $path = str_replace(['{' . $key . '}', '{' . $key . '?}'], $value, $path);
92
+            $path = str_replace(['{'.$key.'}', '{'.$key.'?}'], $value, $path);
93 93
         }
94 94
 
95 95
         return $path;
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             return true;
106 106
         }
107 107
 
108
-        if (!empty($regex) && preg_match('#^' . $regex . '/?$#', $currentPath, $matches)) {
108
+        if (!empty($regex) && preg_match('#^'.$regex.'/?$#', $currentPath, $matches)) {
109 109
             $params = $route->extractParameters($matches);
110 110
             $request->query->add($params);
111 111
             return true;
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 
123 123
         return $result instanceof Response
124 124
             ? $result
125
-            : new Response((string) $result);
125
+            : new Response((string)$result);
126 126
     }
127 127
 
128 128
     private function getRouteByName(string $routeName): Route
@@ -133,6 +133,6 @@  discard block
 block discarded – undo
133 133
     private function normalizePath(string $path): string
134 134
     {
135 135
         $normalized = ltrim($path, '/');
136
-        return str_ends_with($normalized, '/') ? $normalized : $normalized . '/';
136
+        return str_ends_with($normalized, '/') ? $normalized : $normalized.'/';
137 137
     }
138 138
 }
Please login to merge, or discard this patch.
index.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@
 block discarded – undo
4 4
 
5 5
 $app = new Mabs\Application(true);
6 6
 
7
-$app->get('hello/{name}', function ($name) {
7
+$app->get('hello/{name}', function($name) {
8 8
 
9 9
     return 'Hello '.$name;
10 10
 })->run();
11 11
\ No newline at end of file
Please login to merge, or discard this patch.