Skip to content

Commit 786e864

Browse files
committed
Code quality using PHP_CodeSniffer
omit use of call_user_func_array remove error suppression
1 parent 083c446 commit 786e864

25 files changed

+1093
-972
lines changed

ActiveRecord.php

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
<?php
2-
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)
3-
die('PHP ActiveRecord requires PHP 5.3 or higher');
4-
5-
define('PHP_ACTIVERECORD_VERSION_ID','1.0');
6-
7-
if (!defined('PHP_ACTIVERECORD_AUTOLOAD_PREPEND'))
8-
define('PHP_ACTIVERECORD_AUTOLOAD_PREPEND',true);
9-
10-
require __DIR__.'/lib/Singleton.php';
11-
require __DIR__.'/lib/Config.php';
12-
require __DIR__.'/lib/Utils.php';
13-
require __DIR__.'/lib/DateTime.php';
14-
require __DIR__.'/lib/Model.php';
15-
require __DIR__.'/lib/Table.php';
16-
require __DIR__.'/lib/ConnectionManager.php';
17-
require __DIR__.'/lib/Connection.php';
18-
require __DIR__.'/lib/Serialization.php';
19-
require __DIR__.'/lib/SQLBuilder.php';
20-
require __DIR__.'/lib/Reflections.php';
21-
require __DIR__.'/lib/Inflector.php';
22-
require __DIR__.'/lib/CallBack.php';
23-
require __DIR__.'/lib/Exceptions.php';
24-
require __DIR__.'/lib/Cache.php';
25-
26-
if (!defined('PHP_ACTIVERECORD_AUTOLOAD_DISABLE'))
27-
spl_autoload_register('activerecord_autoload',false,PHP_ACTIVERECORD_AUTOLOAD_PREPEND);
28-
29-
function activerecord_autoload($class_name)
30-
{
31-
$path = ActiveRecord\Config::instance()->get_model_directory();
32-
$root = realpath(isset($path) ? $path : '.');
33-
34-
if (($namespaces = ActiveRecord\get_namespaces($class_name)))
35-
{
36-
$class_name = array_pop($namespaces);
37-
$directories = array();
38-
39-
foreach ($namespaces as $directory)
40-
$directories[] = $directory;
41-
42-
$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
43-
}
44-
45-
$file = "$root/$class_name.php";
46-
47-
if (file_exists($file))
48-
require_once $file;
49-
}
1+
<?php
2+
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)
3+
die('PHP ActiveRecord requires PHP 5.3 or higher');
4+
5+
define('PHP_ACTIVERECORD_VERSION_ID', '1.0');
6+
7+
if (!defined('PHP_ACTIVERECORD_AUTOLOAD_PREPEND'))
8+
define('PHP_ACTIVERECORD_AUTOLOAD_PREPEND', true);
9+
10+
require __DIR__.'/lib/Singleton.php';
11+
require __DIR__.'/lib/Config.php';
12+
require __DIR__.'/lib/Utils.php';
13+
require __DIR__.'/lib/DateTime.php';
14+
require __DIR__.'/lib/Model.php';
15+
require __DIR__.'/lib/Table.php';
16+
require __DIR__.'/lib/ConnectionManager.php';
17+
require __DIR__.'/lib/Connection.php';
18+
require __DIR__.'/lib/Serialization.php';
19+
require __DIR__.'/lib/SQLBuilder.php';
20+
require __DIR__.'/lib/Reflections.php';
21+
require __DIR__.'/lib/Inflector.php';
22+
require __DIR__.'/lib/CallBack.php';
23+
require __DIR__.'/lib/Exceptions.php';
24+
require __DIR__.'/lib/Cache.php';
25+
26+
if (!defined('PHP_ACTIVERECORD_AUTOLOAD_DISABLE'))
27+
spl_autoload_register('activerecord_autoload', false, PHP_ACTIVERECORD_AUTOLOAD_PREPEND);
28+
29+
function activerecord_autoload($class_name)
30+
{
31+
$path = ActiveRecord\Config::instance()->get_model_directory();
32+
$root = realpath(isset($path) ? $path : '.');
33+
34+
if (($namespaces = ActiveRecord\get_namespaces($class_name)))
35+
{
36+
$class_name = array_pop($namespaces);
37+
$directories = array();
38+
39+
foreach ($namespaces as $directory)
40+
$directories[] = $directory;
41+
42+
$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
43+
}
44+
45+
$file = "$root/$class_name.php";
46+
47+
if (file_exists($file))
48+
require_once $file;
49+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"require-dev": {
1212
"phpunit/phpunit": "3.7.*",
1313
"pear/pear_exception": "1.0.*@dev",
14-
"pear/Log": "dev-master"
14+
"pear/Log": "dev-master",
15+
"squizlabs/php_codesniffer": "2.*"
1516
},
1617
"autoload": {
1718
"files": [ "ActiveRecord.php" ]

lib/Cache.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static function initialize($url, $options=array())
5050
else
5151
static::$adapter = null;
5252

53-
static::$options = array_merge(array('expire' => 30, 'namespace' => ''),$options);
53+
static::$options = array_merge(array('expire' => 30, 'namespace' => ''), $options);
5454
}
5555

5656
public static function flush()
@@ -110,6 +110,7 @@ public static function delete($key)
110110

111111
private static function get_namespace()
112112
{
113-
return (isset(static::$options['namespace']) && strlen(static::$options['namespace']) > 0) ? (static::$options['namespace'] . "::") : "";
113+
return (isset(static::$options['namespace']) && strlen(static::$options['namespace']) > 0)
114+
? (static::$options['namespace'] . '::') : '';
114115
}
115116
}

lib/CallBack.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,20 @@ public function __construct($model_class_name)
114114
foreach (static::$VALID_CALLBACKS as $name)
115115
{
116116
// look for explicitly defined static callback
117-
if (($definition = $this->klass->getStaticPropertyValue($name,null)))
117+
if (($definition = $this->klass->getStaticPropertyValue($name, null)))
118118
{
119119
if (!is_array($definition))
120120
$definition = array($definition);
121121

122122
foreach ($definition as $method_name)
123-
$this->register($name,$method_name);
123+
$this->register($name, $method_name);
124124
}
125125

126126
// implicit callbacks that don't need to have a static definition
127127
// simply define a method named the same as something in $VALID_CALLBACKS
128128
// and the callback is auto-registered
129129
elseif ($this->klass->hasMethod($name))
130-
$this->register($name,$name);
130+
$this->register($name, $name);
131131
}
132132
}
133133

@@ -168,10 +168,11 @@ public function invoke($model, $name, $must_exist=true)
168168
else
169169
$registry = $this->registry[$name];
170170

171-
$first = substr($name,0,6);
171+
$first = substr($name, 0, 6);
172172

173173
// starts with /(after|before)_(create|update)/
174-
if (($first == 'after_' || $first == 'before') && (($second = substr($name,7,5)) == 'creat' || $second == 'updat' || $second == 'reate' || $second == 'pdate'))
174+
if (($first == 'after_' || $first == 'before')
175+
&& (($second = substr($name, 7, 5)) == 'creat' || $second == 'updat' || $second == 'reate' || $second == 'pdate'))
175176
{
176177
$temporal_save = str_replace(array('create', 'update'), 'save', $name);
177178

@@ -215,7 +216,7 @@ public function register($name, $closure_or_method_name=null, $options=array())
215216
if (!$closure_or_method_name)
216217
$closure_or_method_name = $name;
217218

218-
if (!in_array($name,self::$VALID_CALLBACKS))
219+
if (!in_array($name, self::$VALID_CALLBACKS))
219220
throw new ActiveRecordException("Invalid callback: $name");
220221

221222
if (!($closure_or_method_name instanceof Closure))
@@ -228,8 +229,8 @@ public function register($name, $closure_or_method_name=null, $options=array())
228229
if ($this->klass->hasMethod($closure_or_method_name))
229230
{
230231
// Method is private or protected
231-
throw new ActiveRecordException("Callback methods need to be public (or anonymous closures). " .
232-
"Please change the visibility of " . $this->klass->getName() . "->" . $closure_or_method_name . "()");
232+
throw new ActiveRecordException("Callback methods need to be public (or anonymous closures).
233+
Please change the visibility of {$this->klass->getName()}->{$closure_or_method_name}()");
233234
}
234235
else
235236
{

0 commit comments

Comments
 (0)