GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

YamlRouteServiceProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 9
c 5
b 1
f 0
lcom 1
cbo 7
dl 0
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A boot() 0 3 1
A getConfigCacheFactory() 0 8 2
A loadRouteCollection() 0 8 1
B register() 0 24 2
1
<?php
2
3
namespace Junker\Silex\Provider;
4
5
use Silex\Application;
6
use Silex\ServiceProviderInterface;
7
use Symfony\Component\Config\ConfigCacheInterface;
8
use Symfony\Component\Config\ConfigCacheFactory;
9
use Symfony\Component\Routing\Loader\YamlFileLoader;
10
use Symfony\Component\Routing\RouteCollection;
11
use Symfony\Component\Config\FileLocator;
12
use Junker\Silex\PhpRouteCollectionDumper;
13
14
class YamlRouteServiceProvider implements ServiceProviderInterface
15
{
16
    protected $cacheDirPath;
17
    protected $configFilePath;
18
    protected $configCacheFactory;
19
20
    /**
21
     * @param string     $configFilePath Path to config file
22
     * @param null|array $options        Provider options
23
     */
24
    public function __construct($configFilePath, $options = null)
25
    {
26
        if (is_array($options)) {
27
            if (isset($options['cache_dir'])) {
28
                $this->cacheDirPath = $options['cache_dir'];
29
            }
30
        }
31
32
        $this->configFilePath = $configFilePath;
33
    }
34
35
    public function register(Application $app)
36
    {
37
        $app['routes'] = $app->share($app->extend('routes', function(RouteCollection $routes, Application $app) {
38
            if ($this->cacheDirPath) {
39
                $cache = $this->getConfigCacheFactory($app['debug'])->cache($this->cacheDirPath.'/routes.cache.php',
40
                    function(ConfigCacheInterface $cache) {
41
                        $collection = $this->loadRouteCollection();
42
43
                        $content = PhpRouteCollectionDumper::dump($collection);
44
45
                        $cache->write($content, $collection->getResources());
46
                    }
47
                );
48
49
                $collection = include $cache->getPath();
50
            } else {
51
                $collection = $this->loadRouteCollection();
52
            }
53
54
            $routes->addCollection($collection);
55
56
            return $routes;
57
        }));
58
    }
59
60
    public function boot(Application $app)
61
    {
62
    }
63
64
    /**
65
     * @param bool $debug Is debug mode enabled
66
     *
67
     * @return ConfigCacheFactory
68
     */
69
    private function getConfigCacheFactory($debug)
70
    {
71
        if ($this->configCacheFactory === null) {
72
            $this->configCacheFactory = new ConfigCacheFactory($debug);
73
        }
74
75
        return $this->configCacheFactory;
76
    }
77
78
    protected function loadRouteCollection()
79
    {
80
        $loader = new YamlFileLoader(new FileLocator(dirname($this->configFilePath)));
81
82
        $collection = $loader->load($this->configFilePath);
83
84
        return $collection;
85
    }
86
}
87