Skip to content

Commit 58e0e84

Browse files
committed
fix: atualizar links de documentação para refletir nova URL
refactor(JsonBufferPool): tornar constantes de limite de array públicas test: corrigir testes para validar constantes de limite de array
1 parent ccab7ce commit 58e0e84

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

docs/releases/FRAMEWORK_OVERVIEW_v1.0.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ composer phpstan
550550
### Official Links
551551
- **GitHub**: https://github.com/PivotPHP/pivotphp-core
552552
- **Packagist**: https://packagist.org/packages/pivotphp/core
553-
- **Documentation**: https://docs.pivotphp.com
553+
- **Documentation**: https://pivotphp.github.io/website/docs/
554554
- **Community**: https://discord.gg/pivotphp
555555

556556
### Extensions

docs/releases/FRAMEWORK_OVERVIEW_v1.0.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ composer phpstan
624624
### Official Links
625625
- **GitHub**: https://github.com/PivotPHP/pivotphp-core
626626
- **Packagist**: https://packagist.org/packages/pivotphp/core
627-
- **Documentation**: https://docs.pivotphp.com
627+
- **Documentation**: https://pivotphp.github.io/website/docs/
628628
- **Community**: https://discord.gg/pivotphp
629629

630630
### Extensions

src/Http/Response.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ public function json(mixed $data): self
226226
} else {
227227
// Usar encoding tradicional para dados pequenos
228228
$encoded = json_encode($sanitizedData, self::JSON_ENCODE_FLAGS);
229-
}
230229

231-
// Handle JSON encoding failures for both pooling and traditional paths
232-
if ($encoded === false) {
233-
error_log('JSON encoding failed: ' . json_last_error_msg());
234-
$encoded = '{}';
230+
// Handle JSON encoding failures for traditional path
231+
if ($encoded === false) {
232+
error_log('JSON encoding failed: ' . json_last_error_msg());
233+
$encoded = '{}';
234+
}
235235
}
236236

237237
$this->body = $encoded;
@@ -802,16 +802,21 @@ private function shouldUseJsonPooling(mixed $data): bool
802802
/**
803803
* Codifica JSON usando pooling para melhor performance
804804
*/
805-
private function encodeWithPooling(mixed $data): string|false
805+
private function encodeWithPooling(mixed $data): string
806806
{
807807
try {
808808
return JsonBufferPool::encodeWithPool($data, self::JSON_ENCODE_FLAGS);
809809
} catch (\Throwable $e) {
810810
// Fallback para encoding tradicional em caso de erro
811811
error_log('JSON pooling failed, falling back to traditional encoding: ' . $e->getMessage());
812812

813-
// Fallback to traditional encoding (let caller handle JSON encoding failures)
814-
return json_encode($data, self::JSON_ENCODE_FLAGS);
813+
// Fallback to traditional encoding (handle JSON encoding failures internally)
814+
$encoded = json_encode($data, self::JSON_ENCODE_FLAGS);
815+
if ($encoded === false) {
816+
error_log('JSON fallback encoding failed: ' . json_last_error_msg());
817+
return '{}';
818+
}
819+
return $encoded;
815820
}
816821
}
817822
}

src/Json/Pool/JsonBufferPool.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class JsonBufferPool
2424
private const XLARGE_ARRAY_SIZE = 32768; // XLarge array estimate (>= 1000 items)
2525

2626
// Array size thresholds
27-
private const SMALL_ARRAY_THRESHOLD = 10; // Threshold for small array
28-
private const MEDIUM_ARRAY_THRESHOLD = 100; // Threshold for medium array
29-
private const LARGE_ARRAY_THRESHOLD = 1000; // Threshold for large array
27+
public const SMALL_ARRAY_THRESHOLD = 10; // Threshold for small array
28+
public const MEDIUM_ARRAY_THRESHOLD = 100; // Threshold for medium array
29+
public const LARGE_ARRAY_THRESHOLD = 1000; // Threshold for large array
3030

3131
// Object size estimation constants
3232
private const OBJECT_PROPERTY_OVERHEAD = 50; // Bytes per object property

tests/Json/Pool/JsonSizeEstimationTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,14 @@ public function testConstantsAreReasonable(): void
173173
$this->assertLessThan(32768, 8192); // LARGE < XLARGE
174174

175175
// Test threshold constants are in ascending order
176-
$this->assertLessThan(100, 10); // SMALL < MEDIUM threshold
177-
$this->assertLessThan(1000, 100); // MEDIUM < LARGE threshold
176+
$this->assertLessThan(
177+
JsonBufferPool::MEDIUM_ARRAY_THRESHOLD,
178+
JsonBufferPool::SMALL_ARRAY_THRESHOLD
179+
); // SMALL < MEDIUM threshold
180+
$this->assertLessThan(
181+
JsonBufferPool::LARGE_ARRAY_THRESHOLD,
182+
JsonBufferPool::MEDIUM_ARRAY_THRESHOLD
183+
); // MEDIUM < LARGE threshold
178184

179185
// Test overhead constants are reasonable
180186
$this->assertGreaterThan(0, 20); // STRING_OVERHEAD > 0

0 commit comments

Comments
 (0)