Codeinwp / neve

A fast, lightweight, AMP ready WordPress theme built with speed and usability in mind.
https://themeisle.com/themes/neve/
GNU General Public License v2.0
262 stars 84 forks source link

Update PHPStan and fix the reported issues #3820

Closed cristian-ungureanu closed 1 year ago

cristian-ungureanu commented 1 year ago

Update the composer dependency szepeviktor/phpstan-wordpress to v1.1.7, and fix the reported issues:

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   header-footer-grid/Core/Builder/Abstract_Builder.php                                                                                                                                          
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  649    Property HFG\Core\Builder\Abstract_Builder::$title (string) in isset() is not nullable.                                                                                                       
  653    Property HFG\Core\Builder\Abstract_Builder::$description (string) in isset() is not nullable.                                                                                                 
  1596   Offset 'components' on array{classes: non-empty-array<int, non-falsy-string>, components: non-empty-array<int, mixed>, vertical-align?: mixed} in isset() always exists and is not nullable.  
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------- 
  Line   header-footer-grid/Core/Components/Abstract_Component.php                                           
 ------ ---------------------------------------------------------------------------------------------------- 
  587    Property HFG\Core\Components\Abstract_Component::$description (string) in isset() is not nullable.  
 ------ ---------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------- 
  Line   header-footer-grid/Core/Magic_Tags.php                             
 ------ ------------------------------------------------------------------- 
  440    Variable $current_user in empty() always exists and is not falsy.  
  453    Variable $current_user in empty() always exists and is not falsy.  
  466    Variable $current_user in empty() always exists and is not falsy.  
 ------ ------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------- 
  Line   header-footer-grid/Core/Settings/Manager.php                                   
 ------ ------------------------------------------------------------------------------- 
  397    Offset 'live_refresh…' on array in isset() always exists and is not nullable.  
 ------ ------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------- 
  Line   header-footer-grid/Main.php                                                       
 ------ ---------------------------------------------------------------------------------- 
  53     Property HFG\Main::$settings is never read, only written.                         
         💡 See: https://phpstan.org/developing-extensions/always-read-written-properties   
  80     Property HFG\Main::$css_generator is never read, only written.                    
         💡 See: https://phpstan.org/developing-extensions/always-read-written-properties   
  280    Method HFG\Main::should_enqueue_assets() is unused.                               
 ------ ---------------------------------------------------------------------------------- 

 ------ ----------------------------------------------------------- 
  Line   header-footer-grid/functions-migration.php                 
 ------ ----------------------------------------------------------- 
  471    Callback expects 1 parameter, $accepted_args is set to 4.  
 ------ ----------------------------------------------------------- 

 ------ ------------------------------------------- 
  Line   header-footer-grid/functions-template.php  
 ------ ------------------------------------------- 
  95     Expression in empty() is not falsy.        
 ------ ------------------------------------------- 

 ------ ----------------------------------------------------------------------- 
  Line   header-footer-grid/loader.php                                          
 ------ ----------------------------------------------------------------------- 
  57     Action callback returns HFG\Main|null but should not return anything.  
 ------ ----------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------ 
  Line   inc/admin/dashboard/plugin_helper.php                             
 ------ ------------------------------------------------------------------ 
  135    Result of && is always true.                                      
  135    Variable $plugin_data in empty() always exists and is not falsy.  
  138    Unreachable statement - code above always terminates.             
 ------ ------------------------------------------------------------------ 

 ------ -------------------------------------------------------------- 
  Line   inc/admin/metabox/manager.php                                 
 ------ -------------------------------------------------------------- 
  48     Action callback returns bool but should not return anything.  
 ------ -------------------------------------------------------------- 

 ------ ----------------------------------------------------------------------------------------------------- 
  Line   inc/compatibility/elementor.php                                                                      
 ------ ----------------------------------------------------------------------------------------------------- 
  68     Action callback returns string but should not return anything.                                       
  101    @param array $css does not accept actual type of parameter: non-falsy-string.                        
  102    Parameter #1 $css of static method Neve\Core\Dynamic_Css::minify_css() expects string, array given.  
  431    Variable $condition_parts in empty() always exists and is not falsy.                                 
 ------ ----------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------- 
  Line   inc/compatibility/starter_content.php                        
 ------ ------------------------------------------------------------- 
  33     Callback expects 3 parameters, $accepted_args is set to 99.  
 ------ ------------------------------------------------------------- 

 ------ --------------------------------------------------------------- 
  Line   inc/compatibility/woocommerce.php                              
 ------ --------------------------------------------------------------- 
  110    Action callback returns array but should not return anything.  
  283    Action callback returns bool but should not return anything.   
  284    Action callback returns bool but should not return anything.   
 ------ --------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   inc/core/admin.php                                                                                                                                                 
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  34     Property Neve\Core\Admin::$theme_name is unused.                                                                                                                   
         💡 See: https://phpstan.org/developing-extensions/always-read-written-properties                                                                                    
  98     Offset 'version' on array{nonce: string, slug: 'templates-patterns…', cta: string, path: string, activate: string, deactivate: string} in empty() does not exist.  
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------- 
  Line   inc/core/core_loader.php                                      
 ------ -------------------------------------------------------------- 
  35     Action callback returns bool but should not return anything.  
  69     Variable $now in empty() always exists and is not falsy.      
 ------ -------------------------------------------------------------- 

 ------ --------------------------------------------- 
  Line   inc/core/styles/css_prop.php                 
 ------ --------------------------------------------- 
  146    No error to ignore is reported on line 146.  
 ------ --------------------------------------------- 

 ------ ---------------------------------- 
  Line   inc/core/styles/frontend.php      
 ------ ---------------------------------- 
  981    Right side of && is always true.  
 ------ ---------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  Line   inc/customizer/controls/react/typography.php                                                                                                                                              
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  27     PHPDoc type mixed of property Neve\Customizer\Controls\React\Typography::$input_attrs is not covariant with PHPDoc type array of overridden property WP_Customize_Control::$input_attrs.  
         💡 You can fix 3rd party PHPDoc types with stub files:                                                                                                                                     
            https://phpstan.org/user-guide/stub-files                                                                                                                                              
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 

 ------ ------------------------------------------------------------------------------------------ 
  Line   inc/customizer/defaults/single_post.php (in context of class Neve\Admin\Metabox\Manager)  
 ------ ------------------------------------------------------------------------------------------ 
  127    Expected 3 @param tags, found 1.                                                          
 ------ ------------------------------------------------------------------------------------------ 

 ------ ----------------------------------------------------------------------------------------- 
  Line   inc/customizer/defaults/single_post.php (in context of class Neve\Core\Styles\Frontend)  
 ------ ----------------------------------------------------------------------------------------- 
  127    Expected 3 @param tags, found 1.                                                         
 ------ ----------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------------- 
  Line   inc/customizer/defaults/single_post.php (in context of class Neve\Customizer\Options\Base_Layout_Single)  
 ------ ---------------------------------------------------------------------------------------------------------- 
  127    Expected 3 @param tags, found 1.                                                                          
 ------ ---------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------- 
  Line   inc/customizer/defaults/single_post.php (in context of class Neve\Views\Cover_Header)  
 ------ --------------------------------------------------------------------------------------- 
  127    Expected 3 @param tags, found 1.                                                       
 ------ --------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------- 
  Line   inc/customizer/defaults/single_post.php (in context of class Neve\Views\Post_Layout)  
 ------ -------------------------------------------------------------------------------------- 
  127    Expected 3 @param tags, found 1.                                                      
 ------ -------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------- 
  Line   inc/views/breadcrumbs.php                                     
 ------ -------------------------------------------------------------- 
  25     Action callback returns bool but should not return anything.  
 ------ -------------------------------------------------------------- 

 ------ -------------------------------------------------------------------- 
  Line   inc/views/nav_walker.php                                            
 ------ -------------------------------------------------------------------- 
  119    Access to an undefined property WP_Post::$url.                      
  126    Parameter #1 $text of function esc_attr expects string, int given.  
  270    Access to an undefined property WP_Post::$url.                      
  282    Access to an undefined property WP_Post::$title.                    
 ------ -------------------------------------------------------------------- 

 ------ ------------------------------------------------------- 
  Line   inc/views/pluggable/pagination.php                     
 ------ ------------------------------------------------------- 
  99     While loop condition is always true.                   
  118    Unreachable statement - code above always terminates.  
 ------ ------------------------------------------------------- 

 ------ -------------------------------------------------------------- 
  Line   inc/views/product_layout.php                                  
 ------ -------------------------------------------------------------- 
  31     Action callback returns bool but should not return anything.  
  152    Callback expects 1 parameter, $accepted_args is set to 2.     
  153    While loop condition is always true.                          
  158    Unreachable statement - code above always terminates.         
 ------ -------------------------------------------------------------- 

 -- ----------------------------------------------------------------------------------------------------------------------- 
     Error                                                                                                                  
 -- ----------------------------------------------------------------------------------------------------------------------- 
     Ignored error pattern #Parameter \#2 \$default of function get_theme_mod expects# was not matched in reported errors.  
 -- ----------------------------------------------------------------------------------------------------------------------- 

 [ERROR] Found 50 errors                                                                                                
preda-bogdan commented 1 year ago

@cristian-ungureanu do we intend to raise the PHP minimum version since the package you mentioned requires PHP 7.2. Also, where did you try to upgrade to this specific version?

cristian-ungureanu commented 1 year ago

@preda-bogdan this task started from here https://github.com/Codeinwp/neve/pull/3812#issuecomment-1424254887. I think we will need to raise the PHP minimum version for https://github.com/Codeinwp/neve/issues/3805 anyways.

I tried to do that on a local environment.

preda-bogdan commented 1 year ago

This issue was only referencing the errors reported on Neve, but I believe the same changes needed to be added to the Neve Pro, so I also created a PR for that, my original assessment was wrong as I only accounted for the Neve changes.

mskapusuz commented 1 year ago

@cristian-ungureanu do we intend to raise the PHP minimum version since the package you mentioned requires PHP 7.2. Also, where did you try to upgrade to this specific version?

In https://github.com/Codeinwp/neve/pull/3858 PR, I've handled that. From now on, we'll have two different composer configs (one for production (has min php 7.0 req like our wp min php req.) also one for the dev env, developers (which has min php 7.2 req )) Therefore, I think once the https://github.com/Codeinwp/neve/pull/3858 merged, we'll be free to increase phpstan version. So, I'd like to postpone my PR review until that's clear. What do you think @preda-bogdan ?

Thanks!

preda-bogdan commented 1 year ago

@mskapusuz I merged the changes you made for the composer inside the PR. Will we have the same for Neve Pro or is it not required?

mskapusuz commented 1 year ago

@mskapusuz I merged the changes you made for the composer inside the PR. Will we have the same for Neve Pro or is it not required?

hey @preda-bogdan you're right. I didn't cover it; let me I'll ask to the Marius.

@selul do you think should we have the same approach in Neve Pro to having separate composer files for dev, and prod?

selul commented 1 year ago

@mskapusuz yes, if required.

mskapusuz commented 1 year ago

@mskapusuz yes, if required.

@preda-bogdan in that case, I can handle it until tomorrow and let you know @preda-bogdan is it ok for you?

preda-bogdan commented 1 year ago

@mskapusuz ok, just let me know and I will merge the changes there. Thank you!

mskapusuz commented 1 year ago

Hey @preda-bogdan the https://github.com/Codeinwp/neve-pro-addon/pull/2389 is ready; I've asked for a review from you for it. We can merge it into development after your review. Then you can pull changes from development into https://github.com/Codeinwp/neve-pro-addon/pull/2374 Thanks!

cc: @cristian-ungureanu

pirate-bot commented 1 year ago

:tada: This issue has been resolved in version 3.5.6 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: