Skip to content

Commit

Permalink
~ readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vantoozz committed Mar 27, 2018
1 parent ff363cb commit 945c646
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,50 @@


[![Build Status](https://travis-ci.org/vantoozz/phpcdm.svg?branch=master)](https://travis-ci.org/vantoozz/phpcdm)
[![Coverage Status](https://coveralls.io/repos/github/vantoozz/phpcdm/badge.svg?branch=master)](https://coveralls.io/github/vantoozz/phpcdm?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/4b3e0816e98d486e9f0eff445a6310c6)](https://www.codacy.com/app/vantoozz/phpcdm?utm_source=github.com&utm_medium=referral&utm_content=vantoozz/phpcdm&utm_campaign=Badge_Grade)
[![Packagist](https://img.shields.io/packagist/v/vantoozz/phpcdm.svg)](https://packagist.org/packages/vantoozz/phpcdm)
[![License](https://poser.pugx.org/vantoozz/phpcdm/license)](https://packagist.org/packages/vantoozz/phpcdm)

## What is code density?
Code density is a measure of readability.

Look at this code:
```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);
}
}
```

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.

_Code density_ is a measure of how many characters are displayed on a single page.

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

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


## Installation

Expand Down
2 changes: 1 addition & 1 deletion src/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
abstract class Metadata
{
const NAME = 'phpcdm';
const VERSION = '1.0.0-rc7';
const VERSION = '1.0.0-rc8';
}
26 changes: 26 additions & 0 deletions tests/fixtures/two/SomethingGreat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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);
}
}

0 comments on commit 945c646

Please sign in to comment.