-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description
Refactor classes using GeneralUtility::makeInstance() to use modern constructor-based dependency injection where possible.
Current State
- 11 files using
GeneralUtility::makeInstance() - Some usage is legitimate (TYPO3 singletons), but many can be refactored
- TYPO3 Conformance Report: PHP Architecture score 18/20 (-1 for makeInstance usage)
Files Using makeInstance
Classes/Controller/TranslationController.php
Classes/ViewHelpers/TranslateViewHelper.php
Classes/ViewHelpers/TextdbViewHelper.php
Classes/Service/TranslationService.php
Classes/Service/ImportService.php
Classes/Command/ImportCommand.php
Classes/Domain/Repository/AbstractRepository.php
Classes/Domain/Repository/TranslationRepository.php
Classes/Domain/Repository/TypeRepository.php
Classes/Domain/Repository/EnvironmentRepository.php
Classes/Domain/Repository/ComponentRepository.php
Proposed Changes
1. Analyze Each Usage
- Categorize as "Must use makeInstance" (TYPO3 singletons)
- Categorize as "Can refactor to DI" (services, repositories)
2. Refactor Services
Before:
$service = GeneralUtility::makeInstance(SomeService::class);After:
public function __construct(
private readonly SomeService $someService
) {}3. Update Configuration/Services.yaml
Ensure all services are properly autowired
4. Keep Legitimate Usage
Some TYPO3 APIs require makeInstance():
- IconFactory (singleton)
- ConnectionPool (database)
- LanguageService (in some contexts)
Benefits
- Better testability with mocking
- Explicit dependencies
- Modern TYPO3 patterns
- Improved maintainability
Acceptance Criteria
- All refactorable makeInstance() calls converted to DI
- Remaining makeInstance() calls documented as necessary
- Services.yaml updated if needed
- Tests updated to use dependency injection
- No functionality regressions
Priority
Low - Code quality improvement, not blocking
Related
TYPO3 Conformance Report: PHP Architecture +1 point
Copilot
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request