Conditions | 8 |
Paths | 10 |
Total Lines | 63 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 3 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
28 | public function load(array $configs, ContainerBuilder $container) |
||
29 | { |
||
30 | $config = $this->processConfiguration(new Configuration(), $configs); |
||
31 | |||
32 | $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/services')); |
||
33 | $loader->load('server.xml'); |
||
34 | $loader->load('extensions.xml'); |
||
35 | $loader->load('empty.xml'); |
||
36 | $loader->load('orm.xml'); |
||
37 | |||
38 | if (!$container->hasDefinition('majora.oauth.server')) { |
||
39 | return; |
||
40 | } |
||
41 | |||
42 | // folder path storage : required for doctrine schema registery |
||
43 | $container->setParameter('majora.oauth.bundle_dir', realpath(__DIR__.'/..')); |
||
44 | |||
45 | // token generator |
||
46 | $randomGeneratorDefinition = $container->getDefinition('majora.oauth.random_generator'); |
||
47 | $randomGeneratorDefinition->replaceArgument(0, $config['secret']); |
||
48 | |||
49 | // server |
||
50 | $serverDefinition = $container->getDefinition('majora.oauth.server'); |
||
51 | $serverDefinition->replaceArgument(4, array( |
||
52 | 'access_token_class' => $config['access_token']['class'], |
||
53 | 'access_token_ttl' => $config['access_token']['ttl'], |
||
54 | 'refresh_token_class' => $config['refresh_token']['class'], |
||
55 | 'refresh_token_ttl' => $config['refresh_token']['ttl'], |
||
56 | )); |
||
57 | |||
58 | // aliases generation |
||
59 | foreach (array('access_token', 'refresh_token', 'application', 'account') as $entity) { |
||
60 | foreach (array('loader', 'repository') as $serviceAlias) { |
||
61 | foreach ($config[$entity][$serviceAlias] as $driver => $parameters) { |
||
62 | |||
63 | // given service id or build one from registered strategies |
||
64 | $serviceId = $driver == 'id' ? |
||
65 | $parameters : |
||
66 | sprintf('majora.oauth.%s.%s_%s', $entity, $driver, $serviceAlias) |
||
67 | ; |
||
68 | |||
69 | // publish given service |
||
70 | $container->setAlias( |
||
71 | sprintf('majora.oauth.%s.%s', $entity, $serviceAlias), |
||
72 | $serviceId |
||
73 | ); |
||
74 | |||
75 | // register parameters under driver if given |
||
76 | // |
||
77 | // !! implements here a better strategy !! |
||
78 | // |
||
79 | if (is_array($parameters)) { |
||
80 | foreach ($parameters as $key => $value) { |
||
81 | $container->setParameter( |
||
82 | sprintf('majora.oauth.%s.%s_%s.%s', $entity, $driver, $serviceAlias, $key), |
||
83 | $value |
||
84 | ); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | } |
||
92 |