From 945c646ab6e3413380b8a04c87493e442d4dcb61 Mon Sep 17 00:00:00 2001 From: Ivan Nikitin Date: Tue, 27 Mar 2018 18:32:37 +0300 Subject: [PATCH] ~ readme --- README.md | 41 +++++++++++++++++++++++++-- src/Metadata.php | 2 +- tests/fixtures/two/SomethingGreat.php | 26 +++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/two/SomethingGreat.php diff --git a/README.md b/README.md index b37f4fc..10e4bf2 100644 --- a/README.md +++ b/README.md @@ -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 +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 diff --git a/src/Metadata.php b/src/Metadata.php index 77b4b3f..1a07446 100644 --- a/src/Metadata.php +++ b/src/Metadata.php @@ -9,5 +9,5 @@ abstract class Metadata { const NAME = 'phpcdm'; - const VERSION = '1.0.0-rc7'; + const VERSION = '1.0.0-rc8'; } diff --git a/tests/fixtures/two/SomethingGreat.php b/tests/fixtures/two/SomethingGreat.php new file mode 100644 index 0000000..c5ec3b3 --- /dev/null +++ b/tests/fixtures/two/SomethingGreat.php @@ -0,0 +1,26 @@ +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); + } +} \ No newline at end of file