Skip to content

Latest commit

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

ScienceBoilerplate

DoesScience trait handles some of the boilerplate associated with performing experimental code refactoring using the PHP port of Scientist by Dayle Rees which is itself inspired by GitHub's Scientist.

Example refactoring

<?phpclass myClass
{
publicfunctionmain()
{
$result = $this->oldCreakyMethod();
}
// ...
}

Lets refactor oldCreakyMethod by starting from some boilerplate:

<?phpclass myClass
{
use \thinkspill\DoesScience;
publicfunctionmain()
{
/** boilerplate start */$control = function (...$vars) {
returncall_user_func_array([$this, 'oldCreakyMethod'], func_get_args());
};
$trial = function (...$vars) {
returncall_user_func_array([$this, 'newShinyMethod'], func_get_args());
};
$this->makeScienceExperiment('Experiment Name', $control);
$this->addExperimentTrial('trial 1', $trial);
print_r($this->experimentReport($arg1, $arg2));
/** boilerplate end */// $result = $this->oldCreakyFunction($arg1, $arg2);
}
privatefunctionoldCreakyMethod($arg1, $arg2)
{ // ...
}
privatefunctionnewShinyMethod($arg1, $arg2)
{ // ...
}
}

The experiment boilerplate code gets copy/pasted into the code location that calls the method being refactored, and modified to call the correct control and trial methods.

The only call that needs to retain the actual arguments of the method under refactor are those in the experimentReport call, due to the use of variable arguments everywhere else.

The experimentReport method will return the results of each experiment and if they matched.

About

DoesScience trait handles some of the boilerplate associated with performing experimental code refactoring using Science!

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages