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/phpcdm การวิเคราะห์ไดเรกทอรี src
./vendor/bin/phpcdm srcออกจากรหัสข้อผิดพลาด
./vendor/bin/phpcdm src --non-zero-exit-on-violation