Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from SebSept/improve_index_filler
Browse files Browse the repository at this point in the history
-index.php at root is taken into account, was not treated before.
- fix & improve messages
  • Loading branch information
SebSept authored May 23, 2021
2 parents 34f5a88 + 0f66226 commit 7adb615
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Command/SebSept/IndexPhpFiller.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ private function addMissingIndexFiles(): void
foreach ($this->getDirectoryIterator() as $fileInfo) {
$this->addIndex($fileInfo);
}
// also at the root - I haven't found a way to include it in the iterator :/
$this->addIndex(new \SplFileInfo($this->getcwd()));
}

private function addIndex(\SplFileInfo $splFileInfo): void
Expand All @@ -107,16 +109,22 @@ private function checkMissingIndexes(): int
$indexPhpPath = $fileInfo->getPathname() . '/index.php';
$this->fs->exists($indexPhpPath) ?: array_push($missingIndexFiles, $indexPhpPath);
}
// plus index.php at root
$this->fs->exists($this->getcwd() . '/index.php') ?: array_push($missingIndexFiles, './index.php');

if (empty($missingIndexFiles)) {
$this->getIO()->write('Good : no missing index files.');

return 0;
}

$this->getIO()->write(':( Missing index.php files.');
$this->getIO()->write('<fg=red>✗ Missing index.php files.</>');
$this->getIO()->write('Missing index.php : ', true, IOInterface::VERBOSE);
$this->getIO()->write($missingIndexFiles, true, IOInterface::VERBOSE);
$this->getIO()->write(['Use <info>-v</info> option to list missing files', 'Remove <info>--check-only</info> option to add missing files.']);
$this->getIO()->write([
sprintf('Run <info>composer psdt:%s --check-only -v</info> option to list missing files', $this->getName()),
sprintf('Or run <info>composer psdt:%s</info> to add missing files.', $this->getName()),
]);

return 1;
}
Expand Down Expand Up @@ -144,6 +152,8 @@ private function getDirectoryIterator()
return (new Finder())
->in($this->getcwd())
->directories()
->ignoreDotFiles(false)
->ignoreVCS(true)
->exclude('vendor')
->getIterator();
}
Expand Down

0 comments on commit 7adb615

Please sign in to comment.