Skip to content

437 extract adapter type constants from main classes into dedicated enum classes#438

Merged
armanist merged 3 commits intosoftberg:masterfrom
armanist:437-Extract-adapter-type-constants-from-main-classes-into-dedicated-Enum-classes
Mar 23, 2026
Merged

437 extract adapter type constants from main classes into dedicated enum classes#438
armanist merged 3 commits intosoftberg:masterfrom
armanist:437-Extract-adapter-type-constants-from-main-classes-into-dedicated-Enum-classes

Conversation

@armanist
Copy link
Copy Markdown
Member

@armanist armanist commented Mar 23, 2026

Closes #437

Summary by CodeRabbit

  • Refactor
    • Centralized adapter type identifiers into dedicated enum types across many modules (App, Auth, Cache, Captcha, Database, Encryption, Logger, Mailer, Paginator, Renderer, Session, Storage) and updated factories/helpers to use them; functional behavior remains unchanged.
  • Tests
    • Updated unit tests and helpers to reference the new enum types.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9e9057a0-8e6f-4d1e-9cc0-449ba78d6783

📥 Commits

Reviewing files that changed from the base of the PR and between 6d4c485 and 13ab618.

📒 Files selected for processing (14)
  • src/App/Enums/AppType.php
  • src/Archive/Enums/ArchiveType.php
  • src/Auth/Enums/AuthType.php
  • src/Cache/Enums/CacheType.php
  • src/Captcha/Enums/CaptchaType.php
  • src/Database/Enums/DatabaseType.php
  • src/Encryption/Enums/CryptorType.php
  • src/Logger/Enums/LoggerType.php
  • src/Mailer/Enums/MailerType.php
  • src/Paginator/Enums/PaginatorType.php
  • src/Renderer/Enums/RendererType.php
  • src/Session/Enums/SessionType.php
  • src/Storage/Enums/FileSystemType.php
  • tests/Unit/Session/Factories/SessionFactoryTest.php
✅ Files skipped from review due to trivial changes (13)
  • src/Auth/Enums/AuthType.php
  • src/Renderer/Enums/RendererType.php
  • src/Logger/Enums/LoggerType.php
  • src/Session/Enums/SessionType.php
  • src/Paginator/Enums/PaginatorType.php
  • src/Captcha/Enums/CaptchaType.php
  • src/Database/Enums/DatabaseType.php
  • src/Archive/Enums/ArchiveType.php
  • src/Encryption/Enums/CryptorType.php
  • src/Mailer/Enums/MailerType.php
  • src/Storage/Enums/FileSystemType.php
  • src/App/Enums/AppType.php
  • src/Cache/Enums/CacheType.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Unit/Session/Factories/SessionFactoryTest.php

📝 Walkthrough

Walkthrough

Extracted adapter-type string constants from 13 facade classes into dedicated enum-like classes under each package's Enums/ directory; factories, helpers, templates, CronManager, DbModel, and tests were updated to reference the new enum constants. No other runtime control flow or error handling was altered.

Changes

Cohort / File(s) Summary
App Package
src/App/App.php, src/App/Enums/AppType.php, src/App/Factories/AppFactory.php, tests/Unit/App/...
Moved WEB/CONSOLE constants to AppType; factory and tests updated to use AppType.
Archive Package
src/Archive/Archive.php, src/Archive/Enums/ArchiveType.php, src/Archive/Factories/ArchiveFactory.php, tests/Unit/Archive/...
Moved PHAR/ZIP to ArchiveType; factory default and ADAPTERS keys updated; tests adjusted.
Auth Package
src/Auth/Auth.php, src/Auth/Enums/AuthType.php, src/Auth/Factories/AuthFactory.php, tests/Unit/Auth/...
Moved SESSION/JWT to AuthType; factory ADAPTERS and JWT branch now compare against AuthType.
Cache Package
src/Cache/Cache.php, src/Cache/Enums/CacheType.php, src/Cache/Factories/CacheFactory.php, tests/Unit/Cache/...
Moved cache backend constants to CacheType; factory ADAPTERS keys and tests updated.
Captcha Package
src/Captcha/Captcha.php, src/Captcha/Enums/CaptchaType.php, src/Captcha/Factories/CaptchaFactory.php, tests/Unit/Captcha/...
Moved HCAPTCHA/RECAPTCHA to CaptchaType; factory and tests updated.
Cryptor / Encryption
src/Encryption/Cryptor.php, src/Encryption/Enums/CryptorType.php, src/Encryption/Factories/CryptorFactory.php, src/Encryption/Helpers/encryption.php, tests/Unit/Encryption/...
Moved SYMMETRIC/ASYMMETRIC to CryptorType; factory default, helpers, and tests updated.
Database Package
src/Database/Database.php, src/Database/Enums/DatabaseType.php
Re-keyed Database::ADAPTERS to use DatabaseType constants for SLEEKDB/MYSQL/SQLITE/PGSQL.
Logger Package
src/Logger/Logger.php, src/Logger/Enums/LoggerType.php, src/Logger/Factories/LoggerFactory.php, src/Cron/CronManager.php, tests/Unit/Logger/...
Moved logger type constants to LoggerType; factory, CronManager, and tests updated; debug-mode/message adapter guards switched to LoggerType.
Mailer Package
src/Mailer/Mailer.php, src/Mailer/Enums/MailerType.php, src/Mailer/Factories/MailerFactory.php, tests/Unit/Mailer/...
Moved mailer adapter constants to MailerType; factory and tests updated.
Paginator Package & Templates
src/Paginator/Paginator.php, src/Paginator/Enums/PaginatorType.php, src/Paginator/Factories/PaginatorFactory.php, src/Model/DbModel.php, src/Module/Templates/.../*.tpl, tests/Unit/Paginator/...
Moved ARRAY/MODEL to PaginatorType; factory keys, DbModel::paginate, and template/service call-sites updated.
Renderer Package
src/Renderer/Renderer.php, src/Renderer/Enums/RendererType.php, src/Renderer/Factories/RendererFactory.php, tests/Unit/Renderer/...
Moved HTML/TWIG to RendererType; factory and tests updated.
Session Package
src/Session/Session.php, src/Session/Enums/SessionType.php, src/Session/Factories/SessionFactory.php, tests/Unit/Session/...
Moved NATIVE/DATABASE to SessionType; factory and tests updated.
Storage Package
src/Storage/FileSystem.php, src/Storage/Enums/FileSystemType.php, src/Storage/Factories/FileSystemFactory.php, tests/Unit/Storage/...
Moved LOCAL/DROPBOX/GDRIVE to FileSystemType; factory ADAPTERS/APPS keys and cloud-app condition updated; tests adjusted.
Test Files (global)
tests/Unit/...
Updated many tests to import and use new *Type enums instead of old facade class constants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 I hopped through code, constants in tow,
Into Enums they went — neat in a row.
Thirteen packages now tidy and bright,
Factories and tests all hopping alight.
A rabbit’s small dance for refactors that glow.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective: extracting adapter-type constants from main classes into dedicated enum classes across multiple packages.
Linked Issues check ✅ Passed The PR successfully implements all requirements from issue #437: creates 13 enum classes, removes constants from main classes, updates factories and all references in source/test files to use new enums.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the refactoring objective. The PR extracts adapter-type constants, removes them from main classes, updates factories and test files consistently, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.64%. Comparing base (5ebf23c) to head (13ab618).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #438   +/-   ##
=========================================
  Coverage     82.64%   82.64%           
  Complexity     2721     2721           
=========================================
  Files           241      241           
  Lines          7305     7305           
=========================================
  Hits           6037     6037           
  Misses         1268     1268           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@armanist armanist requested a review from andrey-smaelov March 23, 2026 16:14
@armanist armanist added enhancement New feature or request help wanted Extra attention is needed labels Mar 23, 2026
@armanist armanist added this to the 3.0.0 milestone Mar 23, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
src/Database/Enums/DatabaseType.php (1)

20-22: Align class docblock package with namespace.

At Line 21, @package Quantum\Database is slightly inconsistent with Quantum\Database\Enums. Consider updating the package tag for clearer generated docs.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Database/Enums/DatabaseType.php` around lines 20 - 22, The docblock for
class DatabaseType has an inaccurate `@package` tag; update the phpdoc above the
DatabaseType class so the `@package` value matches the namespace
(Quantum\Database\Enums) or remove the `@package` tag entirely; locate the
DatabaseType class declaration in the file and modify its docblock accordingly.
src/Paginator/Factories/PaginatorFactory.php (1)

62-77: Consider documenting accepted enum values.

The create() method accepts string $type but should only receive PaginatorType::ARRAY or PaginatorType::MODEL. Since PHP 7.4 doesn't support native enums, the current approach is appropriate, but a brief PHPDoc note would improve clarity.

📝 Suggested documentation improvement
     /**
      * Creates a new paginator instance using the selected adapter type.
+     * `@param` string $type One of PaginatorType::ARRAY or PaginatorType::MODEL
      * `@param` array<string, mixed> $params
      * `@throws` BaseException
      * `@throws` PaginatorException
      */
     public static function create(string $type, array $params): Paginator
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Paginator/Factories/PaginatorFactory.php` around lines 62 - 77, Add a
PHPDoc block to PaginatorFactory::create explaining that the $type parameter
must be one of the supported paginator types (PaginatorType::ARRAY or
PaginatorType::MODEL), document the expected shape of $params and reference the
ADAPTERS map; update the doc to show examples or a `@param` annotation like
"string $type One of PaginatorType::ARRAY|PaginatorType::MODEL" and mention that
other values will throw PaginatorException::adapterNotSupported, so callers know
the valid enum-like values without native enum support.
tests/Unit/Captcha/Factories/CaptchaFactoryTest.php (1)

29-34: Pre-existing naming inconsistency: test methods use "CacheFactory" instead of "CaptchaFactory".

The test methods testCacheFactoryDefaultAdapter, testCacheFactoryRecaptchaAdapter, testCacheFactoryHcaptchaAdapter, and testCacheFactoryInvalidTypeAdapter appear to have been copy-pasted from cache tests and not renamed. Consider renaming these to testCaptchaFactory* for clarity.

This is not introduced by this PR but worth noting for future cleanup.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/Unit/Captcha/Factories/CaptchaFactoryTest.php` around lines 29 - 34,
Rename the misnamed test methods in CaptchaFactoryTest so they reflect
CaptchaFactory rather than CacheFactory: change testCacheFactoryDefaultAdapter
to testCaptchaFactoryDefaultAdapter, testCacheFactoryRecaptchaAdapter to
testCaptchaFactoryRecaptchaAdapter, testCacheFactoryHcaptchaAdapter to
testCaptchaFactoryHcaptchaAdapter, and testCacheFactoryInvalidTypeAdapter to
testCaptchaFactoryInvalidTypeAdapter; update any references to these method
names (e.g., in test suites or docblocks) to ensure consistency while leaving
the assertions (like usage of CaptchaFactory::get and assertions on getAdapter()
/ RecaptchaAdapter/HcaptchaAdapter) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Logger/Factories/LoggerFactory.php`:
- Around line 66-70: Resolve the effective adapter before enforcing the
non-debug rejection: move the adapter default resolution using "$adapter =
$isDebug ? LoggerType::MESSAGE : ($adapter ?? config()->get('logging.default'))"
to run before the guard, then perform the check "if (!$isDebug && $adapter ===
LoggerType::MESSAGE) { throw
LoggerException::adapterNotSupported(LoggerType::MESSAGE); }" so the guard
validates the final adapter value instead of the raw nullable $adapter.

In `@tests/Unit/Session/Factories/SessionFactoryTest.php`:
- Around line 115-121: Rename the PHPUnit test method named
testMailerFactoryReturnsSameInstance to testSessionFactoryReturnsSameInstance in
the SessionFactoryTest class so the method name matches the behavior (it
exercises SessionFactory::get with SessionType::NATIVE); update the method
declaration only (preserve the body asserting $this->assertSame($session1,
$session2)) to avoid copy-paste confusion and ensure the test runner recognizes
it as the correct test.

---

Nitpick comments:
In `@src/Database/Enums/DatabaseType.php`:
- Around line 20-22: The docblock for class DatabaseType has an inaccurate
`@package` tag; update the phpdoc above the DatabaseType class so the `@package`
value matches the namespace (Quantum\Database\Enums) or remove the `@package` tag
entirely; locate the DatabaseType class declaration in the file and modify its
docblock accordingly.

In `@src/Paginator/Factories/PaginatorFactory.php`:
- Around line 62-77: Add a PHPDoc block to PaginatorFactory::create explaining
that the $type parameter must be one of the supported paginator types
(PaginatorType::ARRAY or PaginatorType::MODEL), document the expected shape of
$params and reference the ADAPTERS map; update the doc to show examples or a
`@param` annotation like "string $type One of
PaginatorType::ARRAY|PaginatorType::MODEL" and mention that other values will
throw PaginatorException::adapterNotSupported, so callers know the valid
enum-like values without native enum support.

In `@tests/Unit/Captcha/Factories/CaptchaFactoryTest.php`:
- Around line 29-34: Rename the misnamed test methods in CaptchaFactoryTest so
they reflect CaptchaFactory rather than CacheFactory: change
testCacheFactoryDefaultAdapter to testCaptchaFactoryDefaultAdapter,
testCacheFactoryRecaptchaAdapter to testCaptchaFactoryRecaptchaAdapter,
testCacheFactoryHcaptchaAdapter to testCaptchaFactoryHcaptchaAdapter, and
testCacheFactoryInvalidTypeAdapter to testCaptchaFactoryInvalidTypeAdapter;
update any references to these method names (e.g., in test suites or docblocks)
to ensure consistency while leaving the assertions (like usage of
CaptchaFactory::get and assertions on getAdapter() /
RecaptchaAdapter/HcaptchaAdapter) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f3e792c1-2860-49f9-bda5-e629a65c2bb2

📥 Commits

Reviewing files that changed from the base of the PR and between 5ebf23c and 6d4c485.

📒 Files selected for processing (64)
  • src/App/App.php
  • src/App/Enums/AppType.php
  • src/App/Factories/AppFactory.php
  • src/Archive/Archive.php
  • src/Archive/Enums/ArchiveType.php
  • src/Archive/Factories/ArchiveFactory.php
  • src/Auth/Auth.php
  • src/Auth/Enums/AuthType.php
  • src/Auth/Factories/AuthFactory.php
  • src/Cache/Cache.php
  • src/Cache/Enums/CacheType.php
  • src/Cache/Factories/CacheFactory.php
  • src/Captcha/Captcha.php
  • src/Captcha/Enums/CaptchaType.php
  • src/Captcha/Factories/CaptchaFactory.php
  • src/Cron/CronManager.php
  • src/Database/Database.php
  • src/Database/Enums/DatabaseType.php
  • src/Encryption/Cryptor.php
  • src/Encryption/Enums/CryptorType.php
  • src/Encryption/Factories/CryptorFactory.php
  • src/Encryption/Helpers/encryption.php
  • src/Logger/Enums/LoggerType.php
  • src/Logger/Factories/LoggerFactory.php
  • src/Logger/Logger.php
  • src/Mailer/Enums/MailerType.php
  • src/Mailer/Factories/MailerFactory.php
  • src/Mailer/Mailer.php
  • src/Model/DbModel.php
  • src/Module/Templates/Toolkit/src/Services/EmailService.php.tpl
  • src/Module/Templates/Toolkit/src/Services/LogsService.php.tpl
  • src/Paginator/Enums/PaginatorType.php
  • src/Paginator/Factories/PaginatorFactory.php
  • src/Paginator/Paginator.php
  • src/Renderer/Enums/RendererType.php
  • src/Renderer/Factories/RendererFactory.php
  • src/Renderer/Renderer.php
  • src/Session/Enums/SessionType.php
  • src/Session/Factories/SessionFactory.php
  • src/Session/Session.php
  • src/Storage/Enums/FileSystemType.php
  • src/Storage/Factories/FileSystemFactory.php
  • src/Storage/FileSystem.php
  • tests/Unit/App/Factories/AppFactoryTest.php
  • tests/Unit/AppTestCase.php
  • tests/Unit/Archive/Factories/ArchiveFactoryTest.php
  • tests/Unit/Auth/Factories/AuthFactoryTest.php
  • tests/Unit/Auth/Helpers/AuthHelperFunctionsTest.php
  • tests/Unit/Cache/Factories/CacheFactoryTest.php
  • tests/Unit/Cache/Helpers/CacheHelperFunctionsTest.php
  • tests/Unit/Captcha/Factories/CaptchaFactoryTest.php
  • tests/Unit/Captcha/Helpers/CaptchaHelperFunctionsTest.php
  • tests/Unit/Encryption/Factories/CryptorFactoryTest.php
  • tests/Unit/Encryption/Helpers/CryptorHelperFunctionsTest.php
  • tests/Unit/Logger/Factories/LoggerFactoryTest.php
  • tests/Unit/Logger/Helpers/LoggerHelperFunctionsTest.php
  • tests/Unit/Mailer/Factories/MailerFactoryTest.php
  • tests/Unit/Mailer/Helpers/MailerHelperFunctionsTest.php
  • tests/Unit/Paginator/Factories/PaginatorFactoryTest.php
  • tests/Unit/Renderer/Factories/RendererFactoryTest.php
  • tests/Unit/Session/Factories/SessionFactoryTest.php
  • tests/Unit/Session/Helpers/SessionHelperFunctionsTest.php
  • tests/Unit/Storage/Factories/FileSystemFactoryTest.php
  • tests/Unit/Storage/Helpers/FileSystemHelperFunctionsTest.php
💤 Files with no reviewable changes (12)
  • src/App/App.php
  • src/Archive/Archive.php
  • src/Encryption/Cryptor.php
  • src/Captcha/Captcha.php
  • src/Logger/Logger.php
  • src/Paginator/Paginator.php
  • src/Session/Session.php
  • src/Auth/Auth.php
  • src/Renderer/Renderer.php
  • src/Cache/Cache.php
  • src/Storage/FileSystem.php
  • src/Mailer/Mailer.php

@armanist armanist merged commit 404fcb5 into softberg:master Mar 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract adapter-type constants from main classes into dedicated Enum classes

2 participants