diff --git a/src/Faker/Generator.php b/src/Faker/Generator.php index 7c757c3790..dbb493f2c4 100644 --- a/src/Faker/Generator.php +++ b/src/Faker/Generator.php @@ -238,11 +238,20 @@ public function getFormatter($formatter) if (isset($this->formatters[$formatter])) { return $this->formatters[$formatter]; } + $this->formatters[$formatter] = $this->findFormatter($formatter); + return $this->formatters[$formatter]; + } + + /** + * @param string $formatter + * + * @return Callable + */ + protected function findFormatter($formatter) + { foreach ($this->providers as $provider) { if (method_exists($provider, $formatter)) { - $this->formatters[$formatter] = array($provider, $formatter); - - return $this->formatters[$formatter]; + return array($provider, $formatter); } } throw new \InvalidArgumentException(sprintf('Unknown formatter "%s"', $formatter));