Skip to content

[TASK] Do not treat PHPDoc type information as certain#1583

Merged
JakeQZ merged 1 commit into
mainfrom
task/no-certain-phpdoc
May 13, 2026
Merged

[TASK] Do not treat PHPDoc type information as certain#1583
JakeQZ merged 1 commit into
mainfrom
task/no-certain-phpdoc

Conversation

@oliverklee
Copy link
Copy Markdown
Collaborator

This is a library. This means that we have no control over how other software calls our methods, and whether they adher to the types required via @param annotations.

Hence, we shouldn't rely on those types being certain.

This is a library. This means that we have no control over how
other software calls our methods, and whether they adher to
the types required via `@param` annotations.

Hence, we shouldn't rely on those types being certain.
@oliverklee oliverklee requested a review from JakeQZ May 13, 2026 08:05
@oliverklee oliverklee self-assigned this May 13, 2026
@oliverklee oliverklee added the developer-specific Issues that only affect maintainers, contributors, and people submitting PRs label May 13, 2026
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 73.324%. remained the same — task/no-certain-phpdoc into main

@JakeQZ JakeQZ merged commit bdb95ea into main May 13, 2026
24 checks passed
@JakeQZ JakeQZ deleted the task/no-certain-phpdoc branch May 13, 2026 15:26
Comment on lines -51 to -56
-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertSame\(\) with ''red'' and Sabberworm\\CSS\\Value\\Value will always evaluate to false\.$#'
identifier: staticMethod.impossibleType
count: 1
path: ../../tests/ParserTest.php

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That this warning existed indicates something is returning a string but has DocBlock type indicating a different return type.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1584 resolves this concern. Turns out the test code had a loop with no iterations, within which was the assertSame() which would always fail, but was never called.

oliverklee added a commit that referenced this pull request May 13, 2026
This is a library. This means that we have no control over how
other software calls our methods, and whether they adher to
the types required via `@param` annotations.

Hence, we shouldn't rely on those types being certain.
JakeQZ added a commit that referenced this pull request May 13, 2026
`getAllValues()` only includes values that are `Value` objects.
It does not include `string` values.  So the list returned was empty,
the loop had no iterations, and the `assertSame()` was never called.

It doesn't make sense to replace the code with an assertion that
`getAllValues()` is returning an empty list, because the `TestCase` is for
`Parser`, not `Document`.  Besides, there is already an assertion that `red`
is set for the string `color` value.

Uncovered by PHPStan config change in #1583.
This change would also have silenced the same PHPStan warning.
oliverklee pushed a commit that referenced this pull request May 14, 2026
`getAllValues()` only includes values that are `Value` objects.
It does not include `string` values.  So the list returned was empty,
the loop had no iterations, and the `assertSame()` was never called.

It doesn't make sense to replace the code with an assertion that
`getAllValues()` is returning an empty list, because the `TestCase` is for
`Parser`, not `Document`.  Besides, there is already an assertion that `red`
is set for the string `color` value.

Uncovered by PHPStan config change in #1583.
This change would also have silenced the same PHPStan warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

developer-specific Issues that only affect maintainers, contributors, and people submitting PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants