Conditions | 15 |
Paths | 129 |
Total Lines | 55 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
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 |
||
51 | public function load($resource, $type = null) |
||
52 | { |
||
53 | $processor = new Processor(); |
||
54 | $configurationDefinition = new Configuration(); |
||
55 | |||
56 | $configuration = Yaml::parse($resource); |
||
57 | $configuration = $processor->processConfiguration($configurationDefinition, ['routing' => $configuration]); |
||
58 | |||
59 | if (!empty($configuration['only']) && !empty($configuration['except'])) { |
||
60 | throw new \InvalidArgumentException('You can configure only one of "except" & "only" options.'); |
||
61 | } |
||
62 | |||
63 | $routesToGenerate = ['show', 'index', 'create', 'update', 'delete']; |
||
64 | |||
65 | if (!empty($configuration['only'])) { |
||
66 | $routesToGenerate = $configuration['only']; |
||
67 | } |
||
68 | if (!empty($configuration['except'])) { |
||
69 | $routesToGenerate = array_diff($routesToGenerate, $configuration['except']); |
||
70 | } |
||
71 | |||
72 | $isApi = $type === 'sylius.resource_api'; |
||
73 | |||
74 | $metadata = $this->resourceRegistry->get($configuration['alias']); |
||
75 | $routes = $this->routeFactory->createRouteCollection(); |
||
76 | |||
77 | $rootPath = sprintf('/%s/', isset($configuration['path']) ? $configuration['path'] : Urlizer::urlize($metadata->getPluralName())); |
||
78 | |||
79 | if (in_array('index', $routesToGenerate)) { |
||
80 | $indexRoute = $this->createRoute($metadata, $configuration, $rootPath, 'index', ['GET']); |
||
81 | $routes->add($this->getRouteName($metadata, $configuration, 'index'), $indexRoute); |
||
82 | } |
||
83 | |||
84 | if (in_array('create', $routesToGenerate)) { |
||
85 | $createRoute = $this->createRoute($metadata, $configuration, $isApi ? $rootPath : $rootPath.'new', 'create', $isApi ? ['POST'] : ['GET', 'POST']); |
||
86 | $routes->add($this->getRouteName($metadata, $configuration, 'create'), $createRoute); |
||
87 | } |
||
88 | |||
89 | if (in_array('update', $routesToGenerate)) { |
||
90 | $updateRoute = $this->createRoute($metadata, $configuration, $isApi ? $rootPath.'{id}' : $rootPath.'{id}/edit', 'update', $isApi ? ['PUT', 'PATCH'] : ['GET', 'PUT', 'PATCH']); |
||
91 | $routes->add($this->getRouteName($metadata, $configuration, 'update'), $updateRoute); |
||
92 | } |
||
93 | |||
94 | if (in_array('show', $routesToGenerate)) { |
||
95 | $showRoute = $this->createRoute($metadata, $configuration, $rootPath.'{id}', 'show', ['GET']); |
||
96 | $routes->add($this->getRouteName($metadata, $configuration, 'show'), $showRoute); |
||
97 | } |
||
98 | |||
99 | if (in_array('delete', $routesToGenerate)) { |
||
100 | $deleteRoute = $this->createRoute($metadata, $configuration, $rootPath.'{id}', 'delete', ['DELETE']); |
||
101 | $routes->add($this->getRouteName($metadata, $configuration, 'delete'), $deleteRoute); |
||
102 | } |
||
103 | |||
104 | return $routes; |
||
105 | } |
||
106 | |||
183 |