-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46827 from nextcloud/build/psalm/named-attribute-…
…args build(psalm): Enforce named attribute arguments
- Loading branch information
Showing
9 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
use PhpParser\Node\Attribute; | ||
use Psalm\CodeLocation; | ||
use Psalm\FileSource; | ||
use Psalm\Issue\InvalidDocblock; | ||
use Psalm\IssueBuffer; | ||
use Psalm\Plugin\EventHandler\Event\AfterClassLikeVisitEvent; | ||
|
||
class AttributeNamedParameters implements Psalm\Plugin\EventHandler\AfterClassLikeVisitInterface { | ||
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void { | ||
$stmt = $event->getStmt(); | ||
$statementsSource = $event->getStatementsSource(); | ||
|
||
foreach ($stmt->attrGroups as $attrGroup) { | ||
foreach ($attrGroup->attrs as $attr) { | ||
self::checkAttribute($attr, $statementsSource); | ||
} | ||
} | ||
|
||
foreach ($stmt->getMethods() as $method) { | ||
foreach ($method->attrGroups as $attrGroup) { | ||
foreach ($attrGroup->attrs as $attr) { | ||
self::checkAttribute($attr, $statementsSource); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private static function checkAttribute(Attribute $stmt, FileSource $statementsSource): void { | ||
if ($stmt->name->getLast() === 'Attribute') { | ||
return; | ||
} | ||
|
||
foreach ($stmt->args as $arg) { | ||
if ($arg->name === null) { | ||
IssueBuffer::maybeAdd( | ||
new InvalidDocblock( | ||
'Attribute arguments must be named.', | ||
new CodeLocation($statementsSource, $stmt) | ||
) | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters