Permalink
Browse files

Adding type hinting to constructor `$config` arrays and all applicabl…

…e `$options` parameters. Removing explicit array type casts where possible.
  • Loading branch information...
1 parent 220ea85 commit f80098da18b42bf15e115de9f3affd5ce286a827 @nateabele nateabele committed Feb 17, 2010
Showing with 255 additions and 258 deletions.
  1. +3 −3 libraries/lithium/action/Controller.php
  2. +2 −2 libraries/lithium/action/Dispatcher.php
  3. +2 −2 libraries/lithium/action/Response.php
  4. +1 −1 libraries/lithium/analysis/Debugger.php
  5. +1 −1 libraries/lithium/analysis/Docblock.php
  6. +6 −6 libraries/lithium/analysis/Inspector.php
  7. +4 −4 libraries/lithium/analysis/Parser.php
  8. +1 −1 libraries/lithium/analysis/logger/adapter/Cache.php
  9. +1 −1 libraries/lithium/analysis/logger/adapter/File.php
  10. +1 −1 libraries/lithium/analysis/logger/adapter/Syslog.php
  11. +8 −8 libraries/lithium/core/Libraries.php
  12. +1 −1 libraries/lithium/core/Object.php
  13. +1 −1 libraries/lithium/data/Connections.php
  14. +5 −5 libraries/lithium/data/Model.php
  15. +7 −7 libraries/lithium/data/Source.php
  16. +2 −2 libraries/lithium/data/model/Document.php
  17. +2 −2 libraries/lithium/data/model/Record.php
  18. +1 −1 libraries/lithium/data/model/RecordSet.php
  19. +5 −5 libraries/lithium/data/source/Database.php
  20. +5 −5 libraries/lithium/data/source/Http.php
  21. +5 −5 libraries/lithium/data/source/MongoDb.php
  22. +4 −4 libraries/lithium/data/source/database/adapter/MySQLi.php
  23. +2 −2 libraries/lithium/data/source/database/adapter/MySql.php
  24. +4 −4 libraries/lithium/data/source/database/adapter/Sqlite3.php
  25. +5 −5 libraries/lithium/data/source/http/adapter/CouchDb.php
  26. +2 −2 libraries/lithium/g11n/Catalog.php
  27. +4 −4 libraries/lithium/g11n/Message.php
  28. +1 −1 libraries/lithium/g11n/catalog/adapter/Cldr.php
  29. +1 −1 libraries/lithium/g11n/catalog/adapter/Code.php
  30. +1 −4 libraries/lithium/g11n/catalog/adapter/Gettext.php
  31. +1 −1 libraries/lithium/g11n/catalog/adapter/Php.php
  32. +2 −2 libraries/lithium/net/Socket.php
  33. +7 −6 libraries/lithium/net/http/Media.php
  34. +2 −2 libraries/lithium/net/http/Request.php
  35. +1 −1 libraries/lithium/net/http/Response.php
  36. +3 −3 libraries/lithium/net/http/Route.php
  37. +6 −6 libraries/lithium/net/http/Service.php
  38. +1 −1 libraries/lithium/net/socket/Context.php
  39. +1 −1 libraries/lithium/net/socket/Curl.php
  40. +1 −1 libraries/lithium/net/socket/Stream.php
  41. +3 −3 libraries/lithium/security/Auth.php
  42. +4 −4 libraries/lithium/security/auth/adapter/Form.php
  43. +4 −4 libraries/lithium/storage/Session.php
  44. +1 −1 libraries/lithium/storage/cache/adapter/Apc.php
  45. +1 −1 libraries/lithium/storage/cache/adapter/File.php
  46. +1 −1 libraries/lithium/storage/cache/adapter/Memcache.php
  47. +4 −4 libraries/lithium/storage/cache/adapter/Redis.php
  48. +1 −1 libraries/lithium/storage/cache/adapter/XCache.php
  49. +4 −4 libraries/lithium/storage/session/adapter/Cookie.php
  50. +4 −4 libraries/lithium/storage/session/adapter/Memory.php
  51. +4 −4 libraries/lithium/storage/session/adapter/Php.php
  52. +5 −5 libraries/lithium/template/Helper.php
  53. +2 −2 libraries/lithium/template/View.php
  54. +13 −13 libraries/lithium/template/helper/Form.php
  55. +7 −7 libraries/lithium/template/helper/Html.php
  56. +1 −1 libraries/lithium/template/view/Compiler.php
  57. +5 −6 libraries/lithium/template/view/Renderer.php
  58. +2 −2 libraries/lithium/template/view/adapter/File.php
  59. +2 −2 libraries/lithium/template/view/adapter/Simple.php
  60. +1 −1 libraries/lithium/test/Controller.php
  61. +1 −1 libraries/lithium/test/Dispatcher.php
  62. +2 −2 libraries/lithium/test/Filter.php
  63. +3 −3 libraries/lithium/test/Group.php
  64. +1 −1 libraries/lithium/test/Report.php
  65. +1 −1 libraries/lithium/test/Reporter.php
  66. +2 −2 libraries/lithium/test/Unit.php
  67. +2 −2 libraries/lithium/test/filter/Affected.php
  68. +2 −2 libraries/lithium/test/filter/Complexity.php
  69. +3 −3 libraries/lithium/test/filter/Coverage.php
  70. +2 −2 libraries/lithium/test/filter/Profiler.php
  71. +1 −1 libraries/lithium/test/reporter/Html.php
  72. +2 −2 libraries/lithium/tests/cases/security/auth/adapter/FormTest.php
  73. +1 −1 libraries/lithium/tests/mocks/action/MockMediaClass.php
  74. +1 −1 libraries/lithium/tests/mocks/console/MockResponse.php
  75. +1 −1 libraries/lithium/tests/mocks/console/command/MockLibraryService.php
  76. +1 −1 libraries/lithium/tests/mocks/core/MockObjectConfiguration.php
  77. +1 −1 libraries/lithium/tests/mocks/data/MockComment.php
  78. +4 −4 libraries/lithium/tests/mocks/data/MockSource.php
  79. +2 −2 libraries/lithium/tests/mocks/data/model/MockDocumentMultipleKey.php
  80. +2 −2 libraries/lithium/tests/mocks/data/model/MockDocumentPost.php
  81. +5 −5 libraries/lithium/tests/mocks/data/model/MockDocumentSource.php
  82. +5 −5 libraries/lithium/tests/mocks/data/source/database/adapter/MockAdapter.php
  83. +1 −1 libraries/lithium/tests/mocks/data/source/http/adapter/MockService.php
  84. +1 −1 libraries/lithium/tests/mocks/data/source/http/adapter/MockSocket.php
  85. +1 −1 libraries/lithium/tests/mocks/net/http/MockService.php
  86. +1 −1 libraries/lithium/tests/mocks/net/http/MockSocket.php
  87. +3 −3 libraries/lithium/tests/mocks/security/auth/adapter/MockAuthAdapter.php
  88. +2 −2 libraries/lithium/tests/mocks/storage/session/adapter/SessionStorageConditional.php
  89. +1 −1 libraries/lithium/tests/mocks/template/MockRenderer.php
  90. +1 −1 libraries/lithium/tests/mocks/template/helper/MockFormRenderer.php
  91. +1 −1 libraries/lithium/tests/mocks/template/helper/MockHtmlRenderer.php
  92. +1 −1 libraries/lithium/tests/mocks/util/MockCollectionObject.php
  93. +1 −1 libraries/lithium/tests/mocks/util/MockStringObject.php
  94. +4 −4 libraries/lithium/util/Collection.php
  95. +3 −3 libraries/lithium/util/Set.php
  96. +3 −3 libraries/lithium/util/String.php
  97. +3 −3 libraries/lithium/util/Validator.php
  98. +1 −1 libraries/lithium/util/collection/Filters.php
@@ -110,7 +110,7 @@ class Controller extends \lithium\core\Object {
'response' => '\lithium\action\Response'
);
- public function __construct($config = array()) {
+ public function __construct(array $config = array()) {
$defaults = array(
'request' => null, 'response' => array(), 'render' => array(), 'classes' => array()
);
@@ -138,7 +138,7 @@ public function __construct($config = array()) {
* @todo Implement proper exception catching/throwing
* @filter This method can be filtered.
*/
- public function __invoke($request, $dispatchParams, $options = array()) {
+ public function __invoke($request, $dispatchParams, array $options = array()) {
$classes = $this->_classes;
$config = $this->_config;
$render =& $this->_render;
@@ -250,7 +250,7 @@ public function render($options = array()) {
* @return void
* @filter This method can be filtered.
*/
- public function redirect($url, $options = array()) {
+ public function redirect($url, array $options = array()) {
$router = $this->_classes['router'];
$defaults = array('location' => null, 'status' => 302, 'head' => true, 'exit' => true);
$options += $defaults;
@@ -75,7 +75,7 @@ class Dispatcher extends \lithium\core\StaticObject {
* @return array If no parameters are passed, returns an associative array with the current
* configuration, otherwise returns `null`.
*/
- public static function config($config = array()) {
+ public static function config(array $config = array()) {
if (empty($config)) {
return array('rules' => static::$_rules);
}
@@ -100,7 +100,7 @@ public static function config($config = array()) {
* `lithium\action\Response`.
* @todo Add exception-handling/error page rendering
*/
- public static function run($request = null, $options = array()) {
+ public static function run($request = null, array $options = array()) {
$defaults = array('request' => array());
$options += $defaults;
$classes = static::$_classes;
@@ -25,9 +25,9 @@ class Response extends \lithium\net\http\Response {
protected $_config = array();
- public function __construct($config = array()) {
+ public function __construct(array $config = array()) {
$defaults = array('buffer' => 8192, 'request' => null);
- parent::__construct((array) $config + $defaults);
+ parent::__construct($config + $defaults);
}
protected function _init() {
@@ -26,7 +26,7 @@ class Debugger extends \lithium\core\Object {
* - `'trace'`: A trace to use instead of generating one.
* @return string|array Stack trace formatted according to `'format'` option.
*/
- public static function trace($options = array()) {
+ public static function trace(array $options = array()) {
$defaults = array(
'depth' => 999,
'format' => null,
@@ -88,7 +88,7 @@ public static function comment($description) {
* and `line` keys.
* @todo Actually implement useful $options
*/
- public static function parse($str, $options = array()) {
+ public static function parse($str, array $options = array()) {
$tagTypes = array('todo', 'discuss', 'fix', 'important');
$tags = '/@(?P<type>' . join('|', $tagTypes) . ')\s(?P<text>.+)$/mi';
@@ -171,7 +171,7 @@ public static function info($identifier, $info = array()) {
* filtered out as well.
* @return array Returns an array of the executable line numbers of the class.
*/
- public static function executable($class, $options = array()) {
+ public static function executable($class, array $options = array()) {
$defaults = array(
'self' => true, 'filter' => true, 'methods' => array(),
'empty' => array(' ', "\t", '}', ')', ';'), 'pattern' => null,
@@ -219,7 +219,7 @@ function($str) { return preg_quote($str, '/'); },
* and each value is an array of line numbers which are contained in the method.
* @param array $options
*/
- public static function methods($class, $format = null, $options = array()) {
+ public static function methods($class, $format = null, array $options = array()) {
$defaults = array('methods' => array(), 'group' => true, 'self' => true);
$options += $defaults;
@@ -268,7 +268,7 @@ public static function methods($class, $format = null, $options = array()) {
return $result;
}
- public static function properties($class, $options = array()) {
+ public static function properties($class, array $options = array()) {
$defaults = array('properties' => array(), 'self' => true);
$options += $defaults;
@@ -348,7 +348,7 @@ public static function lines($data, $lines) {
* or false on error.
* @link http://php.net/manual/en/function.class-parents.php
*/
- public static function parents($class, $options = array()) {
+ public static function parents($class, array $options = array()) {
$defaults = array('autoLoad' => false);
$options += $defaults;
$class = is_object($class) ? get_class($class) : $class;
@@ -367,7 +367,7 @@ public static function parents($class, $options = array()) {
* @return array Associative of classes and their corresponding definition files
* @todo Document valid options
*/
- public static function classes($options = array()) {
+ public static function classes(array $options = array()) {
$defaults = array('group' => 'classes', 'file' => null);
$options += $defaults;
@@ -410,7 +410,7 @@ function($class) { return new ReflectionClass($class); }, $list
* @return array An array of the static and dynamic class dependencies
* @todo Document valid options
*/
- public static function dependencies($classes, $options = array()) {
+ public static function dependencies($classes, array $options = array()) {
$defaults = array('type' => null);
$options += $defaults;
$static = $dynamic = array();
@@ -24,7 +24,7 @@ class Parser extends \lithium\core\StaticObject {
* @param string $options
* @return mixed
*/
- public static function token($string, $options = array()) {
+ public static function token($string, array $options = array()) {
$defaults = array('id' => false);
$options += $defaults;
@@ -35,7 +35,7 @@ public static function token($string, $options = array()) {
return $token[($options['id']) ? 'id' : 'name'];
}
- public static function tokenize($code, $options = array()) {
+ public static function tokenize($code, array $options = array()) {
$defaults = array('wrap' => true, 'ignore' => array(), 'include' => array());
$options += $defaults;
$tokens = array();
@@ -82,7 +82,7 @@ public static function tokenize($code, $options = array()) {
* the line of code to be matched, defaults to false
* @return array
*/
- public static function find($code, $pattern, $options = array()) {
+ public static function find($code, $pattern, array $options = array()) {
$defaults = array(
'all' => true, 'capture' => array(), 'ignore' => array('T_WHITESPACE'),
'return' => true, 'lineBreaks' => false, 'startOfLine' => false
@@ -193,7 +193,7 @@ function($i) use ($ret) { return isset($i[$ret]) ? $i[$ret] : $i; },
return $results;
}
- public static function match($code, $parameters, $options = array()) {
+ public static function match($code, $parameters, array $options = array()) {
$defaults = array('ignore' => array('T_WHITESPACE'), 'return' => true);
$options += $defaults;
$parameters = static::_prepareMatchParams($parameters);
@@ -22,7 +22,7 @@ class Cache extends \lithium\core\Object {
* @param array $config
* @return void
*/
- public function __construct($config = array()) {
+ public function __construct(array $config = array()) {
$defaults = array(
'config' => null,
'expiry' => '+999 days',
@@ -19,7 +19,7 @@ class File extends \lithium\core\Object {
* @param array $config
* @return void
*/
- public function __construct($config = array()) {
+ public function __construct(array $config = array()) {
$defaults = array('path' => LITHIUM_APP_PATH . '/resources/tmp/logs');
parent::__construct($config + $defaults);
}
@@ -27,7 +27,7 @@ class Syslog extends \lithium\core\Object {
* @param array $config
* @return void
*/
- public function __construct($config = array()) {
+ public function __construct(array $config = array()) {
$defaults = array(
'identity' => false,
'options' => LOG_ODELAY,
@@ -280,7 +280,7 @@ public static function remove($name) {
* @param string $options
* @return array
*/
- public static function find($library, $options = array()) {
+ public static function find($library, array $options = array()) {
$format = function ($file, $config) {
$trim = array(strlen($config['path']) + 1, strlen($config['suffix']));
$rTrim = strpos($file, $config['suffix']) !== false ? -$trim[1] : 9999;
@@ -363,7 +363,7 @@ public static function load($class, $require = false) {
* @return string Returns the absolute path to the file containing `$class`, or `null` if the
* file cannot be found.
*/
- public static function path($class, $options = array()) {
+ public static function path($class, array $options = array()) {
$defaults = array('dirs' => false);
$options += $defaults;
$class = ltrim($class, '\\');
@@ -455,7 +455,7 @@ public static function path($class, $options = array()) {
* registered library. If `$name` is not specified, returns an array of all classes
* found which match `$type`.
*/
- public static function locate($type, $name = null, $options = array()) {
+ public static function locate($type, $name = null, array $options = array()) {
$defaults = array('type' => 'class');
$options += $defaults;
@@ -476,7 +476,7 @@ public static function locate($type, $name = null, $options = array()) {
if (!$name) {
return static::_locateAll($params, $options);
}
- $paths = static::$_paths[$type];
+ $paths = (array) static::$_paths[$type];
if (strpos($name, '.')) {
list($params['library'], $params['name']) = explode('.', $name);
@@ -532,7 +532,7 @@ public static function cache($cache = null) {
* @see lithium\core\Libraries::$_paths
* @see lithium\core\Libraries::locate()
*/
- protected static function _locateDeferred($defer, $paths, $params, $options = array()) {
+ protected static function _locateDeferred($defer, $paths, $params, array $options = array()) {
if (isset($options['library'])) {
$libraries = (array) $options['library'];
$libraries = array_intersect_key(
@@ -577,7 +577,7 @@ protected static function _locateDeferred($defer, $paths, $params, $options = ar
* @param string $options
* @return void
*/
- protected static function _locateAll($params, $options = array()) {
+ protected static function _locateAll(array $params, array $options = array()) {
$defaults = array(
'libraries' => null, 'recursive' => true, 'namespaces' => false,
'filter' => false, 'exclude' => false,
@@ -588,14 +588,14 @@ protected static function _locateAll($params, $options = array()) {
}
);
$options += $defaults;
- $paths = static::$_paths[$params['type']];
+ $paths = (array) static::$_paths[$params['type']];
$libraries = $options['libraries'] ?: array_keys(static::$_configurations);
$classes = array();
foreach ($libraries as $library) {
$config = static::$_configurations[$library];
- foreach ((array) $paths as $template => $tplOpts) {
+ foreach ($paths as $template => $tplOpts) {
if (is_int($template)) {
$template = $tplOpts;
$tplOpts = array();
@@ -45,7 +45,7 @@ class Object {
* @param array $config
* @return object
*/
- public function __construct($config = array()) {
+ public function __construct(array $config = array()) {
$defaults = array('init' => true);
$this->_config = (array) $config + $defaults;
@@ -140,7 +140,7 @@ public static function add($name, $type = null, $config = array()) {
* configuration, instead of the connection itself.
* @return mixed A configured instance of the connection, or an array of the configuration used.
*/
- public static function get($name = null, $options = array()) {
+ public static function get($name = null, array $options = array()) {
$defaults = array('config' => false, 'autoCreate' => true);
$options += $defaults;
@@ -112,7 +112,7 @@ class Model extends \lithium\core\StaticObject {
* @return void
* @todo Merge in inherited config from AppModel and other parent classes.
*/
- public static function __init($options = array()) {
+ public static function __init(array $options = array()) {
if (($class = get_called_class()) == __CLASS__) {
return;
}
@@ -182,7 +182,7 @@ public static function __callStatic($method, $params) {
* @return void
* @filter This method can be filtered.
*/
- public static function find($type, $options = array()) {
+ public static function find($type, array $options = array()) {
$self = static::_instance();
$classes = $self->_classes;
@@ -384,7 +384,7 @@ public static function create($data = array()) {
*
* @return boolean Returns `true` on a successful save operation, `false` on failure.
*/
- public function save($record, $data = null, $options = array()) {
+ public function save($record, $data = null, array $options = array()) {
$self = static::_instance();
$classes = $self->_classes;
$meta = array('model' => get_called_class()) + $self->_meta;
@@ -417,7 +417,7 @@ public function save($record, $data = null, $options = array()) {
return static::_filter(__FUNCTION__, $params, $filter);
}
- public function validates($record, $options = array()) {
+ public function validates($record, array $options = array()) {
$self = static::_instance();
$validator = $self->_classes['validator'];
$params = compact('record', 'options');
@@ -433,7 +433,7 @@ public function validates($record, $options = array()) {
return static::_filter(__FUNCTION__, $params, $filter);
}
- public function delete($record, $options = array()) {
+ public function delete($record, array $options = array()) {
$self = static::_instance();
$query = $self->_classes['query'];
$model = get_called_class();
@@ -47,7 +47,7 @@
* @param array $config
* @return Source object
*/
- public function __construct($config = array()) {
+ public function __construct(array $config = array()) {
$defaults = array('autoConnect' => true);
parent::__construct((array) $config + $defaults);
}
@@ -64,6 +64,7 @@ public function __destruct() {
}
protected function _init() {
+ parent::_init();
if ($this->_config['autoConnect']) {
$this->connect();
}
@@ -82,7 +83,7 @@ protected function _init() {
* as the connection could have timed out or otherwise been dropped by the remote
* resource during the course of the request.
*/
- public function isConnected($options = array()) {
+ public function isConnected(array $options = array()) {
$defaults = array('autoConnect' => false);
$options += $defaults;
@@ -108,7 +109,6 @@ public function isConnected($options = array()) {
*
* @param string $model The fully-name-spaced class name of the object making the request.
* @return array Returns an array of objects to which models can connect.
- * @filter This method can be filtered.
*/
abstract public function entities($class = null);
@@ -121,7 +121,7 @@ public function isConnected($options = array()) {
* @param array $options
* @return boolean Returns true if the operation was a success, otherwise false.
*/
- abstract public function create($query, $options);
+ abstract public function create($query, array $options = array());
/**
* Abstract. Must be defined by child classes.
@@ -130,7 +130,7 @@ public function isConnected($options = array()) {
* @param array $options
* @return boolean Returns true if the operation was a success, otherwise false.
*/
- abstract public function read($query, $options);
+ abstract public function read($query, array $options = array());
/**
* Updates a set of records in a concrete data store.
@@ -142,7 +142,7 @@ public function isConnected($options = array()) {
* @param array $options Options to execute, which are defined by the concrete implementation.
* @return boolean Returns true if the update operation was a success, otherwise false.
*/
- abstract public function update($query, $options);
+ abstract public function update($query, array $options = array());
/**
* Abstract. Must be defined by child classes.
@@ -151,7 +151,7 @@ public function isConnected($options = array()) {
* @param array $options
* @return boolean Returns true if the operation was a success, otherwise false.
*/
- abstract public function delete($query, $options);
+ abstract public function delete($query, array $options = array());
/**
* A method which can be optionally implemented to configure a model class.
Oops, something went wrong.

0 comments on commit f80098d

Please sign in to comment.