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