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 require --dev vantoozz/phpcdmまた、PHPCDMはこのようにグローバルにインストールされる場合があります。
composer global require --dev vantoozz/phpcdmsrcディレクトリの分析
./vendor/bin/phpcdm srcエラーコードで終了します
./vendor/bin/phpcdm src --non-zero-exit-on-violation