phpcdm ist ein Codendichtemesser für PHP
Schauen Sie sich diesen Code an:
<?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 );
}
}Es sieht aus wie eine Wand von Charakteren. Es ist tatsächlich eine Wand von Charakteren. Niemand kann leicht verstehen, was der Autor dieses Codes bedeutete, und definitiv wird niemand glücklich sein, ihn zu lesen. Darüber hinaus sind solche Figurenmauern häufig das Ergebnis eines schlechten Anwendungsdesigns.
Die Codedichte ist ein Maß dafür, wie viele Zeichen auf einer einzelnen Seite angezeigt werden.
Der PHP -Code -Dichtemesser soll einem Entwickler helfen, Probleme mit der Codedichte zu verhindern und eine Anwendung in einer guten Form zu halten.
Der Beispielcode hat eine Dichte von 0,381, die weit über dem Standardschwellenwert liegt (0,2).
Sie können dieses Tool mit Composer als lokale, pro-project-, Entwicklungszeitabhängigkeit zu Ihrem Projekt hinzufügen:
composer require --dev vantoozz/phpcdmAußerdem kann PHPCDM weltweit wie folgt installiert werden:
composer global require --dev vantoozz/phpcdm Analyse des src -Verzeichnisses
./vendor/bin/phpcdm srcBeenden Sie mit einem Fehlercode
./vendor/bin/phpcdm src --non-zero-exit-on-violation