Skip to content

Commit

Permalink
Generate/Validate skeleton by arbitrary path.
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehr committed Jan 21, 2017
1 parent 5672cc8 commit 3c1069d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/ComplianceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class ComplianceValidator

protected $files = null;

public function execute()
public function execute($root = null)
{
$lines = $this->getFiles();
$lines = $this->getFiles($root);
$results = $this->validate($lines);
$this->outputResults($results);
return true;
Expand Down Expand Up @@ -52,10 +52,12 @@ public function validate($lines)
/**
* Get list of files and directories previously set, or generate from parent project.
*/
public function getFiles()
public function getFiles($root = null)
{
$root = $root ?: __DIR__ . '/../../../../';

if ($this->files == null) {
$files = scandir(__DIR__ . "/../../../../");
$files = scandir($root);
foreach ($files as $i => $file) {
if (is_dir($file)) {
$files[$i] .= "/";
Expand Down
2 changes: 1 addition & 1 deletion src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function execute($args)
protected function executeCommand($commandClass, $args)
{
$command = new $commandClass();
return $command->execute($args);
return $command->execute(...$args);
}

protected function outputHelp()
Expand Down
12 changes: 7 additions & 5 deletions src/PackageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

class PackageGenerator
{
public function execute()
public function execute($root = null)
{
$validator = new ComplianceValidator();
$lines = $validator->getFiles();
$validatorResults = $validator->validate($lines);
$files = $this->createFiles($validatorResults);
$files = $this->createFiles($validatorResults, $root);
$this->outputResults($files);
return true;
}

public function createFiles($validatorResults, $root = null)
{
if ($root == null) {
$root = realpath(__DIR__ . "/../../../../");
}
$root = $root ?: __DIR__ . '/../../../../';
$root = realpath($root);

$files = $this->createFileList($validatorResults);
$createdFiles = [];

foreach ($files as $i => $file) {
$isDir = substr($file, -1, 1) == '/';
if ($isDir) {
Expand All @@ -33,6 +34,7 @@ public function createFiles($validatorResults, $root = null)
file_put_contents($path, '');
chmod($path, 0644);
}

return $createdFiles;
}

Expand Down

0 comments on commit 3c1069d

Please sign in to comment.