Cameron Eagans
I'm a Principal Software Engineer at NBCUniversal. I build things for the web.
*Abridged
*
<?php
class Database {
protected $adapter;
public function __construct() {
$this->adapter = new MysqlAdapter();
}
}
class MysqlAdapter {}<?php
class Database {
protected $adapter;
public function __construct(
DatabaseAdapter $adapter
) {
$this->adapter = $adapter;
}
}
interface DatabaseAdapter {}
class MysqlAdapter implements DatabaseAdapter {}
class PgsqlAdapter implements DatabaseAdapter {}Before
After
or, "Chapter 8: Use PDO"
*or a wrapper on top of PDO, like Drupal's DBTNG
Code coverage numbers don't mean anything
<?php
/**
* @author A Name <a.name@example.com>
* @link http://www.phpdoc.org/docs/latest/index.html
*/
class DateTimeHelper {
/**
* @param mixed $anything Anything that we can convert to a \DateTime object
*
* @throws \InvalidArgumentException
*
* @return \DateTime
*/
public function dateTimeFromAnything($anything){}
}It looks like this:
RTFM at phpdoc.org
More details at http://www.phptherightway.com
By Cameron Eagans
I'm a Principal Software Engineer at NBCUniversal. I build things for the web.