Completed
Pull Request — master (#5)
by Matheus
05:31
created

FakerServiceProvider.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace EmanueleMinotto\FakerServiceProvider;
4
5
use Faker\Factory;
6
use Silex\Application;
7
use Silex\ServiceProviderInterface;
8
9
/**
10
 * A Faker service provider for Silex 1.
11
 *
12
 * @author Emanuele Minotto <[email protected]>
13
 *
14
 * @link http://silex.sensiolabs.org/doc/providers.html#creating-a-provider
15
 */
16
class FakerServiceProvider implements ServiceProviderInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function register(Application $app)
22
    {
23
        $app['faker'] = null;
24
        $app['faker.providers'] = [];
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function boot(Application $app)
31
    {
32
        // generator instance
33
        $app['faker'] = $app->share(function ($app) {
0 ignored issues
show
The method share() does not seem to exist on object<Silex\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
            return Factory::create($app['locale']);
35
        });
36
37
        // third-party providers
38
        $providers = array_filter((array) $app['faker.providers'], function ($provider) {
39
            return class_exists($provider) && is_subclass_of($provider, 'Faker\\Provider\\Base');
40
        });
41
42
        foreach ($providers as $provider) {
43
            $app['faker']->addProvider(new $provider($app['faker']));
44
        }
45
    }
46
}
47