Skip to content

Feature: maintain coding style using PHP Code Sniffer #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ php:
- 5.4
- 5.5

script: ./vendor/bin/phpunit
script:
- ./vendor/bin/phpcs --standard=ruleset.xml --warning-severity=6 ./
- ./vendor/bin/phpunit
98 changes: 49 additions & 49 deletions ActiveRecord.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
<?php
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)
die('PHP ActiveRecord requires PHP 5.3 or higher');
define('PHP_ACTIVERECORD_VERSION_ID','1.0');
if (!defined('PHP_ACTIVERECORD_AUTOLOAD_PREPEND'))
define('PHP_ACTIVERECORD_AUTOLOAD_PREPEND',true);
require __DIR__.'/lib/Singleton.php';
require __DIR__.'/lib/Config.php';
require __DIR__.'/lib/Utils.php';
require __DIR__.'/lib/DateTime.php';
require __DIR__.'/lib/Model.php';
require __DIR__.'/lib/Table.php';
require __DIR__.'/lib/ConnectionManager.php';
require __DIR__.'/lib/Connection.php';
require __DIR__.'/lib/Serialization.php';
require __DIR__.'/lib/SQLBuilder.php';
require __DIR__.'/lib/Reflections.php';
require __DIR__.'/lib/Inflector.php';
require __DIR__.'/lib/CallBack.php';
require __DIR__.'/lib/Exceptions.php';
require __DIR__.'/lib/Cache.php';
if (!defined('PHP_ACTIVERECORD_AUTOLOAD_DISABLE'))
spl_autoload_register('activerecord_autoload',false,PHP_ACTIVERECORD_AUTOLOAD_PREPEND);
function activerecord_autoload($class_name)
{
$path = ActiveRecord\Config::instance()->get_model_directory();
$root = realpath(isset($path) ? $path : '.');
if (($namespaces = ActiveRecord\get_namespaces($class_name)))
{
$class_name = array_pop($namespaces);
$directories = array();
foreach ($namespaces as $directory)
$directories[] = $directory;
$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
}
$file = "$root/$class_name.php";
if (file_exists($file))
require_once $file;
}
<?php
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)
die('PHP ActiveRecord requires PHP 5.3 or higher');

define('PHP_ACTIVERECORD_VERSION_ID', '1.0');

if (!defined('PHP_ACTIVERECORD_AUTOLOAD_PREPEND'))
define('PHP_ACTIVERECORD_AUTOLOAD_PREPEND', true);

require __DIR__.'/lib/Singleton.php';
require __DIR__.'/lib/Config.php';
require __DIR__.'/lib/Utils.php';
require __DIR__.'/lib/DateTime.php';
require __DIR__.'/lib/Model.php';
require __DIR__.'/lib/Table.php';
require __DIR__.'/lib/ConnectionManager.php';
require __DIR__.'/lib/Connection.php';
require __DIR__.'/lib/Serialization.php';
require __DIR__.'/lib/SQLBuilder.php';
require __DIR__.'/lib/Reflections.php';
require __DIR__.'/lib/Inflector.php';
require __DIR__.'/lib/CallBack.php';
require __DIR__.'/lib/Exceptions.php';
require __DIR__.'/lib/Cache.php';

if (!defined('PHP_ACTIVERECORD_AUTOLOAD_DISABLE'))
spl_autoload_register('activerecord_autoload', false, PHP_ACTIVERECORD_AUTOLOAD_PREPEND);

function activerecord_autoload($class_name)
{
$path = ActiveRecord\Config::instance()->get_model_directory();
$root = realpath(isset($path) ? $path : '.');

if (($namespaces = ActiveRecord\get_namespaces($class_name)))
{
$class_name = array_pop($namespaces);
$directories = array();

foreach ($namespaces as $directory)
$directories[] = $directory;

$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
}

$file = "$root/$class_name.php";

if (file_exists($file))
require_once $file;
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"require-dev": {
"phpunit/phpunit": "3.7.*",
"pear/pear_exception": "1.0.*@dev",
"pear/Log": "dev-master"
"pear/Log": "dev-master",
"squizlabs/php_codesniffer": "2.*"
},
"autoload": {
"files": [ "ActiveRecord.php" ]
Expand Down
5 changes: 3 additions & 2 deletions lib/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function initialize($url, $options=array())
else
static::$adapter = null;

static::$options = array_merge(array('expire' => 30, 'namespace' => ''),$options);
static::$options = array_merge(array('expire' => 30, 'namespace' => ''), $options);
}

public static function flush()
Expand Down Expand Up @@ -110,6 +110,7 @@ public static function delete($key)

private static function get_namespace()
{
return (isset(static::$options['namespace']) && strlen(static::$options['namespace']) > 0) ? (static::$options['namespace'] . "::") : "";
return (isset(static::$options['namespace']) && strlen(static::$options['namespace']) > 0)
? (static::$options['namespace'] . '::') : '';
}
}
17 changes: 9 additions & 8 deletions lib/CallBack.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ public function __construct($model_class_name)
foreach (static::$VALID_CALLBACKS as $name)
{
// look for explicitly defined static callback
if (($definition = $this->klass->getStaticPropertyValue($name,null)))
if (($definition = $this->klass->getStaticPropertyValue($name, null)))
{
if (!is_array($definition))
$definition = array($definition);

foreach ($definition as $method_name)
$this->register($name,$method_name);
$this->register($name, $method_name);
}

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

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

$first = substr($name,0,6);
$first = substr($name, 0, 6);

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

Expand Down Expand Up @@ -215,7 +216,7 @@ public function register($name, $closure_or_method_name=null, $options=array())
if (!$closure_or_method_name)
$closure_or_method_name = $name;

if (!in_array($name,self::$VALID_CALLBACKS))
if (!in_array($name, self::$VALID_CALLBACKS))
throw new ActiveRecordException("Invalid callback: $name");

if (!($closure_or_method_name instanceof Closure))
Expand All @@ -228,8 +229,8 @@ public function register($name, $closure_or_method_name=null, $options=array())
if ($this->klass->hasMethod($closure_or_method_name))
{
// Method is private or protected
throw new ActiveRecordException("Callback methods need to be public (or anonymous closures). " .
"Please change the visibility of " . $this->klass->getName() . "->" . $closure_or_method_name . "()");
throw new ActiveRecordException("Callback methods need to be public (or anonymous closures).
Please change the visibility of {$this->klass->getName()}->{$closure_or_method_name}()");
}
else
{
Expand Down
Loading