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