Story
When I refactor LanguageConverter I want to avoid overriding constructors by children, so I can easily add/remove new arguments without changing code for all classes in the hierarchy.
Context
At the moment LanguageConverter:: __construct takes too many arguments:
public function __construct( $langobj, $maincode, $variants = [], $variantfallbacks = [], $flags = [], $manualLevel = [] ) { ...
Most of them (except $langobj) are constant and injected by inheritors:
class EnConverter extends LanguageConverter { public function __construct( $langobj ) { parent::__construct( $langobj, 'en', [ 'en', 'en-x-piglatin' ] ); } ...
As a possible solution, the idea is to turn such variables into protected getters overridden by inheritors. This will move a significant part of the logic to that constructors and make it possible not to override it.
Expected Result
- Turn $maincode, $variants, $variantfallbacks, $flags, $manualLevel into getters
- Override getters in inheritors of LanguageConverter
- Avoid overriding the constructor of inheritors when add/remove new argument.