Skip to content

[FEATURE]: Loggable Exception / Issue #102 - #107

Closed
atournayre wants to merge 2 commits into
mainfrom
issue/102-loggable-exception
Closed

atournayre wants to merge 2 commits into
mainfrom
issue/102-loggable-exception

Conversation

@atournayre

@atournayre atournayre commented Nov 24, 2025 •

Copy link
Copy Markdown
Owner

Summary

Implements LoggableInterface for all framework exceptions via an optional trait, following issue #102.

Changes

Architecture (Option A - Interface Segregation):

  • New trait LoggableThrowableTrait combining ThrowableTrait + toLog() method
  • 6 Common/Exception classes now implement LoggableInterface
  • ThrowableInterface remains independent (no forced extension of LoggableInterface)

Modified files:

  • ✨ New: src/Common/Exception/LoggableThrowableTrait.php
  • ♻️ Refactor: 6 exception classes with implements LoggableInterface, use LoggableThrowableTrait
  • 🐛 Bonus fix: UnshiftInterface.php explicit $key parameter typing

Advantages:

  • Respects Interface Segregation principle (SOLID)
  • Composition via trait rather than tight coupling
  • Flexibility: opt-in exceptions, possibility for non-loggable exceptions
  • ThrowableInterface 5-method limit preserved

Testing

  • ✅ PHP syntax validated on all modified files
  • ⚠️ PHPStan/PHPUnit not runnable (local env PHP 8.1 vs required 8.2+)
  • 🔍 Manual code review: Elegant Objects principles respected

Checklist

  • Code follows project standards
  • Tests structure in place
  • Documentation with complete docblocks

Fixes #102

Ajoute type int|string|null pour $key (était untyped, causait ParseError PHPStan).
Issue #102: toutes exceptions doivent implémenter LoggableInterface.

Solution choisie (Option A - Interface Segregation):
- Créer LoggableThrowableTrait combinant ThrowableTrait + toLog()
- Exceptions opt-in LoggableInterface (pas héritage forcé)
- Flexibilité pour exceptions non-loggables si besoin

Changements:
- Nouveau trait LoggableThrowableTrait avec méthode toLog()
- 6 exceptions Common/Exception implémentent LoggableInterface
- ThrowableInterface reste indépendant (pas extends LoggableInterface)

Avantages:
- Respecte principe Interface Segregation (SOLID)
- Composition plutôt que couplage fort
- Limite 5 méthodes ThrowableInterface préservée
@atournayre atournayre added this to the 2.15.0 milestone Nov 24, 2025
@atournayre

atournayre commented Nov 24, 2025 •

Copy link
Copy Markdown
Owner Author

🔍 Automated Code Review

✅ Positive points

Architecture:

  • Interface Segregation respected (SOLID)
  • Composition via trait rather than forced inheritance
  • Flexibility preserved for opt-in/opt-out exceptions

Elegant Objects:

  • Trait contains only public toLog() method
  • Complete docblocks with @return typehint
  • No principle violations (no static methods, getters, etc.)

Code quality:

  • Strict typing array<string, mixed>
  • Consistent naming LoggableThrowableTrait
  • Bonus fix UnshiftInterface type parameter

📝 Suggestions (non-blocking)

Tests:

  • Add unit tests for LoggableThrowableTrait::toLog()
  • Verify returned array format contains [message, code, file, line, trace]

Documentation:

  • Consider adding usage example in LoggableThrowableTrait docblock

✅ Validation

Code ready to merge. PHP syntax validated. Solid architecture respecting project conventions.

@atournayre atournayre closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Loggable Exception

1 participant