Skip to content

Commit

Permalink
vendor no longer mentioned in standard; LICENSE now recommended
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul M. Jones committed Jan 8, 2017
1 parent 1cf5a67 commit 168881e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 48 deletions.
41 changes: 17 additions & 24 deletions src/ComplianceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ComplianceValidator
{
const STATE_OPTIONAL_NOT_PRESENT = 1;
const STATE_CORRECT_PRESENT = 2;
const STATE_REQUIRED_NOT_PRESENT = 3;
const STATE_RECOMMENDED_NOT_PRESENT = 3;
const STATE_INCORRECT_PRESENT = 4;

protected $files = null;
Expand All @@ -28,7 +28,6 @@ public function validate($lines)
"Other resource files" => $this->checkResources($lines),
"PHP source code" => $this->checkSrc($lines),
"Test code" => $this->checkTests($lines),
"Package managers" => $this->checkVendor($lines),
"Log of changes between releases" => $this->checkChangelog($lines),
"Guidelines for contributors" => $this->checkContributing($lines),
"Licensing information" => $this->checkLicense($lines),
Expand Down Expand Up @@ -81,7 +80,7 @@ protected function outputResultLine($label, $complianceState, $expected, $actual
self::STATE_OPTIONAL_NOT_PRESENT => "Optional {$expected} not present",
self::STATE_CORRECT_PRESENT => "Correct {$actual} present",
self::STATE_INCORRECT_PRESENT => "Incorrect {$actual} present",
self::STATE_REQUIRED_NOT_PRESENT => "Required {$expected} not present",
self::STATE_RECOMMENDED_NOT_PRESENT => "Recommended {$expected} not present",
];
echo $this->colorConsoleText("- " . $label . ": " . $messages[$complianceState], $complianceState) . PHP_EOL;
}
Expand All @@ -92,7 +91,7 @@ protected function colorConsoleText($text, $complianceState)
self::STATE_OPTIONAL_NOT_PRESENT => "\033[43;30m",
self::STATE_CORRECT_PRESENT => "\033[42;30m",
self::STATE_INCORRECT_PRESENT => "\033[41m",
self::STATE_REQUIRED_NOT_PRESENT => "\033[41m",
self::STATE_RECOMMENDED_NOT_PRESENT => "\033[41m",
];
if (!array_key_exists($complianceState, $colors)) {
return $text;
Expand All @@ -114,7 +113,7 @@ protected function checkDir($lines, $pass, array $fail)
return [self::STATE_OPTIONAL_NOT_PRESENT, $pass, null];
}

protected function checkFile($lines, $pass, array $fail)
protected function checkFile($lines, $pass, array $fail, $state = self::STATE_OPTIONAL_NOT_PRESENT)
{
foreach ($lines as $line) {
$line = trim($line);
Expand All @@ -127,18 +126,7 @@ protected function checkFile($lines, $pass, array $fail)
}
}
}
return [self::STATE_OPTIONAL_NOT_PRESENT, $pass, null];
}

protected function checkVendor($lines, $pass = 'vendor/')
{
foreach ($lines as $line) {
$line = trim($line);
if ($line == $pass) {
return [self::STATE_CORRECT_PRESENT, $pass, $line];
}
}
return [self::STATE_REQUIRED_NOT_PRESENT, $pass, null];
return [$state, $pass, null];
}

protected function checkChangelog($lines)
Expand Down Expand Up @@ -168,13 +156,18 @@ protected function checkContributing($lines)

protected function checkLicense($lines)
{
return $this->checkFile($lines, 'LICENSE', [
'/^.*EULA.*$/i',
'/^.*(GPL|BSD).*$/i',
'/^([A-Z-]+)?LI(N)?(S|C)(E|A)N(S|C)(E|A)(_[A-Z_]+)?(\.[a-z]+)?$/i',
'/^COPY(I)?NG(\.[a-z]+)?$/i',
'/^COPYRIGHT(\.[a-z]+)?$/i',
]);
return $this->checkFile(
$lines,
'LICENSE',
[
'/^.*EULA.*$/i',
'/^.*(GPL|BSD).*$/i',
'/^([A-Z-]+)?LI(N)?(S|C)(E|A)N(S|C)(E|A)(_[A-Z_]+)?(\.[a-z]+)?$/i',
'/^COPY(I)?NG(\.[a-z]+)?$/i',
'/^COPYRIGHT(\.[a-z]+)?$/i',
],
self::STATE_RECOMMENDED_NOT_PRESENT
);
}

protected function checkReadme($lines)
Expand Down
2 changes: 1 addition & 1 deletion src/PackageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function createFileList($validatorResults)
foreach ($validatorResults as $label => $complianceResult) {
if (in_array($complianceResult['state'], [
ComplianceValidator::STATE_OPTIONAL_NOT_PRESENT,
ComplianceValidator::STATE_REQUIRED_NOT_PRESENT,
ComplianceValidator::STATE_RECOMMENDED_NOT_PRESENT,
])) {
$files[$label] = $complianceResult['expected'];
}
Expand Down
32 changes: 9 additions & 23 deletions tests/ComplianceValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ public static function run()
{
$tester = new ComplianceValidatorTest();
$tester->testValidate_WithIncorrectBin_ReturnsIncorrectBin();
$tester->testValidate_WithoutVendor_ReturnsMissingVendor();
echo __CLASS__ . " errors: {$tester->numErrors}" . PHP_EOL;
}

public function testValidate_WithIncorrectBin_ReturnsIncorrectBin()
{
$paths = [
'cli/',
'vendor/',
'src/',
];

$validator = new ComplianceValidator();
Expand All @@ -31,38 +30,25 @@ public function testValidate_WithIncorrectBin_ReturnsIncorrectBin()
}
continue;
}
if ($expected == "vendor/") {
if ($expected == "src/") {
if ($result['state'] != ComplianceValidator::STATE_CORRECT_PRESENT) {
$this->numErrors++;
echo __FUNCTION__ . ": Expected state of {$result['expected']} to be STATE_CORRECT_PRESENT" . PHP_EOL;
}
continue;
}
if ($expected == "LICENSE") {
if ($result['state'] != ComplianceValidator::STATE_RECOMMENDED_NOT_PRESENT) {
$this->numErrors++;
echo __FUNCTION__ . ": Expected state of {$result['expected']} to be STATE_RECOMMENDED_NOT_PRESENT" . PHP_EOL;
}
continue;
}
if ($result['state'] != ComplianceValidator::STATE_OPTIONAL_NOT_PRESENT) {
$this->numErrors++;
echo __FUNCTION__ . ": Expected state of {$result['expected']} to be STATE_OPTIONAL_NOT_PRESENT" . PHP_EOL;
continue;
}
}
}

public function testValidate_WithoutVendor_ReturnsMissingVendor()
{
$paths = [
'bin/',
];

$validator = new ComplianceValidator();
$results = $validator->validate($paths);

foreach ($results as $expected => $result) {
if ($expected == "vendor/") {
if ($result['state'] != ComplianceValidator::STATE_REQUIRED_NOT_PRESENT) {
$this->numErrors++;
echo __FUNCTION__ . ": Expected state of {$result['expected']} to be STATE_REQUIRED_NOT_PRESENT" . PHP_EOL;
}
continue;
}
}
}
}

0 comments on commit 168881e

Please sign in to comment.