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 PhpStan suggestions #378

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Fix PhpStan suggestions #378

wants to merge 22 commits into from

Conversation

janbarasek
Copy link
Contributor

@janbarasek janbarasek commented Aug 10, 2019

  • bug fix
  • BC break? yes

Fixed PhpStan suggestions.

New errors:

------ ------------------------------------------------------------------------ 
 Line   Bridges/Nette/TracyExtension.php                                        
------ ------------------------------------------------------------------------ 
 103    Cannot access property $netteMailer on array|object.                    
 105    Cannot access property $fromEmail on array|object.                      
 110    Cannot access property $bar on array|object.                            
 112    Strict comparison using === between '' and '@' will always evaluate to  
        false.                                                                  
 130    Cannot access property $blueScreen on array|object.                     
------ ------------------------------------------------------------------------ 

------ ------------------------------------------------------------------- 
 Line   Tracy/Debugger/Debugger.php                                        
------ ------------------------------------------------------------------- 
 374    Access to an undefined property ErrorException::$context.          
 379    Access to an undefined property ErrorException::$context.          
 387    Access to an undefined property ErrorException::$context.          
 401    Access to an undefined property ErrorException::$context.          
 402    Access to an undefined property ErrorException::$skippable.        
 407    Access to an undefined property Tracy\IBarPanel::$data.            
 446    Negated boolean expression is always false.                        
 460    Negated boolean expression is always false.                        
 463    Access to an undefined property Tracy\DefaultBarPanel::$cpuUsage.  
 478    Negated boolean expression is always false.                        
 489    Negated boolean expression is always false.                        
------ ------------------------------------------------------------------- 

------ ------------------------------------------------------------------- 
 Line   Tracy/Dumper/Dumper.php                                            
------ ------------------------------------------------------------------- 
 505    Parameter #1 $character of function ord expects string, float|int  
        given.                                                             
------ ------------------------------------------------------------------- 

------ ---------------------------------------------------------- 
 Line   Tracy/Helpers.php                                         
------ ---------------------------------------------------------- 
 214    Access to an undefined property Throwable::$tracyAction.  
------ ---------------------------------------------------------- 

Old errors:

------ ------------------------------------------------------------------------- 
 Line   Bridges/Nette/Bridge.php                                                 
------ ------------------------------------------------------------------------- 
 36     Class Latte\CompileException not found.                                  
 39     Access to property $sourceName on an unknown class                       
        Latte\CompileException.                                                  
 42     Access to property $sourceName on an unknown class                       
        Latte\CompileException.                                                  
 43     Access to property $sourceLine on an unknown class                       
        Latte\CompileException.                                                  
 43     Access to property $sourceName on an unknown class                       
        Latte\CompileException.                                                  
 44     Access to property $sourceLine on an unknown class                       
        Latte\CompileException.                                                  
 44     Access to property $sourceLine on an unknown class                       
        Latte\CompileException.                                                  
 44     Access to property $sourceName on an unknown class                       
        Latte\CompileException.                                                  
 47     Access to property $sourceCode on an unknown class                       
        Latte\CompileException.                                                  
 47     Access to property $sourceLine on an unknown class                       
        Latte\CompileException.                                                  
 72     Class Latte\CompileException not found.                                  
 73     Access to property $sourceName on an unknown class                       
        Latte\CompileException.                                                  
 74     Call to method getMessage() on an unknown class Latte\CompileException.  
 75     Call to method getMessage() on an unknown class Latte\CompileException.  
 78     Access to property $sourceLine on an unknown class                       
        Latte\CompileException.                                                  
 78     Access to property $sourceName on an unknown class                       
        Latte\CompileException.                                                  
------ ------------------------------------------------------------------------- 

------ ------------------------------------------------------------------------- 
 Line   Bridges/Nette/MailSender.php                                             
------ ------------------------------------------------------------------------- 
 24     Property Tracy\Bridges\Nette\MailSender::$mailer has unknown class       
        Nette\Mail\IMailer as its type.                                          
 30     Parameter $mailer of method                                              
        Tracy\Bridges\Nette\MailSender::__construct() has invalid typehint type  
        Nette\Mail\IMailer.                                                      
 44     Instantiated class Nette\Mail\Message not found.                         
 45     Call to method setHeader() on an unknown class Nette\Mail\Message.       
 47     Call to method setFrom() on an unknown class Nette\Mail\Message.         
 50     Call to method addTo() on an unknown class Nette\Mail\Message.           
 52     Call to method setSubject() on an unknown class Nette\Mail\Message.      
 53     Call to method setBody() on an unknown class Nette\Mail\Message.         
 55     Call to method send() on an unknown class Nette\Mail\IMailer.            
------ ------------------------------------------------------------------------- 

------ ------------------------------------------------------ 
 Line   Bridges/Nette/TracyExtension.php                      
------ ------------------------------------------------------ 
 103    Cannot access property $netteMailer on array|object.  
 103    Class Nette\Mail\IMailer not found.                   
 105    Cannot access property $fromEmail on array|object.    
 110    Cannot access property $bar on array|object.          
 122    Class Nette\Http\Session not found.                   
 128    Cannot access property $blueScreen on array|object.   
------ ------------------------------------------------------ 

------ ------------------------------------------------------------------------ 
 Line   Tracy/Debugger/Debugger.php                                             
------ ------------------------------------------------------------------------ 
 31     Static property Tracy\Debugger::$productionMode (bool) does not accept  
        default value of type null.                                             
 374    Access to an undefined property ErrorException::$context.               
 379    Access to an undefined property ErrorException::$context.               
 387    Access to an undefined property ErrorException::$context.               
 401    Access to an undefined property ErrorException::$context.               
 402    Access to an undefined property ErrorException::$skippable.             
 407    Access to an undefined property Tracy\IBarPanel::$data.                 
 446    Negated boolean expression is always false.                             
 460    Negated boolean expression is always false.                             
 463    Access to an undefined property Tracy\DefaultBarPanel::$cpuUsage.       
 478    Negated boolean expression is always false.                             
 489    Negated boolean expression is always false.                             
------ ------------------------------------------------------------------------ 

------ ------------------------------------------------------------------- 
 Line   Tracy/Dumper/Dumper.php                                            
------ ------------------------------------------------------------------- 
 185    Variable $options might not be defined.                            
 189    Variable $options might not be defined.                            
 192    Variable $options might not be defined.                            
 504    Parameter #1 $character of function ord expects string, float|int  
        given.                                                             
 545    PHPDoc tag @param references unknown parameter: $k                 
------ ------------------------------------------------------------------- 

------ ---------------------------------------------------------- 
 Line   Tracy/Helpers.php                                         
------ ---------------------------------------------------------- 
 215    Access to an undefined property Throwable::$tracyAction.  
 216    Variable $replace might not be defined.                   
 216    Variable $replace might not be defined.                   
 253    Variable $i might not be defined.                         
 254    Variable $i might not be defined.                         
 255    Variable $i might not be defined.                         
 255    Variable $i might not be defined.                         
------ ---------------------------------------------------------- 

------ ---------------------------------- 
 Line   Tracy/Logger/Logger.php           
------ ---------------------------------- 
 166    Right side of && is always true.  
------ ---------------------------------- 

src/Bridges/Nette/Bridge.php Outdated Show resolved Hide resolved
src/Bridges/Nette/Bridge.php Outdated Show resolved Hide resolved
src/Bridges/Nette/MailSender.php Outdated Show resolved Hide resolved
src/Tracy/Dumper/Dumper.php Outdated Show resolved Hide resolved
@@ -163,7 +163,6 @@ protected function sendEmail($message): void

if (
$this->email
&& $this->mailer
Copy link
Contributor

Choose a reason for hiding this comment

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

this is wrong fix, instead the type of the $mailer property should be changed to callable|null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, now I understand. In original implementation property $mailer was setted by __construct in all cases. But property is public and can be changed.

I reverted condition here and change property definition:

/** @var callable|null handler for sending emails */
public $mailer;

$item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]);
} elseif (is_string($item)) {
$item = new Nette\DI\Statement($item);
if (is_string($item)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because in original implementation when you verify variable $item is string, second elseif condition does not make sense.

src/Bridges/Nette/TracyExtension.php Outdated Show resolved Hide resolved
src/Tracy/Helpers.php Outdated Show resolved Hide resolved
@@ -517,7 +518,7 @@ public static function encodeString(string $s, int $maxLength = null): string
$i = $len = 0;
$maxI = $maxLength * 4; // max UTF-8 length
do {
if (($s[$i] < "\x80" || $s[$i] >= "\xC0") && (++$len > $maxLength) || $i >= $maxI) {
if (($s[$i] < "\x80" || $s[$i] >= "\xC0") && ((++$len > $maxLength) || $i >= $maxI)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Operations priority might differ from what programmer expect. Brackets are safe.

Copy link
Contributor

Choose a reason for hiding this comment

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

if it's not related the phpstan error it should not be part of this PR

src/Bridges/Nette/Bridge.php Outdated Show resolved Hide resolved
Copy link
Contributor

@JanTvrdik JanTvrdik left a comment

Choose a reason for hiding this comment

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

you should not mix code changes related to phpstan errors with code style changes in one PR

@dg dg force-pushed the master branch 2 times, most recently from dbabb37 to eb2e772 Compare September 24, 2019 11:11
@dg dg force-pushed the master branch 6 times, most recently from de3ad52 to 191c0d2 Compare December 15, 2019 22:49
@dg dg force-pushed the master branch 2 times, most recently from 2b958bb to f36b649 Compare January 2, 2020 19:40
@dg dg force-pushed the master branch 2 times, most recently from 68b0ec8 to 344c772 Compare February 23, 2020 18:40
@dg dg force-pushed the master branch 10 times, most recently from c3c8bf0 to 6f7e1c3 Compare January 22, 2021 23:21
@dg dg force-pushed the master branch 2 times, most recently from 84dee11 to bd73e33 Compare March 4, 2021 20:09
@dg dg force-pushed the master branch 8 times, most recently from 7799297 to a386d38 Compare April 29, 2021 11:09
@dg dg force-pushed the master branch 2 times, most recently from f3f04e0 to 0a90e93 Compare May 10, 2021 11:10
@dg dg force-pushed the master branch 6 times, most recently from 5ee33d7 to 8e708de Compare August 24, 2021 16:26
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.

4 participants