PHPStan level 3 #1603

Merged
nupplaPhil merged 15 commits from Art4/friendica-addons:phpstan-level-3 into develop 2025-04-27 02:17:42 +02:00
Contributor

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

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
Art4 stopped working 2025-02-25 16:29:54 +01:00
5 seconds
Art4 deleted spent time 2025-02-25 16:30:15 +01:00
- 5 seconds
Art4 changed title from WIP: PHPStan level 3 to PHPStan level 3 2025-03-13 12:58:57 +01:00
@ -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);
Owner

Please change \Friendica\Protocol\ATProtocol\Processor::fetchUriId to always return an integer. This is what the method is expected to do.

Please change `\Friendica\Protocol\ATProtocol\Processor::fetchUriId` to always return an integer. This is what the method is expected to do.
Author
Contributor
Done with https://github.com/friendica/friendica/pull/14830/commits/8ba652818f169a4391c193f9dde31c3c0dddb61e and removed the type casting with https://git.friendi.ca/friendica/friendica-addons/commit/db875bc755449ec71571a35cb62942b282cae0b9
Art4 marked this conversation as resolved
@ -369,3 +369,3 @@
if (filter_var($identifier, FILTER_VALIDATE_EMAIL)) {
$email = explode('@', $identifier);
return $email[1];
return (string) $email[1];
Owner

I'm surprised by this, explode() reportedly only returns strings in the output array. What case is this meant to address?

I'm surprised by this, `explode()` reportedly only returns strings in the output array. What case is this meant to address?
Author
Contributor

I was surprised too, but thought PHPStan complains because explode() could also return false. But now I removed the type cast and PHPStan don't show an error anymore. 🤷

I was surprised too, but thought PHPStan complains because `explode()` could also return `false`. But now I removed the type cast and PHPStan don't show an error anymore. 🤷
Art4 marked this conversation as resolved
@ -374,3 +374,3 @@
//OpenID
$url = parse_url($identifier);
$domain = $url['host'];
$domain = (string) $url['host'];
Owner

parse_url() only returns an integer for the port key, this is superfluous.

`parse_url()` only returns an integer for the `port` key, this is superfluous.
Author
Contributor

Same as above: #1603 (comment)

Same as above: https://git.friendi.ca/friendica/friendica-addons/pulls/1603#issuecomment-196305
Art4 marked this conversation as resolved
@ -51,3 +51,3 @@
$recipients = DBA::p("SELECT DISTINCT `email` FROM `user`" . DBA::buildCondition($condition), $condition);
if (! $recipients) {
if (! $recipients || !is_iterable($recipients)) {
Owner

Instead of checking for this, $recipients should be assigned the result of DBA::toArray(DBA:p(...)) in order for the later foreach() to be valid. Normally, the DBA::p output requires the use of DBA::fetch() in a loop.

Sure, the PDOStatement is iterable, but the mysqli-produced result resource probably isn't.

Instead of checking for this, `$recipients` should be assigned the result of `DBA::toArray(DBA:p(...))` in order for the later `foreach()` to be valid. Normally, the `DBA::p` output requires the use of `DBA::fetch()` in a loop. Sure, the `PDOStatement` is iterable, but the `mysqli`-produced result resource probably isn't.
Author
Contributor

Done, thank you.

Done, thank you.
Art4 marked this conversation as resolved
requested review from MrPetovan 2025-03-14 09:22:10 +01:00
nupplaPhil merged commit 95a9f7038a into develop 2025-04-27 02:17:42 +02:00
Art4 deleted branch phpstan-level-3 2025-04-28 15:22:52 +02:00
Sign in to join this conversation.
No description provided.