Problem/Motivation
In #3425218: Fix PHPStan errors we're trying to fix all PHPStan issues. However, there is one case that is a bit more challenging to fix there and that is about the State classes needing dependency injection:
------ ----------------------------------------------------------------------
Line src/Feeds/State/CleanState.php
------ ----------------------------------------------------------------------
70 \Drupal calls should be avoided in classes, use dependency injection
instead
167 \Drupal calls should be avoided in classes, use dependency injection
instead
------ ----------------------------------------------------------------------
------ ----------------------------------------------------------------------
Line src/State.php
------ ----------------------------------------------------------------------
155 \Drupal calls should be avoided in classes, use dependency injection
instead
169 \Drupal calls should be avoided in classes, use dependency injection
instead
------ ----------------------------------------------------------------------
In src/Entity/Feed.php, in the method getState() there is also a comment that creating State objects should happen in a factory instead:
/**
* {@inheritdoc}
*/
public function getState($stage) {
if (!isset($this->states[$stage])) {
$state = $this->getStateStorage()->get($stage);
if (empty($state)) {
// @todo move this logic to a factory or alike.
switch ($stage) {
case StateInterface::CLEAN:
$state = new CleanState($this->id());
break;
default:
$state = new State();
break;
}
}
$this->states[$stage] = $state;
}
return $this->states[$stage];
}
So that is what we should be doing on this issue.
Proposed resolution
Create a StateFactory and a StateFactoryInterface class. Make a service of the StateFactory class and use that in Feed::getState().
Remaining tasks
- Implement the StateFactory class and declare it as a service.
- Make use of the service in
Feed::getState().
User interface changes
API changes
Data model changes
Issue fork feeds-3456961
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
megachrizComment #5
megachrizI'm leaving this issue open for a few days before merging it.
Comment #7
megachrizI merged the code!