exakat.1.6.3 Review
exakat.1.6.3 Review

exakat.1.6.3 Review

这是2019年新年的exakat 1.6.3审查!新分析仪专注于array_key_exists()即将到来的速度增强,以及捕获preg_match()的捕获子模式。大使报告现在包括一个‘new issues’自上次审核以来,仅显示代码中最近发现的问题的部分。 exakat 1.6.1回来了!

分配和比较

分配和比较是两个本机PHP运算符,其使用(DOH)而且还因其优先级而异。并且它并不总是明显的,操作员首先是哪个,这是秒。

    
<?php

$a = $b == $c;

if ($a = $b == $c) {  
   doSomething();
}

?>

In the above example, the interesting expression is the same : literally the same. In the firs instance, it is easy to read that $a will contain the result of the comparison between $b and $c. While, in the second, it is easy to misread that $a will be assigned with $b, and their value will be compared to $c. Try your eyes on this second example :

    
<?php

while ($dir = readdir('.') !== false) {  
   // use $dir 
}
?>

因此,应在条件时间的分配,也称为IFFectations,应配备括号,以确保正确的执行顺序,或者简单地避免。

实施方法是公开的

当一个类x实现接口y时,那么实现的方法,a.k.a.实际上持有代码的方法,必须是公开的。随着手动所说的,在 “Object interfaces” : “界面中声明的所有方法都必须公开;这是界面的性质。”

然而,它也恰及实施课程唐’T注意这些细节,最终使用一个 protected or private visibility。当实现类和原始接口远离另一个界面时,这尤其如此。这导致了在执行时间下的PHP致命错误。

    
<?php

interface i {   
   function foo() ;
}

class x implements i {  
   private function foo() {} 
}

?>

这是一个经典的情况,其中php lint上面的代码,但在执行时停止以致命错误。除非发生一些牛仔编码,否则可能会被单位测试捕获这些错误。

exakat.1.6.3检测实施方法的可见性的错误配置。它改进了先前的分析,发现了太多方法。

对象引用省略全部分配的参数

Methods and functions may declare an argument as a reference, with the & operator before the argument name. This way, the value passed at call time is passed by reference : modifications on that value will also happen in the calling scope.

References are necessary for primary types, like strings or integers, as PHP would pass them by value, by default. Adding the & makes them more available.

另一方面, 对象不需要任何 &, as they are always passed by reference. So, any type hinted non-scalar argument is automatically a reference. As such, using & and an object is actually superfluous.

    
<?php

function foo($object, &$integer) {  
   $integer = 3;  
   $object->b = 4; 
}

$o = new stdClass();
$i = 5;

foo($o, $i);
// $i == 3;
// $o->b = 4;

?>

Yet, one situation occurs where the & is also necessary for objects : you see, when passing the object, the modifications in the object are reported to the calling scope, but the modification of the object as a whole are not. This requires a reference to the object, and not just the object itself.

    
<?php

function foo(&$object) {  
   $object = new Stclass();
}

foo($o);
// $o is now a stdClass object

?>

exakat.reports those situations, and has been refined to handle cleanly the situations where the argument is actually assigned with a new value. In other cases, the & is superfluous.

每周审计:2019,周#05

exakat包括A.‘weekly’报告:此报告采用五项分析为构建。这意味着短暂的审计报告,几乎没有问题审查。读取它们并不是很多,并在代码中查看它们。 PHP社区中的每个人都可以专注于一个经典的编码问题并解决它。谈谈周围的每周审计:你’LL找到面临同样挑战的程序员。

获得‘weekly’审核,运行审计,请求‘Weekly’ report.

# Init the project (skip when it is already done)    
php exakat.phar init -p <yourproject> -R //github.com/Seldaek/monolog.git -git 

# Run the project (skip when it is already done)    
php exakat.phar project -p <yourproject> 

# Export the weekly project (every monday)    
php exakat.phar report -p <yourproject> -format Weekly 

# Open projects/<yourproject>/weekly/index.html in your browser    

每周,您可以在此找到5个新分析,以便在您的代码中审查。事实上,当您的代码干净时,您也可以快速查看即将到来的

每周 recommendations for PHP code review : 2018, week 2019-04

快乐的PHP代码评论

所有352个分析仪都介绍在文档中,包括轻微: 未定义的变量:在任何创建之前使用的变量。这是一个非常频繁的错误(74%)

您可以查看图库中的所有exakat报告: exakat画廊.

下载exakat.io,安装它 Docker. ,升级它‘exakat.phar升级-u’ and like us on GitHub. .