Passed
Branch main (3df0d9)
by Jacobo
13:51
created
Category
src/Console/Commands/ToonConvertCommand.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             if ($decode) {
47 47
                 $result = $toonService->decode($content);
48 48
                 if ($pretty) {
49
-                    $result = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
49
+                    $result = json_encode($result, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
50 50
                 } else {
51 51
                     $result = json_encode($result, JSON_THROW_ON_ERROR);
52 52
                 }
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             } else {
55 55
                 $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
56 56
                 $result = $toonService->convert($data, $format);
57
-                $outputFormat = strtoupper($format).' TOON';
57
+                $outputFormat = strtoupper($format) . ' TOON';
58 58
             }
59 59
 
60 60
             if ($output) {
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 
70 70
             return self::SUCCESS;
71 71
         } catch (\Exception $e) {
72
-            $this->error('Error durante la conversión: '.$e->getMessage());
72
+            $this->error('Error durante la conversión: ' . $e->getMessage());
73 73
 
74 74
             return self::FAILURE;
75 75
         }
Please login to merge, or discard this patch.
src/Console/Commands/ToonAnalyzeCommand.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -47,43 +47,43 @@  discard block
 block discarded – undo
47 47
 
48 48
                 // Data summary
49 49
                 $this->info('Resumen de Datos:');
50
-                $this->table(['Propiedad', 'Valor'], [
51
-                    ['Tipo', $full['data_summary']['type']],
52
-                    ['Tamaño', $full['data_summary']['size']],
50
+                $this->table([ 'Propiedad', 'Valor' ], [
51
+                    [ 'Tipo', $full[ 'data_summary' ][ 'type' ] ],
52
+                    [ 'Tamaño', $full[ 'data_summary' ][ 'size' ] ],
53 53
                 ]);
54 54
 
55 55
                 // Compression metrics
56 56
                 $this->info('Compresión:');
57
-                $this->table(['Métrica', 'Valor'], [
58
-                    ['Tamaño JSON', number_format($full['compression']['json_size_bytes']).' bytes'],
59
-                    ['Tamaño TOON', number_format($full['compression']['toon_size_bytes']).' bytes'],
60
-                    ['Bytes reducidos', number_format($full['compression']['bytes_reduced']).' bytes'],
61
-                    ['% Reducción', $full['compression']['percent_reduced'].'%'],
62
-                    ['Ratio compresión', $full['compression']['compression_ratio']],
57
+                $this->table([ 'Métrica', 'Valor' ], [
58
+                    [ 'Tamaño JSON', number_format($full[ 'compression' ][ 'json_size_bytes' ]) . ' bytes' ],
59
+                    [ 'Tamaño TOON', number_format($full[ 'compression' ][ 'toon_size_bytes' ]) . ' bytes' ],
60
+                    [ 'Bytes reducidos', number_format($full[ 'compression' ][ 'bytes_reduced' ]) . ' bytes' ],
61
+                    [ '% Reducción', $full[ 'compression' ][ 'percent_reduced' ] . '%' ],
62
+                    [ 'Ratio compresión', $full[ 'compression' ][ 'compression_ratio' ] ],
63 63
                 ]);
64 64
 
65 65
                 // Token metrics
66 66
                 $this->info('Tokens:');
67
-                $this->table(['Métrica', 'Valor'], [
68
-                    ['Tokens JSON', number_format($full['tokens']['json_tokens'])],
69
-                    ['Tokens TOON', number_format($full['tokens']['toon_tokens'])],
70
-                    ['Tokens ahorrados', number_format($full['tokens']['tokens_saved'])],
71
-                    ['% Ahorrado', $full['tokens']['percent_saved'].'%'],
67
+                $this->table([ 'Métrica', 'Valor' ], [
68
+                    [ 'Tokens JSON', number_format($full[ 'tokens' ][ 'json_tokens' ]) ],
69
+                    [ 'Tokens TOON', number_format($full[ 'tokens' ][ 'toon_tokens' ]) ],
70
+                    [ 'Tokens ahorrados', number_format($full[ 'tokens' ][ 'tokens_saved' ]) ],
71
+                    [ '% Ahorrado', $full[ 'tokens' ][ 'percent_saved' ] . '%' ],
72 72
                 ]);
73 73
 
74 74
                 // Recommendations
75
-                if (!empty($full['recommendations'])) {
75
+                if (!empty($full[ 'recommendations' ])) {
76 76
                     $this->info('Recomendaciones:');
77
-                    foreach ($full['recommendations'] as $rec) {
78
-                        $icon = match ($rec['level']) {
77
+                    foreach ($full[ 'recommendations' ] as $rec) {
78
+                        $icon = match ($rec[ 'level' ]) {
79 79
                             'excellent' => '✓',
80 80
                             'good' => '→',
81 81
                             'moderate' => '~',
82 82
                             'important' => '!',
83 83
                             default => '•',
84 84
                         };
85
-                        $this->info("  {$icon} {$rec['message']}");
86
-                        $this->line("    {$rec['action']}");
85
+                        $this->info("  {$icon} {$rec[ 'message' ]}");
86
+                        $this->line("    {$rec[ 'action' ]}");
87 87
                     }
88 88
                 }
89 89
 
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
 
92 92
                 if ($this->confirm('¿Desea ver el contenido comprimido?')) {
93 93
                     $this->info('JSON Original:');
94
-                    $this->line($full['content']['original_json']);
94
+                    $this->line($full[ 'content' ][ 'original_json' ]);
95 95
                     $this->newLine();
96 96
                     $this->info('TOON Comprimido:');
97
-                    $this->line($full['content']['compressed_toon']);
97
+                    $this->line($full[ 'content' ][ 'compressed_toon' ]);
98 98
                 }
99 99
             } else {
100 100
                 $summary = $metrics->summary($data);
101 101
 
102
-                $this->table(['Métrica', 'Valor'], [
103
-                    ['JSON Size', number_format($summary['json_size_bytes']).' bytes'],
104
-                    ['TOON Size', number_format($summary['toon_size_bytes']).' bytes'],
105
-                    ['Bytes Saved', $summary['bytes_saved_percent'].'%'],
106
-                    ['Tokens Saved', $summary['tokens_saved_percent'].'%'],
102
+                $this->table([ 'Métrica', 'Valor' ], [
103
+                    [ 'JSON Size', number_format($summary[ 'json_size_bytes' ]) . ' bytes' ],
104
+                    [ 'TOON Size', number_format($summary[ 'toon_size_bytes' ]) . ' bytes' ],
105
+                    [ 'Bytes Saved', $summary[ 'bytes_saved_percent' ] . '%' ],
106
+                    [ 'Tokens Saved', $summary[ 'tokens_saved_percent' ] . '%' ],
107 107
                 ]);
108 108
             }
109 109
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 
113 113
             return self::SUCCESS;
114 114
         } catch (\Exception $e) {
115
-            $this->error('Error durante el análisis: '.$e->getMessage());
115
+            $this->error('Error durante el análisis: ' . $e->getMessage());
116 116
 
117 117
             return self::FAILURE;
118 118
         }
Please login to merge, or discard this patch.
src/Console/Commands/ToonBenchmarkCommand.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
             $this->info('Ejecutando benchmark de rendimiento...');
49 49
             $benchmark = $metrics->benchmark($data, $iterations);
50 50
 
51
-            $this->table(['Métrica', 'Valor'], [
52
-                ['Iteraciones', number_format($benchmark['iterations'])],
53
-                ['Tiempo de codificación (total)', $benchmark['encode_time_seconds'].' s'],
54
-                ['Tiempo por operación (encode)', $benchmark['encode_time_per_op_ms'].' ms'],
55
-                ['Tiempo de decodificación (total)', $benchmark['decode_time_seconds'].' s'],
56
-                ['Tiempo por operación (decode)', $benchmark['decode_time_per_op_ms'].' ms'],
57
-                ['Tiempo total', $benchmark['total_time_seconds'].' s'],
51
+            $this->table([ 'Métrica', 'Valor' ], [
52
+                [ 'Iteraciones', number_format($benchmark[ 'iterations' ]) ],
53
+                [ 'Tiempo de codificación (total)', $benchmark[ 'encode_time_seconds' ] . ' s' ],
54
+                [ 'Tiempo por operación (encode)', $benchmark[ 'encode_time_per_op_ms' ] . ' ms' ],
55
+                [ 'Tiempo de decodificación (total)', $benchmark[ 'decode_time_seconds' ] . ' s' ],
56
+                [ 'Tiempo por operación (decode)', $benchmark[ 'decode_time_per_op_ms' ] . ' ms' ],
57
+                [ 'Tiempo total', $benchmark[ 'total_time_seconds' ] . ' s' ],
58 58
             ]);
59 59
 
60 60
             // Cost comparison
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
             $this->info('Comparación de tamaños:');
63 63
 
64 64
             $sizes = $metrics->compareSizes($data);
65
-            $this->table(['Formato', 'Bytes', 'KB'], [
66
-                ['JSON', number_format($sizes['json']['size_bytes']), $sizes['json']['size_kb']],
67
-                ['TOON Readable', number_format($sizes['toon_readable']['size_bytes']), $sizes['toon_readable']['size_kb']],
68
-                ['TOON Compact', number_format($sizes['toon_compact']['size_bytes']), $sizes['toon_compact']['size_kb']],
69
-                ['TOON Tabular', number_format($sizes['toon_tabular']['size_bytes']), $sizes['toon_tabular']['size_kb']],
65
+            $this->table([ 'Formato', 'Bytes', 'KB' ], [
66
+                [ 'JSON', number_format($sizes[ 'json' ][ 'size_bytes' ]), $sizes[ 'json' ][ 'size_kb' ] ],
67
+                [ 'TOON Readable', number_format($sizes[ 'toon_readable' ][ 'size_bytes' ]), $sizes[ 'toon_readable' ][ 'size_kb' ] ],
68
+                [ 'TOON Compact', number_format($sizes[ 'toon_compact' ][ 'size_bytes' ]), $sizes[ 'toon_compact' ][ 'size_kb' ] ],
69
+                [ 'TOON Tabular', number_format($sizes[ 'toon_tabular' ][ 'size_bytes' ]), $sizes[ 'toon_tabular' ][ 'size_kb' ] ],
70 70
             ]);
71 71
 
72 72
             // Cost estimation if model is provided
@@ -76,14 +76,14 @@  discard block
 block discarded – undo
76 76
 
77 77
                 $costComparison = $costCalculator->estimateWithJsonComparison($model, $data, 'input');
78 78
 
79
-                if ($costComparison['success']) {
80
-                    $this->table(['Formato', 'Tokens', 'Costo'], [
81
-                        ['JSON', number_format($costComparison['json']['tokens']), $costComparison['json']['cost_formatted']],
82
-                        ['TOON', number_format($costComparison['toon']['tokens']), $costComparison['toon']['cost_formatted']],
83
-                        ['Ahorros', number_format($costComparison['savings']['tokens']), $costComparison['savings']['cost_formatted'].' ('.$costComparison['savings']['percent'].'%)'],
79
+                if ($costComparison[ 'success' ]) {
80
+                    $this->table([ 'Formato', 'Tokens', 'Costo' ], [
81
+                        [ 'JSON', number_format($costComparison[ 'json' ][ 'tokens' ]), $costComparison[ 'json' ][ 'cost_formatted' ] ],
82
+                        [ 'TOON', number_format($costComparison[ 'toon' ][ 'tokens' ]), $costComparison[ 'toon' ][ 'cost_formatted' ] ],
83
+                        [ 'Ahorros', number_format($costComparison[ 'savings' ][ 'tokens' ]), $costComparison[ 'savings' ][ 'cost_formatted' ] . ' (' . $costComparison[ 'savings' ][ 'percent' ] . '%)' ],
84 84
                     ]);
85 85
                 } else {
86
-                    $this->warn('Modelo no encontrado: '.$model);
86
+                    $this->warn('Modelo no encontrado: ' . $model);
87 87
                 }
88 88
             }
89 89
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
             return self::SUCCESS;
94 94
         } catch (\Exception $e) {
95
-            $this->error('Error durante benchmark: '.$e->getMessage());
95
+            $this->error('Error durante benchmark: ' . $e->getMessage());
96 96
 
97 97
             return self::FAILURE;
98 98
         }
Please login to merge, or discard this patch.
src/Console/Commands/ToonDashboardCommand.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         try {
70 70
             $data = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
71 71
 
72
-            $format = $this->choice('Seleccione formato:', ['compact', 'readable', 'tabular']);
72
+            $format = $this->choice('Seleccione formato:', [ 'compact', 'readable', 'tabular' ]);
73 73
             $result = $toonService->convert($data, $format);
74 74
 
75 75
             $this->newLine();
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                 $this->info("✓ Guardado en: {$filename}");
83 83
             }
84 84
         } catch (\Exception $e) {
85
-            $this->error('Error: '.$e->getMessage());
85
+            $this->error('Error: ' . $e->getMessage());
86 86
         }
87 87
     }
88 88
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
         try {
100 100
             $data = $toonService->decode($toon);
101
-            $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
101
+            $json = json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
102 102
 
103 103
             $this->newLine();
104 104
             $this->info('Resultado JSON:');
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
                 $this->info("✓ Guardado en: {$filename}");
111 111
             }
112 112
         } catch (\Exception $e) {
113
-            $this->error('Error: '.$e->getMessage());
113
+            $this->error('Error: ' . $e->getMessage());
114 114
         }
115 115
     }
116 116
 
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
 
131 131
             $this->newLine();
132 132
             $this->info('
Please login to merge, or discard this patch.
src/Services/ToonService.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
         $bytesReduced = $jsonSize - $toonSize;
70 70
         $percentReduced = $jsonSize > 0 ? (($bytesReduced / $jsonSize) * 100) : 0;
71 71
 
72
-        $jsonTokens = $this->estimateTokens($json)['tokens_estimate'];
73
-        $toonTokens = $this->estimateTokens($toon)['tokens_estimate'];
72
+        $jsonTokens = $this->estimateTokens($json)[ 'tokens_estimate' ];
73
+        $toonTokens = $this->estimateTokens($toon)[ 'tokens_estimate' ];
74 74
         $tokensReduced = $jsonTokens - $toonTokens;
75 75
         $tokenPercentReduced = $jsonTokens > 0 ? (($tokensReduced / $jsonTokens) * 100) : 0;
76 76
 
@@ -127,17 +127,17 @@  discard block
 block discarded – undo
127 127
 
128 128
         return [
129 129
             'data' => $data,
130
-            'json_size_bytes' => $compressed['original']['size_bytes'],
131
-            'json_tokens' => $compressed['original']['tokens_estimate'],
132
-            'toon_size_bytes' => $compressed['compressed']['size_bytes'],
133
-            'toon_tokens' => $compressed['compressed']['tokens_estimate'],
134
-            'bytes_saved' => $compressed['metrics']['bytes_reduced'],
135
-            'bytes_saved_percent' => $compressed['metrics']['percent_reduced'],
136
-            'tokens_saved' => $compressed['metrics']['tokens_reduced'],
137
-            'tokens_saved_percent' => $compressed['metrics']['token_percent_reduced'],
138
-            'compression_ratio' => $compressed['metrics']['compression_ratio'],
139
-            'original_format' => $compressed['original']['content'],
140
-            'compressed_format' => $compressed['compressed']['content'],
130
+            'json_size_bytes' => $compressed[ 'original' ][ 'size_bytes' ],
131
+            'json_tokens' => $compressed[ 'original' ][ 'tokens_estimate' ],
132
+            'toon_size_bytes' => $compressed[ 'compressed' ][ 'size_bytes' ],
133
+            'toon_tokens' => $compressed[ 'compressed' ][ 'tokens_estimate' ],
134
+            'bytes_saved' => $compressed[ 'metrics' ][ 'bytes_reduced' ],
135
+            'bytes_saved_percent' => $compressed[ 'metrics' ][ 'percent_reduced' ],
136
+            'tokens_saved' => $compressed[ 'metrics' ][ 'tokens_reduced' ],
137
+            'tokens_saved_percent' => $compressed[ 'metrics' ][ 'token_percent_reduced' ],
138
+            'compression_ratio' => $compressed[ 'metrics' ][ 'compression_ratio' ],
139
+            'original_format' => $compressed[ 'original' ][ 'content' ],
140
+            'compressed_format' => $compressed[ 'compressed' ][ 'content' ],
141 141
         ];
142 142
     }
143 143
 }
Please login to merge, or discard this patch.
src/Services/TokenAnalyzer.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
     public function estimate(string $content): int
18 18
     {
19
-        $cacheKey = self::CACHE_PREFIX.md5($content);
19
+        $cacheKey = self::CACHE_PREFIX . md5($content);
20 20
 
21 21
         if (config('laravel-toon.token_analysis.cache_results', true)) {
22 22
             $cached = Cache::store(config('laravel-toon.cache.store', 'file'))
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     public function clearCache(): void
144 144
     {
145 145
         Cache::store(config('laravel-toon.cache.store', 'file'))
146
-            ->forget(self::CACHE_PREFIX.'*');
146
+            ->forget(self::CACHE_PREFIX . '*');
147 147
     }
148 148
 }
149 149
 
Please login to merge, or discard this patch.
src/Services/CostCalculator.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 class CostCalculator
8 8
 {
9 9
     public function __construct(
10
-        private readonly array $models = [],
10
+        private readonly array $models = [ ],
11 11
         private readonly ToonService $toon = new ToonService(),
12 12
         private readonly TokenAnalyzer $tokenAnalyzer = new TokenAnalyzer(),
13 13
     ) {}
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
             'tokens' => $tokens,
34 34
             'cost_per_million' => $costPerMillionTokens,
35 35
             'cost' => round($cost, 6),
36
-            'cost_formatted' => '$'.number_format($cost, 4),
36
+            'cost_formatted' => '$' . number_format($cost, 4),
37 37
         ];
38 38
     }
39 39
 
40 40
     public function compareModels(mixed $data, string $role = 'input'): array
41 41
     {
42 42
         $tokens = $this->tokenAnalyzer->estimateToon($data);
43
-        $results = [];
43
+        $results = [ ];
44 44
 
45 45
         foreach ($this->models as $model => $prices) {
46
-            if (isset($prices[$role])) {
47
-                $costPerMillionTokens = $prices[$role];
46
+            if (isset($prices[ $role ])) {
47
+                $costPerMillionTokens = $prices[ $role ];
48 48
                 $cost = ($tokens / 1_000_000) * $costPerMillionTokens;
49 49
 
50
-                $results[$model] = [
50
+                $results[ $model ] = [
51 51
                     'tokens' => $tokens,
52 52
                     'cost_per_million' => $costPerMillionTokens,
53 53
                     'cost' => round($cost, 6),
54
-                    'cost_formatted' => '$'.number_format($cost, 4),
54
+                    'cost_formatted' => '$' . number_format($cost, 4),
55 55
                 ];
56 56
             }
57 57
         }
58 58
 
59 59
         // Sort by cost (lowest first)
60
-        uasort($results, fn ($a, $b) => $a['cost'] <=> $b['cost']);
60
+        uasort($results, fn ($a, $b) => $a[ 'cost' ] <=> $b[ 'cost' ]);
61 61
 
62 62
         return [
63 63
             'tokens' => $tokens,
@@ -94,17 +94,17 @@  discard block
 block discarded – undo
94 94
             'json' => [
95 95
                 'tokens' => $jsonTokens,
96 96
                 'cost' => round($jsonCost, 6),
97
-                'cost_formatted' => '$'.number_format($jsonCost, 4),
97
+                'cost_formatted' => '$' . number_format($jsonCost, 4),
98 98
             ],
99 99
             'toon' => [
100 100
                 'tokens' => $toonTokens,
101 101
                 'cost' => round($toonCost, 6),
102
-                'cost_formatted' => '$'.number_format($toonCost, 4),
102
+                'cost_formatted' => '$' . number_format($toonCost, 4),
103 103
             ],
104 104
             'savings' => [
105 105
                 'tokens' => $jsonTokens - $toonTokens,
106 106
                 'cost' => round($savings, 6),
107
-                'cost_formatted' => '$'.number_format($savings, 4),
107
+                'cost_formatted' => '$' . number_format($savings, 4),
108 108
                 'percent' => round($savingsPercent, 2),
109 109
             ],
110 110
         ];
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     public function estimateBatchCost(string $model, array $dataItems, string $role = 'input'): array
114 114
     {
115 115
         $totalTokens = 0;
116
-        $costs = [];
116
+        $costs = [ ];
117 117
 
118 118
         foreach ($dataItems as $index => $item) {
119 119
             $tokens = $this->tokenAnalyzer->estimateToon($item);
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
             }
126 126
 
127 127
             $cost = ($tokens / 1_000_000) * $costPerMillionTokens;
128
-            $costs[$index] = [
128
+            $costs[ $index ] = [
129 129
                 'tokens' => $tokens,
130 130
                 'cost' => round($cost, 6),
131 131
             ];
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
             'items' => $costs,
143 143
             'total_tokens' => $totalTokens,
144 144
             'total_cost' => round($totalCost, 6),
145
-            'total_cost_formatted' => '$'.number_format($totalCost, 4),
145
+            'total_cost_formatted' => '$' . number_format($totalCost, 4),
146 146
             'average_cost_per_item' => count($costs) > 0 ? round($totalCost / count($costs), 6) : 0,
147 147
         ];
148 148
     }
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
     {
152 152
         $costResult = $this->estimateCost($model, $data, $role);
153 153
 
154
-        if (!$costResult['success']) {
154
+        if (!$costResult[ 'success' ]) {
155 155
             return [
156 156
                 'success' => false,
157
-                'error' => $costResult['error'],
157
+                'error' => $costResult[ 'error' ],
158 158
             ];
159 159
         }
160 160
 
161
-        $costPerRequest = $costResult['cost'];
161
+        $costPerRequest = $costResult[ 'cost' ];
162 162
         $requestsAffordable = (int)floor($budget / $costPerRequest);
163 163
         $percentBudgetUsed = $budget > 0 ? (($costPerRequest / $budget) * 100) : 0;
164 164
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
             'model' => $model,
168 168
             'budget' => round($budget, 2),
169 169
             'cost_per_request' => round($costPerRequest, 6),
170
-            'cost_per_request_formatted' => '$'.number_format($costPerRequest, 4),
170
+            'cost_per_request_formatted' => '$' . number_format($costPerRequest, 4),
171 171
             'requests_affordable' => $requestsAffordable,
172 172
             'percent_budget_per_request' => round($percentBudgetUsed, 2),
173 173
             'remaining_budget_after_one_request' => round($budget - $costPerRequest, 6),
@@ -177,24 +177,24 @@  discard block
 block discarded – undo
177 177
     public function priceComparison(mixed $data, string $role = 'input'): array
178 178
     {
179 179
         $tokens = $this->tokenAnalyzer->estimateToon($data);
180
-        $comparison = [];
180
+        $comparison = [ ];
181 181
 
182 182
         foreach ($this->models as $model => $prices) {
183
-            if (isset($prices[$role])) {
184
-                $costPerMillionTokens = $prices[$role];
183
+            if (isset($prices[ $role ])) {
184
+                $costPerMillionTokens = $prices[ $role ];
185 185
                 $cost = ($tokens / 1_000_000) * $costPerMillionTokens;
186 186
 
187
-                $comparison[$model] = [
187
+                $comparison[ $model ] = [
188 188
                     'cost_per_million' => $costPerMillionTokens,
189 189
                     'cost_for_this_request' => round($cost, 6),
190
-                    'cost_for_1m_tokens' => '$'.number_format($costPerMillionTokens, 4),
191
-                    'cost_for_this_request_formatted' => '$'.number_format($cost, 4),
190
+                    'cost_for_1m_tokens' => '$' . number_format($costPerMillionTokens, 4),
191
+                    'cost_for_this_request_formatted' => '$' . number_format($cost, 4),
192 192
                 ];
193 193
             }
194 194
         }
195 195
 
196 196
         // Sort by cost
197
-        uasort($comparison, fn ($a, $b) => $a['cost_for_this_request'] <=> $b['cost_for_this_request']);
197
+        uasort($comparison, fn ($a, $b) => $a[ 'cost_for_this_request' ] <=> $b[ 'cost_for_this_request' ]);
198 198
 
199 199
         return [
200 200
             'tokens' => $tokens,
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
     private function getPricePerMillionTokens(string $model, string $role): ?float
207 207
     {
208 208
         // First check in instance models
209
-        if (isset($this->models[$model][$role])) {
210
-            return $this->models[$model][$role];
209
+        if (isset($this->models[ $model ][ $role ])) {
210
+            return $this->models[ $model ][ $role ];
211 211
         }
212 212
 
213 213
         // Then check in config
214
-        $configModels = config('laravel-toon.cost_calculation.models', []);
215
-        if (isset($configModels[$model][$role])) {
216
-            return $configModels[$model][$role];
214
+        $configModels = config('laravel-toon.cost_calculation.models', [ ]);
215
+        if (isset($configModels[ $model ][ $role ])) {
216
+            return $configModels[ $model ][ $role ];
217 217
         }
218 218
 
219 219
         return null;
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
 
222 222
     public function getAvailableModels(): array
223 223
     {
224
-        $configModels = config('laravel-toon.cost_calculation.models', []);
224
+        $configModels = config('laravel-toon.cost_calculation.models', [ ]);
225 225
         $all = array_merge($this->models, $configModels);
226 226
 
227
-        $result = [];
227
+        $result = [ ];
228 228
         foreach ($all as $model => $prices) {
229
-            $result[$model] = array_keys($prices);
229
+            $result[ $model ] = array_keys($prices);
230 230
         }
231 231
 
232 232
         return $result;
Please login to merge, or discard this patch.
src/Services/CompressionMetrics.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -22,22 +22,22 @@  discard block
 block discarded – undo
22 22
                 'size' => is_string($data) ? strlen($data) : (is_array($data) ? count($data) : 0),
23 23
             ],
24 24
             'compression' => [
25
-                'json_size_bytes' => $compressed['original']['size_bytes'],
26
-                'toon_size_bytes' => $compressed['compressed']['size_bytes'],
27
-                'bytes_reduced' => $compressed['metrics']['bytes_reduced'],
28
-                'percent_reduced' => $compressed['metrics']['percent_reduced'],
29
-                'compression_ratio' => $compressed['metrics']['compression_ratio'],
25
+                'json_size_bytes' => $compressed[ 'original' ][ 'size_bytes' ],
26
+                'toon_size_bytes' => $compressed[ 'compressed' ][ 'size_bytes' ],
27
+                'bytes_reduced' => $compressed[ 'metrics' ][ 'bytes_reduced' ],
28
+                'percent_reduced' => $compressed[ 'metrics' ][ 'percent_reduced' ],
29
+                'compression_ratio' => $compressed[ 'metrics' ][ 'compression_ratio' ],
30 30
             ],
31 31
             'tokens' => [
32
-                'json_tokens' => $tokenComparison['json_tokens'],
33
-                'toon_tokens' => $tokenComparison['toon_tokens'],
34
-                'tokens_saved' => $tokenComparison['tokens_saved'],
35
-                'percent_saved' => $tokenComparison['percent_saved'],
36
-                'efficiency_ratio' => $tokenComparison['efficiency_ratio'],
32
+                'json_tokens' => $tokenComparison[ 'json_tokens' ],
33
+                'toon_tokens' => $tokenComparison[ 'toon_tokens' ],
34
+                'tokens_saved' => $tokenComparison[ 'tokens_saved' ],
35
+                'percent_saved' => $tokenComparison[ 'percent_saved' ],
36
+                'efficiency_ratio' => $tokenComparison[ 'efficiency_ratio' ],
37 37
             ],
38 38
             'content' => [
39
-                'original_json' => $compressed['original']['content'],
40
-                'compressed_toon' => $compressed['compressed']['content'],
39
+                'original_json' => $compressed[ 'original' ][ 'content' ],
40
+                'compressed_toon' => $compressed[ 'compressed' ][ 'content' ],
41 41
             ],
42 42
             'recommendations' => $this->generateRecommendations($compressed, $tokenComparison),
43 43
         ];
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
         $compressed = $this->toon->compress($data);
49 49
 
50 50
         return [
51
-            'json_size_bytes' => $compressed['original']['size_bytes'],
52
-            'toon_size_bytes' => $compressed['compressed']['size_bytes'],
53
-            'bytes_saved_percent' => $compressed['metrics']['percent_reduced'],
54
-            'tokens_saved_percent' => $compressed['metrics']['token_percent_reduced'],
51
+            'json_size_bytes' => $compressed[ 'original' ][ 'size_bytes' ],
52
+            'toon_size_bytes' => $compressed[ 'compressed' ][ 'size_bytes' ],
53
+            'bytes_saved_percent' => $compressed[ 'metrics' ][ 'percent_reduced' ],
54
+            'tokens_saved_percent' => $compressed[ 'metrics' ][ 'token_percent_reduced' ],
55 55
         ];
56 56
     }
57 57
 
@@ -114,36 +114,36 @@  discard block
 block discarded – undo
114 114
 
115 115
     private function generateRecommendations(array $compressed, array $tokens): array
116 116
     {
117
-        $recommendations = [];
117
+        $recommendations = [ ];
118 118
 
119
-        if ($compressed['metrics']['percent_reduced'] > 70) {
120
-            $recommendations[] = [
119
+        if ($compressed[ 'metrics' ][ 'percent_reduced' ] > 70) {
120
+            $recommendations[ ] = [
121 121
                 'level' => 'excellent',
122 122
                 'message' => 'Excelente compresión: mayor al 70% de reducción',
123 123
                 'action' => 'Use TOON para este tipo de datos en producción',
124 124
             ];
125
-        } elseif ($compressed['metrics']['percent_reduced'] > 50) {
126
-            $recommendations[] = [
125
+        } elseif ($compressed[ 'metrics' ][ 'percent_reduced' ] > 50) {
126
+            $recommendations[ ] = [
127 127
                 'level' => 'good',
128 128
                 'message' => 'Buena compresión: 50-70% de reducción',
129 129
                 'action' => 'TOON es altamente recomendado para este contenido',
130 130
             ];
131
-        } elseif ($compressed['metrics']['percent_reduced'] > 30) {
132
-            $recommendations[] = [
131
+        } elseif ($compressed[ 'metrics' ][ 'percent_reduced' ] > 30) {
132
+            $recommendations[ ] = [
133 133
                 'level' => 'moderate',
134 134
                 'message' => 'Compresión moderada: 30-50% de reducción',
135 135
                 'action' => 'Considere usar TOON para casos de uso con restricción de tokens',
136 136
             ];
137 137
         } else {
138
-            $recommendations[] = [
138
+            $recommendations[ ] = [
139 139
                 'level' => 'low',
140 140
                 'message' => 'Compresión baja: menos del 30%',
141 141
                 'action' => 'TOON puede no ser ideal para este tipo de datos',
142 142
             ];
143 143
         }
144 144
 
145
-        if ($tokens['percent_saved'] > 60) {
146
-            $recommendations[] = [
145
+        if ($tokens[ 'percent_saved' ] > 60) {
146
+            $recommendations[ ] = [
147 147
                 'level' => 'important',
148 148
                 'message' => 'Ahorro significativo de tokens: superior al 60%',
149 149
                 'action' => 'Esto resultará en ahorros sustanciales en costos de API',
Please login to merge, or discard this patch.
src/Middleware/CompressResponse.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -42,11 +42,11 @@
 block discarded – undo
42 42
             $data = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
43 43
             $compressed = $this->toon->compress($data);
44 44
 
45
-            $compressionPercent = $compressed['metrics']['percent_reduced'];
45
+            $compressionPercent = $compressed[ 'metrics' ][ 'percent_reduced' ];
46 46
             $threshold = config('laravel-toon.middleware.compression_threshold', 50);
47 47
 
48 48
             if ($compressionPercent >= $threshold) {
49
-                $response->setContent($compressed['compressed']['content']);
49
+                $response->setContent($compressed[ 'compressed' ][ 'content' ]);
50 50
                 $response->headers->set('X-Content-Compressed', 'true');
51 51
                 $response->headers->set('X-Compression-Percent', round($compressionPercent, 2));
52 52
                 $response->headers->set('Content-Type', 'text/plain; charset=utf-8');
Please login to merge, or discard this patch.