Conditions | 11 |
Paths | 12 |
Total Lines | 65 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
48 | public function process(): void |
||
49 | { |
||
50 | if (count($this->builder->getPagesFiles()) == 0) { |
||
51 | return; |
||
52 | } |
||
53 | |||
54 | $max = count($this->builder->getPagesFiles()); |
||
55 | $count = 0; |
||
56 | /** @var \Symfony\Component\Finder\SplFileInfo $file */ |
||
57 | foreach ($this->builder->getPagesFiles() as $file) { |
||
58 | $count++; |
||
59 | /** @var Page $page */ |
||
60 | $page = new Page(Page::createId($file)); |
||
61 | $page->setFile($file)->parse(); |
||
62 | |||
63 | /* |
||
64 | * Apply an - optional - custom path to pages of a section. |
||
65 | * |
||
66 | * ```yaml |
||
67 | * paths: |
||
68 | * - section: Blog |
||
69 | * language: fr # optional |
||
70 | * path: :section/:year/:month/:day/:slug |
||
71 | * ``` |
||
72 | */ |
||
73 | if (is_array($this->config->get('paths'))) { |
||
74 | foreach ($this->config->get('paths') as $entry) { |
||
75 | if (isset($entry['section'])) { |
||
76 | /** @var Page $page */ |
||
77 | if ($page->getSection() == Page::slugify($entry['section'])) { |
||
78 | if ((isset($entry['language']) && $entry['language'] != $page->getVariable('language'))) { |
||
79 | break; |
||
80 | } |
||
81 | if (isset($entry['path'])) { |
||
82 | $path = str_replace( |
||
83 | [ |
||
84 | ':year', |
||
85 | ':month', |
||
86 | ':day', |
||
87 | ':section', |
||
88 | ':slug', |
||
89 | ], |
||
90 | [ |
||
91 | $page->getVariable('date')->format('Y'), |
||
92 | $page->getVariable('date')->format('m'), |
||
93 | $page->getVariable('date')->format('d'), |
||
94 | $page->getSection(), |
||
95 | $page->getSlug(), |
||
96 | ], |
||
97 | $entry['path'] |
||
98 | ); |
||
99 | $page->setPath(trim($path, '/')); |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | |||
106 | // add the page to pages collection only if its language is defined in configuration |
||
107 | if (in_array($page->getVariable('language', $this->config->getLanguageDefault()), array_column($this->config->getLanguages(), 'code'))) { |
||
108 | $this->builder->getPages()->add($page); |
||
109 | } |
||
110 | |||
111 | $message = \sprintf('Page "%s" created', $page->getId()); |
||
112 | $this->builder->getLogger()->info($message, ['progress' => [$count, $max]]); |
||
113 | } |
||
116 |