refactor: extract magic numbers to named constants #18

Open
opened 2026-02-20 03:17:35 +00:00 by Clotho · 0 comments
Member

Code Quality Issue

Magic Numbers Found

  1. WebhookDelivery.php:98 - 10000

    'response_body' => substr($responseBody, 0, 10000),
    

    Should be: const MAX_RESPONSE_BODY_LENGTH = 10000;

  2. WebhookService.php:119 - 100

    ->limit(100)
    

    Should be: const MAX_WEBHOOK_BATCH_SIZE = 100;

  3. DeliverWebhookJob.php:33 - 5 (already a constant ✓)

    const MAX_RETRIES = 5;
    

    Good example!

  4. McpApiController.php:various - 600 (cache TTL)

    Cache::remember('mcp_servers', 600, ...)
    

    Should be: const MCP_CACHE_TTL = 600; or config value

Why This Matters

  • Clarity: Named constants explain intent
  • Maintainability: Change in one place
  • Testability: Can override in tests
  • Configuration: Some should be config values
  1. Define class constants for domain-specific limits
  2. Move infrastructure values (cache TTL) to config files
  3. Add comments explaining why limits are set

Priority

Low - Code quality improvement

## Code Quality Issue ### Magic Numbers Found 1. **WebhookDelivery.php:98** - `10000` ```php 'response_body' => substr($responseBody, 0, 10000), ``` Should be: `const MAX_RESPONSE_BODY_LENGTH = 10000;` 2. **WebhookService.php:119** - `100` ```php ->limit(100) ``` Should be: `const MAX_WEBHOOK_BATCH_SIZE = 100;` 3. **DeliverWebhookJob.php:33** - `5` (already a constant ✓) ```php const MAX_RETRIES = 5; ``` Good example! 4. **McpApiController.php:various** - `600` (cache TTL) ```php Cache::remember('mcp_servers', 600, ...) ``` Should be: `const MCP_CACHE_TTL = 600;` or config value ### Why This Matters - **Clarity**: Named constants explain intent - **Maintainability**: Change in one place - **Testability**: Can override in tests - **Configuration**: Some should be config values ### Recommended Approach 1. Define class constants for domain-specific limits 2. Move infrastructure values (cache TTL) to config files 3. Add comments explaining why limits are set ### Priority Low - Code quality improvement
Clotho added the
discovery
label 2026-02-20 03:17:35 +00:00
Charon added
PHP
refactor
P2
and removed
discovery
labels 2026-02-20 12:17:06 +00:00
Clotho was assigned by Charon 2026-02-20 12:21:02 +00:00
Charon added the
agent-ready
label 2026-02-21 01:30:27 +00:00
Sign in to join this conversation.
No description provided.