Conditions | 14 |
Paths | 58 |
Total Lines | 65 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
47 | public function load($type, $parameters, $responseType = LoaderInterface::SINGLE) |
||
48 | { |
||
49 | $dm = $this->serviceContainer->get('doctrine_phpcr.odm.document_manager'); |
||
50 | $configurationPath = $this->serviceContainer->getParameter('kernel.root_dir').'/Resources/meta/article.yml'; |
||
51 | $metadataCache = $this->serviceContainer->get('doctrine_cache.providers.main_cache'); |
||
52 | |||
53 | $article = null; |
||
54 | if (empty($parameters)) { |
||
55 | $parameters = []; |
||
56 | } |
||
57 | |||
58 | // Cache meta configuration |
||
59 | $cacheKey = md5($configurationPath); |
||
60 | if (!$metadataCache->contains($cacheKey)) { |
||
61 | if (!is_readable($configurationPath)) { |
||
62 | throw new \InvalidArgumentException('Configuration file is not readable for parser'); |
||
63 | } |
||
64 | $yaml = new Parser(); |
||
65 | $configuration = $yaml->parse(file_get_contents($configurationPath)); |
||
66 | $metadataCache->save($cacheKey, $configuration); |
||
67 | } else { |
||
68 | $configuration = $metadataCache->fetch($cacheKey); |
||
69 | } |
||
70 | |||
71 | if ($responseType === LoaderInterface::SINGLE) { |
||
72 | if (array_key_exists('contentPath', $parameters)) { |
||
73 | $article = $dm->find('SWP\Bundle\ContentBundle\Document\Article', $parameters['contentPath']); |
||
74 | } elseif (array_key_exists('article', $parameters)) { |
||
75 | $article = $parameters['article']; |
||
76 | } elseif (array_key_exists('slug', $parameters)) { |
||
77 | $article = $dm->getRepository('SWP\Bundle\ContentBundle\Document\Article') |
||
78 | ->findOneBy(array('slug' => $parameters['slug'])); |
||
79 | } |
||
80 | |||
81 | if (!is_null($article)) { |
||
82 | return new Meta($configuration, $article); |
||
83 | } |
||
84 | } elseif ($responseType === LoaderInterface::COLLECTION) { |
||
85 | if (array_key_exists('route', $parameters)) { |
||
86 | $pathBuilder = $this->serviceContainer->get('swp_multi_tenancy.path_builder'); |
||
87 | $route = $dm->find(null, $pathBuilder->build( |
||
88 | $this->serviceContainer->getParameter( |
||
89 | 'swp_multi_tenancy.persistence.phpcr.route_basepaths' |
||
90 | )[0].$parameters['route'] |
||
91 | )); |
||
92 | |||
93 | if ($route) { |
||
94 | $articles = $dm->getReferrers($route, null, null, null, 'SWP\Bundle\ContentBundle\Document\Article'); |
||
95 | $metas = []; |
||
96 | foreach ($articles as $article) { |
||
97 | if (!is_null($article)) { |
||
98 | $metas[] = new Meta( |
||
99 | $configuration, |
||
100 | $article |
||
101 | ); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | return $metas; |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 | |||
110 | return false; |
||
111 | } |
||
112 | |||
125 |