Skip to content

Commit 7bd62eb

Browse files
Merge pull request #65922 from nextcloud/bugfix/noid/ensure-since-version-is-from-branch
fix(since): Ensure provided since version is from the current branch
2 parents 406c29b + 92fbe47 commit 7bd62eb

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

‎build/psalm/OcpSinceChecker.php‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ private static function checkClassComment(ClassLike $stmt, FileSource $statement
140140
)
141141
);
142142
}
143+
foreach ($parsedDocblock->tags['since'] ?? [] as $since) {
144+
self::checkSinceIsReleasable(trim($since), $statementsSource, $stmt);
145+
}
143146

144147
if (isset($parsedDocblock->tags['depreacted'])) {
145148
IssueBuffer::maybeAdd(
@@ -184,6 +187,9 @@ private static function checkStatementComment(Stmt $stmt, FileSource $statements
184187
)
185188
);
186189
}
190+
foreach ($parsedDocblock->tags['since'] ?? [] as $since) {
191+
self::checkSinceIsReleasable(trim($since), $statementsSource, $stmt);
192+
}
187193

188194
if (isset($parsedDocblock->tags['depreacted'])) {
189195
IssueBuffer::maybeAdd(
@@ -213,9 +219,46 @@ private static function checkAttributeHasValidSinceVersion(\PhpParser\Node\Attri
213219
new CodeLocation($statementsSource, $stmt)
214220
)
215221
);
222+
} else {
223+
self::checkSinceIsReleasable($arg->value->value, $statementsSource, $stmt);
216224
}
217225
}
218226
}
219227
}
220228
}
229+
230+
/**
231+
* A since version must not be newer than the next patch release of the
232+
* current branch, so backports with an unadjusted since fail
233+
*/
234+
private static function checkSinceIsReleasable(string $since, FileSource $statementsSource, \PhpParser\Node $stmt): void {
235+
// Backports may list multiple versions: "33.0.1, 32.0.7"
236+
if (!preg_match('/^\d+(\.\d+)*(\s*,\s*\d+(\.\d+)*)*/', $since, $list)) {
237+
return;
238+
}
239+
240+
$maxVersion = self::getMaxSinceVersion();
241+
foreach (preg_split('/\s*,\s*/', $list[0]) as $version) {
242+
if (version_compare($version, $maxVersion, '<=')) {
243+
return;
244+
}
245+
}
246+
247+
IssueBuffer::maybeAdd(
248+
new InvalidDocblock(
249+
'Since version ' . $list[0] . ' is newer than the next release ' . $maxVersion . ' of this branch, please adjust it to the version the change is released in.',
250+
new CodeLocation($statementsSource, $stmt)
251+
)
252+
);
253+
}
254+
255+
private static function getMaxSinceVersion(): string {
256+
static $maxVersion = null;
257+
if ($maxVersion === null) {
258+
require __DIR__ . '/../../version.php';
259+
/** @var array{0: int, 1: int, 2: int, 3: int} $OC_Version */
260+
$maxVersion = $OC_Version[0] . '.' . $OC_Version[1] . '.' . ($OC_Version[2] + 1);
261+
}
262+
return $maxVersion;
263+
}
221264
}

0 commit comments

Comments
 (0)