Skip to content

Commit

Permalink
Declare more precise phpdoc types
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Apr 13, 2024
1 parent 46be456 commit 999135f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/PhpParser/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface Node {
/**
* Gets the type of the node.
*
* @psalm-return non-empty-string
* @return string Type of the node
*/
public function getType(): string;
Expand Down
12 changes: 10 additions & 2 deletions lib/PhpParser/Node/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
use PhpParser\NodeAbstract;

class Name extends NodeAbstract {
/** @var string Name as string */
/**
* @psalm-var non-empty-string
* @var non-empty-string Name as string
*/
public string $name;

/** @var array<string, bool> */
Expand Down Expand Up @@ -33,6 +36,7 @@ public function getSubNodeNames(): array {
/**
* Get parts of name (split by the namespace separator).
*
* @psalm-return non-empty-array<string>
* @return string[] Parts of name
*/
public function getParts(): array {
Expand Down Expand Up @@ -103,6 +107,7 @@ public function isRelative(): bool {
* Returns a string representation of the name itself, without taking the name type into
* account (e.g., not including a leading backslash for fully qualified names).
*
* @psalm-return non-empty-string
* @return string String representation
*/
public function toString(): string {
Expand All @@ -113,6 +118,7 @@ public function toString(): string {
* Returns a string representation of the name as it would occur in code (e.g., including
* leading backslash for fully qualified names.
*
* @psalm-return non-empty-string
* @return string String representation
*/
public function toCodeString(): string {
Expand All @@ -123,6 +129,7 @@ public function toCodeString(): string {
* Returns lowercased string representation of the name, without taking the name type into
* account (e.g., no leading backslash for fully qualified names).
*
* @psalm-return non-empty-string
* @return string Lowercased string representation
*/
public function toLowerString(): string {
Expand All @@ -142,6 +149,7 @@ public function isSpecialClassName(): bool {
* Returns a string representation of the name by imploding the namespace parts with the
* namespace separator.
*
* @psalm-return non-empty-string
* @return string String representation
*/
public function __toString(): string {
Expand Down Expand Up @@ -237,7 +245,7 @@ public static function concat($name1, $name2, array $attributes = []) {
*
* @param string|string[]|self $name Name to prepare
*
* @return string Prepared name
* @return non-empty-string Prepared name
*/
private static function prepareName($name): string {
if (\is_string($name)) {
Expand Down

0 comments on commit 999135f

Please sign in to comment.