2017 © Pedro Peláez
 

library phpcdm

PHP Code Density Meter (PHPCDM)

image

vantoozz/phpcdm

PHP Code Density Meter (PHPCDM)

  • Wednesday, March 28, 2018
  • by vantoozz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 32 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 68 % Grown

The README.md

PHP Code Density Meter (PHPCDM)

phpcdm is a Code Density Meter for PHP, (*1)

Build Status Codacy Badge Coverage Status Latest Stable Version License, (*2)

What is code density?

Look at this code:, (*3)

<?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);
    }
}

It looks like a wall of characters. It actually is a wall of characters. No one can easily understand what the author of this code meant and definitely, no one will be happy trying to read it. Moreover, often such walls of characters are the result of bad application design., (*4)

Code density is a measure of how many characters are displayed on a single page., (*5)

PHP Code Density Meter aims to help a developer to prevent code density issues and eventually keep an application in a good shape., (*6)

The example code has density of 0.381 which is far above the default threshold (0.2), (*7)

Installation

You can add this tool as a local, per-project, development-time dependency to your project using Composer:, (*8)

composer require --dev vantoozz/phpcdm

Also, PHPCDM may be installed globally like this:, (*9)

composer global require --dev vantoozz/phpcdm

Running

Analyzing the src directory, (*10)

 ./vendor/bin/phpcdm src

Exiting with an error code, (*11)

 ./vendor/bin/phpcdm src --non-zero-exit-on-violation

The Versions