Skip to content

Commit

Permalink
refactor: cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Apr 16, 2023
1 parent 1e1d7c7 commit c4c4036
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions src/Step/Data/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getName(): string
*/
public function init(array $options): void
{
if (is_dir($this->builder->getConfig()->getDataPath()) && (bool) $this->config->get('data.load')) {
if (is_dir($this->config->getDataPath()) && (bool) $this->config->get('data.load')) {
$this->canProcess = true;
}
}
Expand All @@ -53,8 +53,8 @@ public function process(): void
{
$files = Finder::create()
->files()
->in($this->builder->getConfig()->getDataPath())
->name('/\.(' . implode('|', (array) $this->builder->getConfig()->get('data.ext')) . ')$/')
->in($this->config->getDataPath())
->name('/\.(' . implode('|', (array) $this->config->get('data.ext')) . ')$/')
->sortByName(true);
$total = count($files);

Expand Down Expand Up @@ -103,7 +103,7 @@ function ($severity, $message, $file, $line) {
$basename = $file->getBasename('.' . $file->getExtension());
$subpath = \Cecil\Util\File::getFS()->makePathRelative(
$file->getPath(),
$this->builder->getConfig()->getDataPath()
$this->config->getDataPath()
);
$subpath = trim($subpath, './');
$array = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Step/Pages/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function init(array $options): void
{
parent::init($options);

if (is_dir($this->builder->getConfig()->getPagesPath())) {
if (is_dir($this->config->getPagesPath())) {
$this->canProcess = true;
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ public function process(): void
$this->builder->getPages()->remove($page->getId());
continue;
} catch (\Exception $e) {
$this->builder->getLogger()->error(\sprintf('Unable to convert "%s": %s', Util::joinPath(Util\File::getFS()->makePathRelative($page->getFilePath(), $this->builder->getConfig()->getPagesPath())), $e->getMessage()));
$this->builder->getLogger()->error(\sprintf('Unable to convert "%s": %s', Util::joinPath(Util\File::getFS()->makePathRelative($page->getFilePath(), $this->config->getPagesPath())), $e->getMessage()));
$this->builder->getPages()->remove($page->getId());
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Step/Pages/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function init(array $options): void
{
$this->builder->setPages(new PagesCollection('all-pages'));

if (is_dir($this->builder->getConfig()->getPagesPath())) {
if (is_dir($this->config->getPagesPath())) {
$this->canProcess = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Step/Pages/Generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getName(): string
*/
public function init(array $options): void
{
if (count((array) $this->builder->getConfig()->get('generators')) > 0) {
if (count((array) $this->config->get('generators')) > 0) {
$this->canProcess = true;
}
}
Expand All @@ -49,7 +49,7 @@ public function process(): void

Util::autoload($this->builder, 'generators');

$generators = (array) $this->builder->getConfig()->get('generators');
$generators = (array) $this->config->get('generators');
array_walk($generators, function ($generator, $priority) use ($generatorManager) {
if (!class_exists($generator)) {
$message = \sprintf('Unable to load generator "%s".', $generator);
Expand Down
28 changes: 14 additions & 14 deletions src/Step/Pages/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function getName(): string
public function init(array $options): void
{
// legacy support
if (is_dir(Util::joinFile($this->builder->getConfig()->getSourceDir(), 'content'))) {
if (is_dir(Util::joinFile($this->config->getSourceDir(), 'content'))) {
$this->builder->getLogger()->alert('"content" directory is deprecated, please rename it to "pages"');
}

if (!is_dir($this->builder->getConfig()->getPagesPath())) {
throw new RuntimeException(\sprintf('Pages path "%s" not found.', $this->builder->getConfig()->getPagesPath()));
if (!is_dir($this->config->getPagesPath())) {
throw new RuntimeException(\sprintf('Pages path "%s" not found.', $this->config->getPagesPath()));
}

$this->page = $options['page'];
Expand All @@ -57,39 +57,39 @@ public function init(array $options): void
*/
public function process(): void
{
$namePattern = '/\.(' . implode('|', (array) $this->builder->getConfig()->get('pages.ext')) . ')$/';
$namePattern = '/\.(' . implode('|', (array) $this->config->get('pages.ext')) . ')$/';
$content = Finder::create()
->files()
->in($this->builder->getConfig()->getPagesPath())
->in($this->config->getPagesPath())
->sortByName(true);
// load only one page?
if ($this->page) {
// is the page path starts with the `pages.dir` configuration option?
// (i.e.: `pages/...`, `/pages/...`, `./pages/...`)
$pagePathAsArray = explode(DIRECTORY_SEPARATOR, $this->page);
if ($pagePathAsArray[0] == (string) $this->builder->getConfig()->get('pages.dir')) {
if ($pagePathAsArray[0] == (string) $this->config->get('pages.dir')) {
unset($pagePathAsArray[0]);
$this->page = implode(DIRECTORY_SEPARATOR, $pagePathAsArray);
}
if ($pagePathAsArray[0] == '.' && $pagePathAsArray[1] == (string) $this->builder->getConfig()->get('pages.dir')) {
if ($pagePathAsArray[0] == '.' && $pagePathAsArray[1] == (string) $this->config->get('pages.dir')) {
unset($pagePathAsArray[0]);
unset($pagePathAsArray[1]);
$this->page = implode(DIRECTORY_SEPARATOR, $pagePathAsArray);
}
if (!util\File::getFS()->exists(Util::joinFile($this->builder->getConfig()->getPagesPath(), $this->page))) {
if (!util\File::getFS()->exists(Util::joinFile($this->config->getPagesPath(), $this->page))) {
$this->builder->getLogger()->error(sprintf('File "%s" doesn\'t exist.', $this->page));
}
$content->path('.')->path(dirname($this->page));
$content->name('/index\.(' . implode('|', (array) $this->builder->getConfig()->get('pages.ext')) . ')$/');
$content->name('/index\.(' . implode('|', (array) $this->config->get('pages.ext')) . ')$/');
$namePattern = basename($this->page);
}
$content->name($namePattern);
if (is_array($this->builder->getConfig()->get('pages.exclude'))) {
$content->exclude($this->builder->getConfig()->get('pages.exclude'));
$content->notPath($this->builder->getConfig()->get('pages.exclude'));
$content->notName($this->builder->getConfig()->get('pages.exclude'));
if (is_array($this->config->get('pages.exclude'))) {
$content->exclude($this->config->get('pages.exclude'));
$content->notPath($this->config->get('pages.exclude'));
$content->notName($this->config->get('pages.exclude'));
}
if (file_exists(Util::joinFile($this->builder->getConfig()->getPagesPath(), '.gitignore'))) {
if (file_exists(Util::joinFile($this->config->getPagesPath(), '.gitignore'))) {
$content->ignoreVCSIgnored(true);
}
$this->builder->setPagesFiles($content);
Expand Down
8 changes: 4 additions & 4 deletions src/Step/PostProcess/AbstractPostProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public function init(array $options): void
if ($options['dry-run']) {
return;
}
if (false === $this->builder->getConfig()->get(\sprintf('postprocess.%s.enabled', $this->type))) {
if (false === $this->config->get(\sprintf('postprocess.%s.enabled', $this->type))) {
return;
}
if (true === $this->builder->getConfig()->get('postprocess.enabled')) {
if (true === $this->config->get('postprocess.enabled')) {
$this->canProcess = true;
}
}
Expand All @@ -55,14 +55,14 @@ public function process(): void
{
$this->setProcessor();

$extensions = (array) $this->builder->getConfig()->get(\sprintf('postprocess.%s.ext', $this->type));
$extensions = (array) $this->config->get(\sprintf('postprocess.%s.ext', $this->type));
if (empty($extensions)) {
throw new RuntimeException(\sprintf('The config key "postprocess.%s.ext" is empty', $this->type));
}

$files = Finder::create()
->files()
->in($this->builder->getConfig()->getOutputPath())
->in($this->config->getOutputPath())
->name('/\.(' . implode('|', $extensions) . ')$/')
->notName('/\.min\.(' . implode('|', $extensions) . ')$/')
->sortByName(true);
Expand Down
2 changes: 1 addition & 1 deletion src/Step/StaticFiles/Load.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getName(): string
*/
public function init(array $options): void
{
if (is_dir($this->builder->getConfig()->getStaticPath()) && (bool) $this->config->get('static.load')) {
if (is_dir($this->config->getStaticPath()) && (bool) $this->config->get('static.load')) {
$this->canProcess = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Step/Taxonomies/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getName(): string
*/
public function init(array $options): void
{
if (is_dir($this->builder->getConfig()->getPagesPath()) && $this->hasTaxonomies()) {
if (is_dir($this->config->getPagesPath()) && $this->hasTaxonomies()) {
$this->canProcess = true;
}
}
Expand Down

0 comments on commit c4c4036

Please sign in to comment.