Passed
Push — main ( 3df0d9...eddb6f )
by Jacobo
02:44
created
src/Adapters/OpenAIAdapter.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
         ?array $options = null
28 28
     ): array {
29 29
         if (!$this->isEnabled()) {
30
-            return ['success' => false, 'error' => 'OpenAI adapter not enabled'];
30
+            return [ 'success' => false, 'error' => 'OpenAI adapter not enabled' ];
31 31
         }
32 32
 
33 33
         $model ??= $this->getDefaultModel();
34
-        $options ??= [];
34
+        $options ??= [ ];
35 35
 
36 36
         $toonMessage = $this->compressMessage($message);
37 37
 
38 38
         $payload = array_merge([
39 39
             'model' => $model,
40 40
             'messages' => [
41
-                ['role' => 'user', 'content' => $toonMessage],
41
+                [ 'role' => 'user', 'content' => $toonMessage ],
42 42
             ],
43 43
             'temperature' => 0.7,
44 44
         ], $options);
@@ -72,16 +72,16 @@  discard block
 block discarded – undo
72 72
         ?array $options = null
73 73
     ): array {
74 74
         if (!$this->isEnabled()) {
75
-            return ['success' => false, 'error' => 'OpenAI adapter not enabled'];
75
+            return [ 'success' => false, 'error' => 'OpenAI adapter not enabled' ];
76 76
         }
77 77
 
78 78
         $model ??= $this->getDefaultModel();
79
-        $options ??= [];
79
+        $options ??= [ ];
80 80
 
81 81
         // Compress messages
82 82
         $compressedMessages = array_map(fn ($msg) => [
83 83
             ...$msg,
84
-            'content' => $this->compressMessage($msg['content']),
84
+            'content' => $this->compressMessage($msg[ 'content' ]),
85 85
         ], $messages);
86 86
 
87 87
         $payload = array_merge([
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
                 ->json();
98 98
 
99 99
             $originalTokens = array_sum(array_map(
100
-                fn ($msg) => $this->tokenAnalyzer->estimate($msg['content']),
100
+                fn ($msg) => $this->tokenAnalyzer->estimate($msg[ 'content' ]),
101 101
                 $messages
102 102
             ));
103 103
 
104 104
             $compressedTokens = array_sum(array_map(
105
-                fn ($msg) => $this->tokenAnalyzer->estimate($msg['content']),
105
+                fn ($msg) => $this->tokenAnalyzer->estimate($msg[ 'content' ]),
106 106
                 $compressedMessages
107 107
             ));
108 108
 
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
             $timeout = config('laravel-toon.adapters.openai.timeout', 30);
148 148
 
149 149
             $this->client = Http::baseUrl($baseUrl)
150
-                ->withHeader('Authorization', 'Bearer '.$apiKey)
150
+                ->withHeader('Authorization', 'Bearer ' . $apiKey)
151 151
                 ->withHeader('Content-Type', 'application/json')
152 152
                 ->timeout($timeout);
153 153
         }
Please login to merge, or discard this patch.
src/Adapters/MistralAdapter.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
         ?array $options = null
28 28
     ): array {
29 29
         if (!$this->isEnabled()) {
30
-            return ['success' => false, 'error' => 'Mistral adapter not enabled'];
30
+            return [ 'success' => false, 'error' => 'Mistral adapter not enabled' ];
31 31
         }
32 32
 
33 33
         $model ??= $this->getDefaultModel();
34
-        $options ??= [];
34
+        $options ??= [ ];
35 35
 
36 36
         $toonMessage = $this->compressMessage($message);
37 37
 
38 38
         $payload = array_merge([
39 39
             'model' => $model,
40 40
             'messages' => [
41
-                ['role' => 'user', 'content' => $toonMessage],
41
+                [ 'role' => 'user', 'content' => $toonMessage ],
42 42
             ],
43 43
         ], $options);
44 44
 
@@ -71,16 +71,16 @@  discard block
 block discarded – undo
71 71
         ?array $options = null
72 72
     ): array {
73 73
         if (!$this->isEnabled()) {
74
-            return ['success' => false, 'error' => 'Mistral adapter not enabled'];
74
+            return [ 'success' => false, 'error' => 'Mistral adapter not enabled' ];
75 75
         }
76 76
 
77 77
         $model ??= $this->getDefaultModel();
78
-        $options ??= [];
78
+        $options ??= [ ];
79 79
 
80 80
         // Compress messages
81 81
         $compressedMessages = array_map(fn ($msg) => [
82 82
             ...$msg,
83
-            'content' => $this->compressMessage($msg['content']),
83
+            'content' => $this->compressMessage($msg[ 'content' ]),
84 84
         ], $messages);
85 85
 
86 86
         $payload = array_merge([
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
                 ->json();
96 96
 
97 97
             $originalTokens = array_sum(array_map(
98
-                fn ($msg) => $this->tokenAnalyzer->estimate($msg['content']),
98
+                fn ($msg) => $this->tokenAnalyzer->estimate($msg[ 'content' ]),
99 99
                 $messages
100 100
             ));
101 101
 
102 102
             $compressedTokens = array_sum(array_map(
103
-                fn ($msg) => $this->tokenAnalyzer->estimate($msg['content']),
103
+                fn ($msg) => $this->tokenAnalyzer->estimate($msg[ 'content' ]),
104 104
                 $compressedMessages
105 105
             ));
106 106
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
             $timeout = config('laravel-toon.adapters.mistral.timeout', 30);
146 146
 
147 147
             $this->client = Http::baseUrl($baseUrl)
148
-                ->withHeader('Authorization', 'Bearer '.$apiKey)
148
+                ->withHeader('Authorization', 'Bearer ' . $apiKey)
149 149
                 ->withHeader('Content-Type', 'application/json')
150 150
                 ->timeout($timeout);
151 151
         }
Please login to merge, or discard this patch.
src/Adapters/AnthropicAdapter.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
         ?array $options = null
28 28
     ): array {
29 29
         if (!$this->isEnabled()) {
30
-            return ['success' => false, 'error' => 'Anthropic adapter not enabled'];
30
+            return [ 'success' => false, 'error' => 'Anthropic adapter not enabled' ];
31 31
         }
32 32
 
33 33
         $model ??= $this->getDefaultModel();
34
-        $options ??= [];
34
+        $options ??= [ ];
35 35
 
36 36
         $toonMessage = $this->compressMessage($message);
37 37
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             'model' => $model,
40 40
             'max_tokens' => 1024,
41 41
             'messages' => [
42
-                ['role' => 'user', 'content' => $toonMessage],
42
+                [ 'role' => 'user', 'content' => $toonMessage ],
43 43
             ],
44 44
         ], $options);
45 45
 
@@ -72,16 +72,16 @@  discard block
 block discarded – undo
72 72
         ?array $options = null
73 73
     ): array {
74 74
         if (!$this->isEnabled()) {
75
-            return ['success' => false, 'error' => 'Anthropic adapter not enabled'];
75
+            return [ 'success' => false, 'error' => 'Anthropic adapter not enabled' ];
76 76
         }
77 77
 
78 78
         $model ??= $this->getDefaultModel();
79
-        $options ??= [];
79
+        $options ??= [ ];
80 80
 
81 81
         // Compress messages
82 82
         $compressedMessages = array_map(fn ($msg) => [
83 83
             ...$msg,
84
-            'content' => $this->compressMessage($msg['content']),
84
+            'content' => $this->compressMessage($msg[ 'content' ]),
85 85
         ], $messages);
86 86
 
87 87
         $payload = array_merge([
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
                 ->json();
98 98
 
99 99
             $originalTokens = array_sum(array_map(
100
-                fn ($msg) => $this->tokenAnalyzer->estimate($msg['content']),
100
+                fn ($msg) => $this->tokenAnalyzer->estimate($msg[ 'content' ]),
101 101
                 $messages
102 102
             ));
103 103
 
104 104
             $compressedTokens = array_sum(array_map(
105
-                fn ($msg) => $this->tokenAnalyzer->estimate($msg['content']),
105
+                fn ($msg) => $this->tokenAnalyzer->estimate($msg[ 'content' ]),
106 106
                 $compressedMessages
107 107
             ));
108 108
 
Please login to merge, or discard this patch.
src/LaravelToonServiceProvider.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -22,29 +22,29 @@  discard block
 block discarded – undo
22 22
     public function register(): void
23 23
     {
24 24
         $this->mergeConfigFrom(
25
-            __DIR__.'/../config/laravel-toon.php',
25
+            __DIR__ . '/../config/laravel-toon.php',
26 26
             'laravel-toon'
27 27
         );
28 28
 
29 29
         // Registrar servicios principales
30
-        $this->app->singleton('toon', function ($app) {
30
+        $this->app->singleton('toon', function($app) {
31 31
             return new ToonService();
32 32
         });
33 33
 
34
-        $this->app->singleton(ToonService::class, function ($app) {
34
+        $this->app->singleton(ToonService::class, function($app) {
35 35
             return $app->make('toon');
36 36
         });
37 37
 
38
-        $this->app->singleton(TokenAnalyzer::class, function ($app) {
38
+        $this->app->singleton(TokenAnalyzer::class, function($app) {
39 39
             return new TokenAnalyzer();
40 40
         });
41 41
 
42
-        $this->app->singleton(CompressionMetrics::class, function ($app) {
42
+        $this->app->singleton(CompressionMetrics::class, function($app) {
43 43
             return new CompressionMetrics();
44 44
         });
45 45
 
46
-        $this->app->singleton(CostCalculator::class, function ($app) {
47
-            return new CostCalculator(config('laravel-toon.cost_calculation.models', []));
46
+        $this->app->singleton(CostCalculator::class, function($app) {
47
+            return new CostCalculator(config('laravel-toon.cost_calculation.models', [ ]));
48 48
         });
49 49
     }
50 50
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     {
56 56
         // Publicar configuración
57 57
         $this->publishes([
58
-            __DIR__.'/../config/laravel-toon.php' => config_path('laravel-toon.php'),
58
+            __DIR__ . '/../config/laravel-toon.php' => config_path('laravel-toon.php'),
59 59
         ], 'laravel-toon-config');
60 60
 
61 61
         // Registrar comandos Artisan
Please login to merge, or discard this patch.
src/Toon/Normalize.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@
 block discarded – undo
32 32
 
33 33
     private static function normalizeArray(array $array): mixed
34 34
     {
35
-        $result = [];
35
+        $result = [ ];
36 36
         foreach ($array as $key => $item) {
37 37
             $normalizedKey = is_int($key) ? $key : (string)$key;
38
-            $result[$normalizedKey] = self::normalize($item);
38
+            $result[ $normalizedKey ] = self::normalize($item);
39 39
         }
40 40
 
41 41
         return $result;
Please login to merge, or discard this patch.
src/Toon/Constants.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
     public const FALSE_VALUE = 'false';
25 25
 
26 26
     // Escaped characters
27
-    public const ESCAPABLE_CHARS = ['\\', '"', "\n", "\r", "\t"];
27
+    public const ESCAPABLE_CHARS = [ '\\', '"', "\n", "\r", "\t" ];
28 28
     public const ESCAPE_MAP = [
29 29
         '\\' => '\\',
30 30
         '"' => '"',
Please login to merge, or discard this patch.
src/Toon/Primitives.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     {
46 46
         // No quotes needed for simple alphanumeric strings
47 47
         if (self::needsQuoting($value)) {
48
-            return Constants::QUOTE_CHAR.self::escape($value).Constants::QUOTE_CHAR;
48
+            return Constants::QUOTE_CHAR . self::escape($value) . Constants::QUOTE_CHAR;
49 49
         }
50 50
 
51 51
         return $value;
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         }
59 59
 
60 60
         // Reserved words
61
-        if (in_array($value, [Constants::NULL_VALUE, Constants::TRUE_VALUE, Constants::FALSE_VALUE], true)) {
61
+        if (in_array($value, [ Constants::NULL_VALUE, Constants::TRUE_VALUE, Constants::FALSE_VALUE ], true)) {
62 62
             return true;
63 63
         }
64 64
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
     {
80 80
         $result = '';
81 81
         for ($i = 0; $i < strlen($value); ++$i) {
82
-            $char = $value[$i];
82
+            $char = $value[ $i ];
83 83
             if (in_array($char, Constants::ESCAPABLE_CHARS, true)) {
84
-                $result .= Constants::ESCAPE_CHAR.Constants::ESCAPE_MAP[$char];
84
+                $result .= Constants::ESCAPE_CHAR . Constants::ESCAPE_MAP[ $char ];
85 85
             } else {
86 86
                 $result .= $char;
87 87
             }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         }
100 100
 
101 101
         // Handle quoted strings
102
-        if (Constants::QUOTE_CHAR === $value[0]) {
102
+        if (Constants::QUOTE_CHAR === $value[ 0 ]) {
103 103
             return self::unquote($value);
104 104
         }
105 105
 
@@ -141,17 +141,17 @@  discard block
 block discarded – undo
141 141
         $result = '';
142 142
         $i = 0;
143 143
         while ($i < strlen($value)) {
144
-            if (Constants::ESCAPE_CHAR === $value[$i] && $i + 1 < strlen($value)) {
145
-                $nextChar = $value[$i + 1];
146
-                if (isset(Constants::UNESCAPE_MAP[$nextChar])) {
147
-                    $result .= Constants::UNESCAPE_MAP[$nextChar];
144
+            if (Constants::ESCAPE_CHAR === $value[ $i ] && $i + 1 < strlen($value)) {
145
+                $nextChar = $value[ $i + 1 ];
146
+                if (isset(Constants::UNESCAPE_MAP[ $nextChar ])) {
147
+                    $result .= Constants::UNESCAPE_MAP[ $nextChar ];
148 148
                     $i += 2;
149 149
                 } else {
150
-                    $result .= $value[$i];
150
+                    $result .= $value[ $i ];
151 151
                     ++$i;
152 152
                 }
153 153
             } else {
154
-                $result .= $value[$i];
154
+                $result .= $value[ $i ];
155 155
                 ++$i;
156 156
             }
157 157
         }
Please login to merge, or discard this patch.
src/Toon/Toon.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 
38 38
     private static function parseLines(array $lines, int &$index = 0, int $expectedIndent = 0): mixed
39 39
     {
40
-        $result = [];
40
+        $result = [ ];
41 41
         $isObject = false;
42 42
         $isList = false;
43 43
 
44 44
         while ($index < count($lines)) {
45
-            $line = $lines[$index];
45
+            $line = $lines[ $index ];
46 46
             $indent = self::getIndent($line);
47 47
             $content = trim($line);
48 48
 
@@ -64,33 +64,33 @@  discard block
 block discarded – undo
64 64
 
65 65
             if (str_contains($content, Constants::OBJECT_MARKER)) {
66 66
                 $isObject = true;
67
-                [$key, $value] = self::parseObjectLine($content);
67
+                [ $key, $value ] = self::parseObjectLine($content);
68 68
                 ++$index;
69 69
 
70 70
                 if ($index < count($lines)) {
71
-                    $nextLine = $lines[$index];
71
+                    $nextLine = $lines[ $index ];
72 72
                     $nextIndent = self::getIndent($nextLine);
73 73
                     if ($nextIndent > $expectedIndent) {
74
-                        $result[$key] = self::parseLines($lines, $index, $nextIndent);
74
+                        $result[ $key ] = self::parseLines($lines, $index, $nextIndent);
75 75
 
76 76
                         continue;
77 77
                     }
78 78
                 }
79 79
 
80
-                $result[$key] = $value;
80
+                $result[ $key ] = $value;
81 81
 
82 82
                 continue;
83 83
             }
84 84
 
85 85
             if (str_contains($content, Constants::ARRAY_MARKER)) {
86 86
                 $isList = true;
87
-                $result[] = self::parseArrayLine($content);
87
+                $result[ ] = self::parseArrayLine($content);
88 88
                 ++$index;
89 89
 
90 90
                 continue;
91 91
             }
92 92
 
93
-            $result[] = Primitives::decode($content);
93
+            $result[ ] = Primitives::decode($content);
94 94
             ++$index;
95 95
         }
96 96
 
@@ -100,29 +100,29 @@  discard block
 block discarded – undo
100 100
     private static function parseObjectLine(string $line): array
101 101
     {
102 102
         $parts = explode(Constants::OBJECT_MARKER, $line, 2);
103
-        $key = trim($parts[0]);
104
-        $value = isset($parts[1]) ? trim($parts[1]) : null;
103
+        $key = trim($parts[ 0 ]);
104
+        $value = isset($parts[ 1 ]) ? trim($parts[ 1 ]) : null;
105 105
 
106 106
         if ('' === $value || null === $value) {
107
-            return [$key, null];
107
+            return [ $key, null ];
108 108
         }
109 109
 
110
-        return [$key, Primitives::decode($value)];
110
+        return [ $key, Primitives::decode($value) ];
111 111
     }
112 112
 
113 113
     private static function parseArrayLine(string $line): mixed
114 114
     {
115 115
         // Extract array length
116 116
         if (preg_match('/^(\d+)\]/', $line, $matches)) {
117
-            $length = (int)$matches[1];
118
-            $line = substr($line, strlen($matches[0]));
117
+            $length = (int)$matches[ 1 ];
118
+            $line = substr($line, strlen($matches[ 0 ]));
119 119
             $line = trim($line);
120 120
 
121 121
             // Check for field headers (tabular format)
122 122
             if (str_contains($line, Constants::ARRAY_FIELD_WRAPPER_START)) {
123 123
                 preg_match('/\{([^}]+)\}/', $line, $fieldMatches);
124
-                if (isset($fieldMatches[1])) {
125
-                    $fields = explode(Constants::FIELD_DELIMITER, $fieldMatches[1]);
124
+                if (isset($fieldMatches[ 1 ])) {
125
+                    $fields = explode(Constants::FIELD_DELIMITER, $fieldMatches[ 1 ]);
126 126
 
127 127
                     return [
128 128
                         'length' => $length,
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
             // Extract values
136 136
             if (str_contains($line, Constants::ARRAY_HEADER_DELIMITER)) {
137 137
                 $parts = explode(Constants::ARRAY_HEADER_DELIMITER, $line, 2);
138
-                $values = explode(Constants::FIELD_DELIMITER, trim($parts[1] ?? ''));
138
+                $values = explode(Constants::FIELD_DELIMITER, trim($parts[ 1 ] ?? ''));
139 139
 
140 140
                 return array_map(fn ($v) => Primitives::decode($v), $values);
141 141
             }
142 142
         }
143 143
 
144
-        return [];
144
+        return [ ];
145 145
     }
146 146
 
147 147
     private static function getIndent(string $line): int
Please login to merge, or discard this patch.
src/Toon/Encoders.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -57,15 +57,15 @@  discard block
 block discarded – undo
57 57
             $keyStr = is_int($key) ? (string)$key : $key;
58 58
 
59 59
             if (is_array($value) && !empty($value)) {
60
-                $writer->line($keyStr.Constants::OBJECT_MARKER);
60
+                $writer->line($keyStr . Constants::OBJECT_MARKER);
61 61
                 $writer->indent();
62 62
                 self::encodeArray($value, $writer, $options);
63 63
                 $writer->dedent();
64 64
             } elseif (is_array($value)) {
65
-                $writer->line($keyStr.Constants::OBJECT_MARKER.' []');
65
+                $writer->line($keyStr . Constants::OBJECT_MARKER . ' []');
66 66
             } else {
67 67
                 $encoded = Primitives::encode($value);
68
-                $writer->line($keyStr.Constants::OBJECT_MARKER.' '.$encoded);
68
+                $writer->line($keyStr . Constants::OBJECT_MARKER . ' ' . $encoded);
69 69
             }
70 70
         }
71 71
     }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         if ($allPrimitives) {
89 89
             $encoded = array_map(fn ($item) => Primitives::encode($item), $array);
90 90
             $content = implode($options->delimiter, $encoded);
91
-            $writer->line($count.Constants::ARRAY_MARKER_END.Constants::ARRAY_HEADER_DELIMITER.' '.$content);
91
+            $writer->line($count . Constants::ARRAY_MARKER_END . Constants::ARRAY_HEADER_DELIMITER . ' ' . $content);
92 92
 
93 93
             return;
94 94
         }
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
         }
105 105
 
106 106
         // List format with hyphens
107
-        $writer->line($count.Constants::ARRAY_MARKER_END.Constants::OBJECT_MARKER);
107
+        $writer->line($count . Constants::ARRAY_MARKER_END . Constants::OBJECT_MARKER);
108 108
         $writer->indent();
109 109
         foreach ($array as $item) {
110 110
             if (is_array($item)) {
@@ -142,16 +142,16 @@  discard block
 block discarded – undo
142 142
     private static function encodeTabularArray(array $array, LineWriter $writer, EncodeOptions $options): void
143 143
     {
144 144
         $count = count($array);
145
-        $keys = array_keys(reset($array) ?? []);
145
+        $keys = array_keys(reset($array) ?? [ ]);
146 146
         $keysStr = implode($options->delimiter, $keys);
147 147
 
148
-        $writer->line($count.Constants::ARRAY_MARKER_END.Constants::ARRAY_FIELD_WRAPPER_START.$keysStr.Constants::ARRAY_FIELD_WRAPPER_END.Constants::OBJECT_MARKER);
148
+        $writer->line($count . Constants::ARRAY_MARKER_END . Constants::ARRAY_FIELD_WRAPPER_START . $keysStr . Constants::ARRAY_FIELD_WRAPPER_END . Constants::OBJECT_MARKER);
149 149
         $writer->indent();
150 150
 
151 151
         foreach ($array as $row) {
152
-            $values = [];
152
+            $values = [ ];
153 153
             foreach ($keys as $key) {
154
-                $values[] = Primitives::encode($row[$key] ?? null);
154
+                $values[ ] = Primitives::encode($row[ $key ] ?? null);
155 155
             }
156 156
             $writer->line(implode($options->delimiter, $values));
157 157
         }
Please login to merge, or discard this patch.