Skip to content

Commit 168881e

Browse files
author
Paul M. Jones
committed
vendor no longer mentioned in standard; LICENSE now recommended
1 parent 1cf5a67 commit 168881e

File tree

3 files changed

+27
-48
lines changed

3 files changed

+27
-48
lines changed

src/ComplianceValidator.php

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ComplianceValidator
55
{
66
const STATE_OPTIONAL_NOT_PRESENT = 1;
77
const STATE_CORRECT_PRESENT = 2;
8-
const STATE_REQUIRED_NOT_PRESENT = 3;
8+
const STATE_RECOMMENDED_NOT_PRESENT = 3;
99
const STATE_INCORRECT_PRESENT = 4;
1010

1111
protected $files = null;
@@ -28,7 +28,6 @@ public function validate($lines)
2828
"Other resource files" => $this->checkResources($lines),
2929
"PHP source code" => $this->checkSrc($lines),
3030
"Test code" => $this->checkTests($lines),
31-
"Package managers" => $this->checkVendor($lines),
3231
"Log of changes between releases" => $this->checkChangelog($lines),
3332
"Guidelines for contributors" => $this->checkContributing($lines),
3433
"Licensing information" => $this->checkLicense($lines),
@@ -81,7 +80,7 @@ protected function outputResultLine($label, $complianceState, $expected, $actual
8180
self::STATE_OPTIONAL_NOT_PRESENT => "Optional {$expected} not present",
8281
self::STATE_CORRECT_PRESENT => "Correct {$actual} present",
8382
self::STATE_INCORRECT_PRESENT => "Incorrect {$actual} present",
84-
self::STATE_REQUIRED_NOT_PRESENT => "Required {$expected} not present",
83+
self::STATE_RECOMMENDED_NOT_PRESENT => "Recommended {$expected} not present",
8584
];
8685
echo $this->colorConsoleText("- " . $label . ": " . $messages[$complianceState], $complianceState) . PHP_EOL;
8786
}
@@ -92,7 +91,7 @@ protected function colorConsoleText($text, $complianceState)
9291
self::STATE_OPTIONAL_NOT_PRESENT => "\033[43;30m",
9392
self::STATE_CORRECT_PRESENT => "\033[42;30m",
9493
self::STATE_INCORRECT_PRESENT => "\033[41m",
95-
self::STATE_REQUIRED_NOT_PRESENT => "\033[41m",
94+
self::STATE_RECOMMENDED_NOT_PRESENT => "\033[41m",
9695
];
9796
if (!array_key_exists($complianceState, $colors)) {
9897
return $text;
@@ -114,7 +113,7 @@ protected function checkDir($lines, $pass, array $fail)
114113
return [self::STATE_OPTIONAL_NOT_PRESENT, $pass, null];
115114
}
116115

117-
protected function checkFile($lines, $pass, array $fail)
116+
protected function checkFile($lines, $pass, array $fail, $state = self::STATE_OPTIONAL_NOT_PRESENT)
118117
{
119118
foreach ($lines as $line) {
120119
$line = trim($line);
@@ -127,18 +126,7 @@ protected function checkFile($lines, $pass, array $fail)
127126
}
128127
}
129128
}
130-
return [self::STATE_OPTIONAL_NOT_PRESENT, $pass, null];
131-
}
132-
133-
protected function checkVendor($lines, $pass = 'vendor/')
134-
{
135-
foreach ($lines as $line) {
136-
$line = trim($line);
137-
if ($line == $pass) {
138-
return [self::STATE_CORRECT_PRESENT, $pass, $line];
139-
}
140-
}
141-
return [self::STATE_REQUIRED_NOT_PRESENT, $pass, null];
129+
return [$state, $pass, null];
142130
}
143131

144132
protected function checkChangelog($lines)
@@ -168,13 +156,18 @@ protected function checkContributing($lines)
168156

169157
protected function checkLicense($lines)
170158
{
171-
return $this->checkFile($lines, 'LICENSE', [
172-
'/^.*EULA.*$/i',
173-
'/^.*(GPL|BSD).*$/i',
174-
'/^([A-Z-]+)?LI(N)?(S|C)(E|A)N(S|C)(E|A)(_[A-Z_]+)?(\.[a-z]+)?$/i',
175-
'/^COPY(I)?NG(\.[a-z]+)?$/i',
176-
'/^COPYRIGHT(\.[a-z]+)?$/i',
177-
]);
159+
return $this->checkFile(
160+
$lines,
161+
'LICENSE',
162+
[
163+
'/^.*EULA.*$/i',
164+
'/^.*(GPL|BSD).*$/i',
165+
'/^([A-Z-]+)?LI(N)?(S|C)(E|A)N(S|C)(E|A)(_[A-Z_]+)?(\.[a-z]+)?$/i',
166+
'/^COPY(I)?NG(\.[a-z]+)?$/i',
167+
'/^COPYRIGHT(\.[a-z]+)?$/i',
168+
],
169+
self::STATE_RECOMMENDED_NOT_PRESENT
170+
);
178171
}
179172

180173
protected function checkReadme($lines)

src/PackageGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function createFileList($validatorResults)
4242
foreach ($validatorResults as $label => $complianceResult) {
4343
if (in_array($complianceResult['state'], [
4444
ComplianceValidator::STATE_OPTIONAL_NOT_PRESENT,
45-
ComplianceValidator::STATE_REQUIRED_NOT_PRESENT,
45+
ComplianceValidator::STATE_RECOMMENDED_NOT_PRESENT,
4646
])) {
4747
$files[$label] = $complianceResult['expected'];
4848
}

tests/ComplianceValidatorTest.php

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ public static function run()
99
{
1010
$tester = new ComplianceValidatorTest();
1111
$tester->testValidate_WithIncorrectBin_ReturnsIncorrectBin();
12-
$tester->testValidate_WithoutVendor_ReturnsMissingVendor();
1312
echo __CLASS__ . " errors: {$tester->numErrors}" . PHP_EOL;
1413
}
1514

1615
public function testValidate_WithIncorrectBin_ReturnsIncorrectBin()
1716
{
1817
$paths = [
1918
'cli/',
20-
'vendor/',
19+
'src/',
2120
];
2221

2322
$validator = new ComplianceValidator();
@@ -31,38 +30,25 @@ public function testValidate_WithIncorrectBin_ReturnsIncorrectBin()
3130
}
3231
continue;
3332
}
34-
if ($expected == "vendor/") {
33+
if ($expected == "src/") {
3534
if ($result['state'] != ComplianceValidator::STATE_CORRECT_PRESENT) {
3635
$this->numErrors++;
3736
echo __FUNCTION__ . ": Expected state of {$result['expected']} to be STATE_CORRECT_PRESENT" . PHP_EOL;
3837
}
3938
continue;
4039
}
40+
if ($expected == "LICENSE") {
41+
if ($result['state'] != ComplianceValidator::STATE_RECOMMENDED_NOT_PRESENT) {
42+
$this->numErrors++;
43+
echo __FUNCTION__ . ": Expected state of {$result['expected']} to be STATE_RECOMMENDED_NOT_PRESENT" . PHP_EOL;
44+
}
45+
continue;
46+
}
4147
if ($result['state'] != ComplianceValidator::STATE_OPTIONAL_NOT_PRESENT) {
4248
$this->numErrors++;
4349
echo __FUNCTION__ . ": Expected state of {$result['expected']} to be STATE_OPTIONAL_NOT_PRESENT" . PHP_EOL;
4450
continue;
4551
}
4652
}
4753
}
48-
49-
public function testValidate_WithoutVendor_ReturnsMissingVendor()
50-
{
51-
$paths = [
52-
'bin/',
53-
];
54-
55-
$validator = new ComplianceValidator();
56-
$results = $validator->validate($paths);
57-
58-
foreach ($results as $expected => $result) {
59-
if ($expected == "vendor/") {
60-
if ($result['state'] != ComplianceValidator::STATE_REQUIRED_NOT_PRESENT) {
61-
$this->numErrors++;
62-
echo __FUNCTION__ . ": Expected state of {$result['expected']} to be STATE_REQUIRED_NOT_PRESENT" . PHP_EOL;
63-
}
64-
continue;
65-
}
66-
}
67-
}
6854
}

0 commit comments

Comments
 (0)