| Conditions | 14 |
| Paths | 108 |
| Total Lines | 59 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 62 | public function process(): void |
||
| 63 | { |
||
| 64 | $namePattern = '/\.(' . implode('|', (array) $this->config->get('pages.ext')) . ')$/'; |
||
| 65 | $pages = Finder::create() |
||
| 66 | ->files() |
||
| 67 | ->in($this->config->getPagesPath()) |
||
| 68 | ->sort(function (SplFileInfo $a, SplFileInfo $b): int { |
||
| 69 | // section's index first |
||
| 70 | if ($a->getRelativePath() == $b->getRelativePath() && $a->getBasename('.' . $a->getExtension()) == 'index') { |
||
| 71 | return -1; |
||
| 72 | } |
||
| 73 | if ($b->getRelativePath() == $a->getRelativePath() && $b->getBasename('.' . $b->getExtension()) == 'index') { |
||
| 74 | return 1; |
||
| 75 | } |
||
| 76 | // sort by name |
||
| 77 | return strnatcasecmp($a->getRealPath(), $b->getRealPath()); |
||
| 78 | }); |
||
| 79 | // load only one page? |
||
| 80 | if ($this->page) { |
||
| 81 | // is the page path starts with the `pages.dir` configuration option? |
||
| 82 | // (i.e.: `pages/...`, `/pages/...`, `./pages/...`) |
||
| 83 | $pagePathAsArray = explode(DIRECTORY_SEPARATOR, Util::joinFile($this->page)); |
||
| 84 | if ($pagePathAsArray[0] == (string) $this->config->get('pages.dir')) { |
||
| 85 | unset($pagePathAsArray[0]); |
||
| 86 | $this->page = implode(DIRECTORY_SEPARATOR, $pagePathAsArray); |
||
| 87 | } |
||
| 88 | if ($pagePathAsArray[0] == '.' && $pagePathAsArray[1] == (string) $this->config->get('pages.dir')) { |
||
| 89 | unset($pagePathAsArray[0]); |
||
| 90 | unset($pagePathAsArray[1]); |
||
| 91 | $this->page = implode(DIRECTORY_SEPARATOR, $pagePathAsArray); |
||
| 92 | } |
||
| 93 | if (!util\File::getFS()->exists(Util::joinFile($this->config->getPagesPath(), $this->page))) { |
||
| 94 | $this->builder->getLogger()->error(\sprintf('File "%s" doesn\'t exist.', $this->page)); |
||
| 95 | } |
||
| 96 | $pages->path('.')->path(\dirname($this->page)); |
||
| 97 | $pages->name('/index\.(' . implode('|', (array) $this->config->get('pages.ext')) . ')$/'); |
||
| 98 | $namePattern = basename($this->page); |
||
| 99 | } |
||
| 100 | $pages->name($namePattern); |
||
| 101 | if (\is_array($exclude = $this->config->get('pages.exclude'))) { |
||
| 102 | $pages->exclude($exclude); |
||
| 103 | $pages->notPath($exclude); |
||
| 104 | $pages->notName($exclude); |
||
| 105 | } |
||
| 106 | if (file_exists(Util::joinFile($this->config->getPagesPath(), '.gitignore'))) { |
||
| 107 | $pages->ignoreVCSIgnored(true); |
||
| 108 | } |
||
| 109 | $this->builder->setPagesFiles($pages); |
||
| 110 | |||
| 111 | $total = $pages->count(); |
||
| 112 | $count = 0; |
||
| 113 | if ($total === 0) { |
||
| 114 | $this->builder->getLogger()->info('Nothing to load'); |
||
| 115 | |||
| 116 | return; |
||
| 117 | } |
||
| 118 | foreach ($pages as $file) { |
||
| 119 | $count++; |
||
| 120 | $this->builder->getLogger()->info(\sprintf('File "%s" loaded', $file->getRelativePathname()), ['progress' => [$count, $total]]); |
||
| 121 | } |
||
| 124 |