Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Temporal coupling in InstallComposerDevDependencyTaskExecutor #92

Open
rjkip opened this issue Feb 17, 2017 · 1 comment
Open

Temporal coupling in InstallComposerDevDependencyTaskExecutor #92

rjkip opened this issue Feb 17, 2017 · 1 comment

Comments

@rjkip
Copy link
Contributor

rjkip commented Feb 17, 2017

Originally submitted by @rpkamp:

The InstallComposerDevDependencyTaskExecutor has a temporal coupling problem with the arePrerequisitesMet and execute methods. Namely, if you call execute without calling arePrerequisitesMet first, the tool will blow up because the class property composerProject is not set yet.

Although this is not a big problem because the class is only called in a fixed manner from outside, it would be nice to rid of this temporal coupling by somehow preventing execute from running if arePrerequisitesMet hasn't run yet, and maybe also when arePrerequisitesMet did run but the prerequisites were not met.

A relatively easy way to do this would be something like

private $arePrerequisitesMet = false;

public function arePrerequisitesMet(...)
{
    // some checking here
    $this->arePrerequisitesMet = true;
}

public function execute()
{
    if (!$this->arePrerequisitesMet) {
        throw new RuntimeException(
            sprintf(
                'Either the prerequisites for "%s" have not been checked, or they have not been met.',
                get_class($this)
            )
        );
    }
    // execute code
}
@rjkip
Copy link
Contributor Author

rjkip commented Feb 17, 2017

I must note that it's currently by design; consumers of the Executor API must take this temporal coupling into account. This design was put in place to keep Executors simple and it wasn't a conscious decision to incur technical debt to further the project. Not sure I like putting the suggested checks in place in all Executors. I'm still open to being convinced otherwise or to other solutions, though 😉

@rjkip rjkip added this to the 3.1.0 milestone Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant