Skip to content

Commit

Permalink
Merge branch '1.x' of github.com:php-pds/skeleton into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Jan 22, 2017
2 parents 621974d + a8fe032 commit 75285aa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
8 changes: 6 additions & 2 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
Validate your project's compliance by following these steps:

- Install package in your project: `composer require pds/skeleton @dev`
- Run the validator: `vendor/bin/pds-skeleton validate`
- Run the validator: `vendor/bin/pds-skeleton validate [path]`

If no path is specified, the project in which pds-skeleton is installed will be used.

## Generator

Generate a compliant package skeleton by following these steps:

- Install package in your project: `composer require pds/skeleton @dev`
- Run the generator: `vendor/bin/pds-skeleton generate`
- Run the generator: `vendor/bin/pds-skeleton generate [path]`

If no path is specified, the project in which pds-skeleton is installed will be used.
13 changes: 8 additions & 5 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,12 +52,15 @@ 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__ . '/../../../../';
$root = realpath($root);

if ($this->files == null) {
$files = scandir(__DIR__ . "/../../../../");
$files = scandir($root);
foreach ($files as $i => $file) {
if (is_dir($file)) {
if (is_dir("$root/$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 75285aa

Please sign in to comment.