2017 © Pedro Peláez
 

library dic-doc

Magic type hinting for dependency injection container results

image

jmartin82/dic-doc

Magic type hinting for dependency injection container results

  • Saturday, April 16, 2016
  • by jmartin82
  • Repository
  • 2 Watchers
  • 6 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

DIC - DOC

Dependency Injection Container Documentator, (*1)

Build Status Coverage Status Scrutinizer Code Quality, (*2)

The problem

Since I've been using Dependency Injection Containers in my projects, the IDEs no longer understands what’s going on in some places in my code., (*3)

This problems affect the code hints, autocompletion and refactoring tools when dealing with classes. Then my IDE becomes useless., (*4)

The solution

You can define class of the variable returned by DIC 'manually':, (*5)

/** @var YourClassType $mailer */
$mailer = $container['mailer'];

Use two asterisks and write the data type before the name of the variable. You can write the data type without the name of the variable (but not the name without the data type)., (*6)

In the major part of the IDEs this comment solves your problems. But..., (*7)

The lazy solution

If you are a lazy person like me, you can use de DIC., (*8)

To document any variable from your code, you should enclose the variable with dd function, execute the code and black magic is going to happen (ok, not too magic, but it works)!, (*9)

Before:, (*10)

$mailer = dd($container['mailer']);

Start:, (*11)

/** @var YourClassType $mailer */
$mailer = $container['mailer'];

Installation / Usage

  1. Download and install Composer by following the official instructions.
  2. Create a composer.json defining the dependencies., (*12)

    json { "require-dev": { "jmartin82/DicDoc": "dev-master" } }, (*13)

  3. Run Composer: php composer.phar install, (*14)

Important

  • The code have to run to be replaced
  • Never use the dd function in production code
  • Always review the changes
  • Remember refresh the file if the IDE doesn't do it automatically.

The Versions

16/04 2016

dev-master

9999999-dev

Magic type hinting for dependency injection container results

  Sources   Download

MIT

The Development Requires

documentation dic ioc