Conditions | 8 |
Paths | 16 |
Total Lines | 55 |
Code Lines | 39 |
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 |
||
69 | public function getContent($basePath, $post) |
||
70 | { |
||
71 | $breadcrumbs = $this->makeBreadcrumbsFromPost($post); |
||
72 | $title = $this->makeTitleFromBreadcrumbs($breadcrumbs); |
||
73 | |||
74 | $postPath = $basePath .($post? '/'. $post : ''); |
||
75 | $isDir = false; |
||
76 | $index = []; |
||
77 | |||
78 | if ($this->filesystem->isDirectory($postPath)) { |
||
79 | $isDir = true; |
||
80 | $index['subcategories'] = $this->filesystem->directories($postPath); |
||
81 | $index['files'] = $this->filesystem->files($postPath); |
||
82 | $postPath .= '/index'; |
||
83 | } |
||
84 | |||
85 | $file = $postPath.'.md'; |
||
86 | if ($this->filesystem->exists($file)) { |
||
87 | $post = $this->parser->parse($this->filesystem->get($file)); |
||
88 | } else { |
||
89 | $post = ''; |
||
90 | } |
||
91 | |||
92 | if ($isDir) { |
||
93 | foreach ($index['subcategories'] as $i => $item) { |
||
94 | $item = str_replace($basePath, '', $item); |
||
95 | $paths = explode('/', $item); |
||
96 | $name = array_pop($paths); |
||
97 | $index['subcategories'][$i] = [ |
||
98 | 'href' => $item, |
||
99 | 'name' => $this->deslugify($name), |
||
100 | ]; |
||
101 | } |
||
102 | foreach ($index['files'] as $i => $item) { |
||
103 | $item = str_replace($basePath, '', $item); |
||
104 | $item = str_replace('.md', '', $item); |
||
105 | $paths = explode('/', $item); |
||
106 | $name = array_pop($paths); |
||
107 | $index['files'][$i] = [ |
||
108 | 'href' => $item, |
||
109 | 'name' => $this->deslugify($name), |
||
110 | ]; |
||
111 | if ($index['files'][$i]['name'] === 'index') { |
||
112 | unset($index['files'][$i]); |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | |||
117 | return [ |
||
118 | 'title' => $title, |
||
119 | 'breadcrumbs' => $breadcrumbs, |
||
120 | 'index' => $index, |
||
121 | 'post' => $post, |
||
122 | ]; |
||
123 | } |
||
124 | |||
188 |