phpcdm
1.0.0
phpcdm是PHP的代码密度仪表
查看此代码:
<?php
final class SomethingGreat
{
public function doSomethingGreat ( $ entity , $ property , $ type , $ refProperties , $ update , $ delete )
{
$ time = $ this -> startAction ( " $ type ( " . implode ( ' , ' , ( array ) $ type ) . ' ) ' );
$ this -> createAction ()-> addExtraKey ( $ entity , $ entity , $ property , $ refProperties , $ delete , $ update )-> execute ();
$ this -> finishAction ( $ time );
$ this -> createAction ()-> updateProperty ( $ entity , $ property , $ type )-> execute ();
if ( $ type instanceof InvalidArgumentException && $ type -> getMessage () !== null ) {
$ this -> createAction ()-> addDescriptionOnProperty ( $ entity , $ property , $ type -> description )-> execute ();
}
$ this -> createAction ()-> renameEntity ( $ entity , $ property )-> execute ();
$ this -> finishAction ( $ time );
$ time = $ this -> startAction ( " $ type ( " . implode ( ' , ' , ( array ) $ type ) . ' ) ' );
$ this -> createAction ()-> addExtraKey ( $ entity , $ entity , $ property , $ refProperties , $ delete , $ update )-> execute ();
if ( $ type instanceof InvalidArgumentException && $ type -> getMessage () !== $ delete ) {
$ this -> finishAction ( $ time );
$ this -> createAction ()-> addDescriptionOnProperty ( $ entity , $ property , $ type -> description )-> execute ();
$ this -> createAction ()-> renameEntity ( $ entity , $ property )-> execute ();
}
$ this -> createAction ()-> updateProperty ( $ entity , $ property , $ type )-> execute ();
$ this -> finishAction ( $ time );
}
}它看起来像是角色的墙。它实际上是字符的墙。没有人可以轻松地理解该代码的作者的含义,而且绝对没有人会很高兴尝试阅读它。此外,这种字符的墙通常是应用程序设计不良的结果。
代码密度是在单个页面上显示多少个字符的度量。
PHP代码密度计旨在帮助开发人员防止代码密度问题,并最终保持良好的应用。
示例代码的密度为0.381,远高于默认阈值(0.2)
您可以使用Composer将此工具添加为项目的本地,每项项目的开发时间依赖性:
composer require --dev vantoozz/phpcdm此外,PHPCDM可以像这样在全球安装:
composer global require --dev vantoozz/phpcdm分析src目录
./vendor/bin/phpcdm src使用错误代码退出
./vendor/bin/phpcdm src --non-zero-exit-on-violation