Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8.2 warnings, add PHPStan, refactor type hinting, and fix notification link and content #48

Merged
merged 5 commits into from
May 13, 2023

Conversation

rafaucau
Copy link
Contributor

@rafaucau rafaucau commented May 13, 2023

  • Fixed PHP 8.2 warnings by properly handling null parameters.
  • Updated minishlink/web-push to the latest version. PHP 8.0 is now minimum supported version.
  • Added PHPStan to the project, which will help us find issues more efficiently.
  • Refactored the code to use native PHP variable types to make it easier to catch issues.
  • Fixed the discussion link and content.

Specifically, I found that the following conditional block was causing problems:

if (in_array($blueprint->getType(), ['newPost', 'byobuPrivateDiscussionReplied'])) {
    $subject = $blueprint->post;
    $subjectModel = CommentPost::class;
}

This block was modifying the $subject and $subjectModel variables unnecessarily. The correct implementation was already present before this block:

$subject = $blueprint->getSubject();
$subjectModel = $blueprint->getSubjectModel();

So, I've removed the problematic conditional block entirely, which resolved the issue.
I have tested the push notifications with new posts and with fof/byobu. Everything is working as expected, with no errors or issues found.

@rafaucau
Copy link
Contributor Author

Some PHPStan issues to fix:

 ------ ------------------------------------------------------------------------------------------- 
  Line   src/Api/Controller/AddPushSubscriptionController.php                                       
 ------ ------------------------------------------------------------------------------------------- 
  69     Call to an undefined method Flarum\User\User::pushSubscriptions().                         
  91     Access to an undefined property Askvortsov\FlarumPWA\PushSubscription::$user_id.           
  92     Access to an undefined property Askvortsov\FlarumPWA\PushSubscription::$endpoint.          
  93     Access to an undefined property Askvortsov\FlarumPWA\PushSubscription::$expires_at.        
  94     Access to an undefined property Askvortsov\FlarumPWA\PushSubscription::$vapid_public_key.  
  95     Access to an undefined property Askvortsov\FlarumPWA\PushSubscription::$keys.              
 ------ ------------------------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------- 
  Line   src/Api/Controller/ResetVAPIDKeysController.php                  
 ------ ----------------------------------------------------------------- 
  47     Dead catch - RuntimeException is never thrown in the try block.  
 ------ ----------------------------------------------------------------- 

 ------ -----------------------------------------------------------
  Line   src/Api/Serializer/PushSubscriptionSerializer.php
 ------ -----------------------------------------------------------
  31     Cannot access property $endpoint on array|object.
  32     Cannot access property $vapid_public_key on array|object.
  33     Cannot access property $expires_at on array|object.
 ------ -----------------------------------------------------------

 ------ ------------------------------------------------------------------------------------
  Line   src/PushSender.php
 ------ ------------------------------------------------------------------------------------
  144    Access to an undefined property Askvortsov\FlarumPWA\PushSubscription::$last_used.
  163    Access to an undefined property Flarum\Database\AbstractModel::$display_name.
  170    Access to an undefined property Flarum\Database\AbstractModel::$type.
  170    Call to an undefined method Flarum\Database\AbstractModel::formatContent().
  172    Access to an undefined property Flarum\Database\AbstractModel::$discussion_id.
  172    Access to an undefined property Flarum\Database\AbstractModel::$number.
  183    Call to an undefined method Illuminate\Contracts\Filesystem\Filesystem::url().
  188    If condition is always true.
  191    Call to an undefined method Illuminate\Contracts\Filesystem\Filesystem::url().
 ------ ------------------------------------------------------------------------------------

@askvortsov1
Copy link
Owner

Specifically, I found that the following conditional block was causing problems:

Yeah, this made some sense before my most recent refactor, but now it's just a bug. Thanks for this and all the fixes/changes!

I'm actually going to do this as 2 releases: one to clean up bugs and upgrading to web push v7, and another dropping PHP 7 support.

@askvortsov1 askvortsov1 merged commit 5bc54c1 into askvortsov1:master May 13, 2023
@rafaucau rafaucau deleted the fix-ext branch May 13, 2023 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants