PHP UML (PEAR package)

Keywords

The PHP UML package offers some limited reverse engineering capabilities:

PHP_UML is a PHP parser, an XMI generator and a documentation tool.
Practically, with PHP_UML, you will be able to feed a UML CASE tool, like Rational Rose or Argouml, with a UML representation of existing PHP source code. This way, you get an instant overview of a PHP application, with all the usual functions of a software design tool (such as class diagrams exportation, refactoring of object-oriented applications, or automatic code generation).

PHP_UML:
- Can generate UML/XMI files in version 1.4, or in version 2.1 (logical, component, and deployment views)
- Can generate an API documentation in HTML format
- Can generate PHP code (code skeleton) from a given XMI file
- Can convert UML/XMI content from version 1.4 to version 2.1

PHP_UML:
- Parses object-oriented PHP code, in all versions (classes, interfaces, functions, properties...)
- From version 1.5, PHP_UML can also parse procedural code (functions and constants). See the "htmlnew" exportation format
- Interprets the PHP namespacing instructions (namespace and use)
- Parses comment docblocks: class (@package), function (@param, @return), property (@var) and header file comments (@package)
- Detects types (by parsing the type hints, and by analyzing the default values)

I am currently using version PHP UML 1.6.1, installed on Mac OS X via macports.

PHP UML Caveats

PHP UML has some limitations, and one needs to baby-sit it quite a bit to get some usable XMI UML:

- PHP scalars like int, string, can't be used as type hints, so by default it handles most method parameters as DataType 'mixed'. However, if you use the @var property docblock (and you must include some documentation text on the line above the @var line) it will catch the scalar type ok.

  /**
   * The path portion of the URL for the menu set. 
   * 
   * @var string
   */
  private $path;

- For class types in @var, you must use the fully qualified class name including namespace !

  /**
   * The base path page controller (will be shared with the 1st tab menu item).
   *
   * @var \Drupal\ooe\Page\IPageController 
   */
  private $pageControllerBase;

It does not catch the array type notation recommended by the Drupal API documentation and comment standards in return types:

  /**
   * The menu items handled by this.
   *
   * @return \Drupal\ooe\Menu\IMenuItem[]
   *   The array of menu items handled by this.
   */
  public function getMenuItems();

The XMI will give no (not even void) return type.


If you have an array as default value for the matching property it will assign that as the type (ignoring the @var type):

  /**
   * The menu items handled by this.
   * 
   * @var \Drupal\ooe\Menu\IMenuItem[]
   */
  private $menuItems = array();

It does not handle {@inheritdoc}:

  /**
   * {@inheritdoc}
   */
  public function getMenuItems() { return $this->menuItems;}

The documentation will be extracted as '{@inheritdoc}'.


Visit also