PHPStan level 3 #1603
No reviewers
Labels
No labels
2018.09
2019.01
2019.03
2019.06
2019.09
2019.12
2020.03
2020.06
2020.09
2020.12
2021.03
2021.07
2021.09
2022.02
2022.06
2022.09
2022.12
2023.04
2023.05
2023.09
2024.03
2024.06
2024.09
2024.12
2025.02
2025.05
dependencies
Hackathon 2021
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: friendica/friendica-addons#1603
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Art4/friendica-addons:phpstan-level-3"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR fixes all 22 errors that are reported by PHPStan level 3.
This PR targets the 2025.05 release.
Refs https://github.com/friendica/friendica/pull/14830
WIP: PHPStan level 3to PHPStan level 3@ -962,3 +962,3 @@
$comments = Post::countPosts(['thr-parent' => $existing_uri, 'gravity' => Item::GRAVITY_COMMENT]);
if (($post->replyCount <= $comments) || !$complete) {
return DI::atpProcessor()->fetchUriId($existing_uri, $uid);
return (int) DI::atpProcessor()->fetchUriId($existing_uri, $uid);
Please change
\Friendica\Protocol\ATProtocol\Processor::fetchUriId
to always return an integer. This is what the method is expected to do.Done with https://github.com/friendica/friendica/pull/14830/commits/8ba652818f169a4391c193f9dde31c3c0dddb61e and removed the type casting with
db875bc755
@ -369,3 +369,3 @@
if (filter_var($identifier, FILTER_VALIDATE_EMAIL)) {
$email = explode('@', $identifier);
return $email[1];
return (string) $email[1];
I'm surprised by this,
explode()
reportedly only returns strings in the output array. What case is this meant to address?I was surprised too, but thought PHPStan complains because
explode()
could also returnfalse
. But now I removed the type cast and PHPStan don't show an error anymore. 🤷@ -374,3 +374,3 @@
//OpenID
$url = parse_url($identifier);
$domain = $url['host'];
$domain = (string) $url['host'];
parse_url()
only returns an integer for theport
key, this is superfluous.Same as above: #1603 (comment)
@ -51,3 +51,3 @@
$recipients = DBA::p("SELECT DISTINCT `email` FROM `user`" . DBA::buildCondition($condition), $condition);
if (! $recipients) {
if (! $recipients || !is_iterable($recipients)) {
Instead of checking for this,
$recipients
should be assigned the result ofDBA::toArray(DBA:p(...))
in order for the laterforeach()
to be valid. Normally, theDBA::p
output requires the use ofDBA::fetch()
in a loop.Sure, the
PDOStatement
is iterable, but themysqli
-produced result resource probably isn't.Done, thank you.