Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use call_user_func_array instead of switch on option count #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 3 additions & 25 deletions src/PatternLab/Faker/PatternLabListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,10 @@ public function formatOptionsAndFake($formatter, $options) {

// get explodey
$options = explode(",", $options);
$count = count($options);

// clean up the options
$option0 = $this->clean($options[0]);
$option1 = isset($options[1]) ? $this->clean($options[1]) : "";
$option2 = isset($options[2]) ? $this->clean($options[2]) : "";
$option3 = isset($options[3]) ? $this->clean($options[3]) : "";
$option4 = isset($options[4]) ? $this->clean($options[4]) : "";
$option5 = isset($options[5]) ? $this->clean($options[5]) : "";
$option6 = isset($options[6]) ? $this->clean($options[6]) : "";

// probably should have used a switch. i'm lazy
$cleaned_options = array_map(array($this, 'clean'), $options);

try {
if ($count === 6) {
return $this->faker->$formatter($option0,$option1,$option2,$option3,$option4,$option5);
} else if ($count === 5) {
return $this->faker->$formatter($option0,$option1,$option2,$option3,$option4);
} else if ($count === 4) {
return $this->faker->$formatter($option0,$option1,$option2,$option3);
} else if ($count === 3) {
return $this->faker->$formatter($option0,$option1,$option2);
} else if ($count === 2) {
return $this->faker->$formatter($option0,$option1);
} else {
return $this->faker->$formatter($option0);
}
return call_user_func_array(array($this->faker, $formatter), $cleaned_options);
} catch (\InvalidArgumentException $e) {
Console::writeWarning("Faker plugin error: ".$e->getMessage()."...");
}
Expand Down