Commit 716bb65b authored by lsmith's avatar lsmith

- first round of PEAR CS fixes

parent f6400e01
......@@ -344,9 +344,9 @@ final class Doctrine {
* @return string
*/
public static function getPath() {
if(! self::$path)
if (! self::$path) {
self::$path = dirname(__FILE__);
}
return self::$path;
}
/**
......@@ -358,7 +358,7 @@ final class Doctrine {
public static function loadAll() {
$classes = Doctrine_Compiler::getRuntimeClasses();
foreach($classes as $class) {
foreach ($classes as $class) {
Doctrine::autoload($class);
}
}
......@@ -400,17 +400,17 @@ final class Doctrine {
* @return boolean
*/
public static function autoload($classname) {
if(class_exists($classname))
if (class_exists($classname)) {
return false;
if(! self::$path)
}
if (! self::$path) {
self::$path = dirname(__FILE__);
}
$class = self::$path.DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR,$classname) . '.php';
if( ! file_exists($class))
if ( ! file_exists($class)) {
return false;
}
require_once($class);
......@@ -441,7 +441,7 @@ final class Doctrine {
* @return boolean
*/
public static function isValidClassname($classname) {
if(preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname))
if (preg_match('~(^[a-z])|(_[a-z])|([\W])|(_{2})~', $classname))
return false;
return true;
......
......@@ -41,9 +41,9 @@ abstract class Doctrine_Access implements ArrayAccess {
* @return Doctrine_Access
*/
public function setArray(array $array) {
foreach($array as $k=>$v):
foreach ($array as $k=>$v) {
$this->set($k,$v);
endforeach;
};
return $this;
}
......@@ -114,11 +114,12 @@ abstract class Doctrine_Access implements ArrayAccess {
* @return void
*/
public function offsetSet($offset, $value) {
if( ! isset($offset)) {
if ( ! isset($offset)) {
$this->add($value);
} else
} else {
$this->set($offset,$value);
}
}
/**
* unset a given offset
* @see set, offsetSet, __set
......@@ -128,4 +129,3 @@ abstract class Doctrine_Access implements ArrayAccess {
return $this->remove($offset);
}
}
......@@ -49,19 +49,17 @@ class Doctrine_Cache_Query_Sqlite implements Countable {
* @param Doctrine_Connection|null $connection
*/
public function __construct($connection = null) {
if( ! ($connection instanceof Doctrine_Connection))
if ( ! ($connection instanceof Doctrine_Connection)) {
$connection = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->session = $connection;
$dir = 'cache';
$this->path = $dir.DIRECTORY_SEPARATOR;
$this->dbh = new PDO("sqlite::memory:");
try {
if($this->session->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true)
{
if ($this->session->getAttribute(Doctrine::ATTR_CREATE_TABLES) === true) {
$columns = array();
$columns['query_md5'] = array('string', 32, 'notnull');
$columns['query_result'] = array('array', 100000, 'notnull');
......
This diff is collapsed.
......@@ -53,9 +53,9 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
*/
public function setBatchSize($batchSize) {
$batchSize = (int) $batchSize;
if($batchSize <= 0)
if ($batchSize <= 0) {
return false;
}
$this->batchSize = $batchSize;
return true;
}
......@@ -75,40 +75,39 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @return boolean whether or not the load operation was successful
*/
public function load(Doctrine_Record $record) {
if(empty($this->data))
if (empty($this->data)) {
return false;
}
$id = $record->obtainIdentifier();
$identifier = $this->table->getIdentifier();
foreach($this->data as $key => $v) {
if(is_object($v)) {
if($v->obtainIdentifier() == $id)
foreach ($this->data as $key => $v) {
if (is_object($v)) {
if ($v->obtainIdentifier() == $id) {
break;
} elseif(is_array($v[$identifier])) {
if($v[$identifier] == $id)
}
} elseif (is_array($v[$identifier])) {
if ($v[$identifier] == $id) {
break;
}
}
}
$x = floor($key / $this->batchSize);
if( ! isset($this->loaded[$x])) {
if ( ! isset($this->loaded[$x])) {
$e = $x * $this->batchSize;
$e2 = ($x + 1)* $this->batchSize;
$a = array();
$proxies = array();
for($i = $e; $i < $e2 && $i < $this->count(); $i++):
if($this->data[$i] instanceof Doctrine_Record)
for ($i = $e; $i < $e2 && $i < $this->count(); $i++) {
if ($this->data[$i] instanceof Doctrine_Record) {
$id = $this->data[$i]->getIncremented();
elseif(is_array($this->data[$i]))
} elseif (is_array($this->data[$i])) {
$id = $this->data[$i][$identifier];
}
$a[$i] = $id;
endfor;
};
$c = count($a);
......@@ -120,14 +119,14 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
$stmt = $this->table->getConnection()->execute($query,array_values($a));
foreach($a as $k => $id) {
foreach ($a as $k => $id) {
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row === false)
if ($row === false) {
break;
}
$this->table->setData($row);
if(is_object($this->data[$k])) {
if (is_object($this->data[$k])) {
$this->data[$k]->factoryRefresh($this->table);
} else {
$this->data[$k] = $this->table->getRecord();
......@@ -148,8 +147,8 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
* @return object Doctrine_Record record
*/
public function get($key) {
if(isset($this->data[$key])) {
switch(gettype($this->data[$key])):
if (isset($this->data[$key])) {
switch (gettype($this->data[$key])) {
case "array":
// Doctrine_Record didn't exist in cache
$this->table->setData($this->data[$key]);
......@@ -157,21 +156,18 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
$this->data[$key]->addCollection($this);
break;
endswitch;
};
} else {
$this->expand($key);
if( ! isset($this->data[$key]))
if ( ! isset($this->data[$key])) {
$this->data[$key] = $this->table->create();
}
}
if(isset($this->reference_field))
if (isset($this->reference_field)) {
$this->data[$key]->set($this->reference_field, $this->reference, false);
}
return $this->data[$key];
}
/**
......@@ -181,4 +177,3 @@ class Doctrine_Collection_Batch extends Doctrine_Collection {
return new Doctrine_Collection_Iterator_Expandable($this);
}
}
......@@ -18,4 +18,3 @@ class Doctrine_Collection_Immediate extends Doctrine_Collection {
parent::__construct($table);
}
}
......@@ -69,9 +69,10 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
public function rewind() {
$this->index = 0;
$i = $this->index;
if(isset($this->keys[$i]))
if (isset($this->keys[$i])) {
$this->key = $this->keys[$i];
}
}
/**
* returns the current key
......@@ -97,10 +98,8 @@ abstract class Doctrine_Collection_Iterator implements Iterator {
public function next() {
$this->index++;
$i = $this->index;
if(isset($this->keys[$i]))
if (isset($this->keys[$i])) {
$this->key = $this->keys[$i];
}
}
}
......@@ -32,15 +32,14 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
*/
class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterator {
public function valid() {
if($this->index < $this->count)
if ($this->index < $this->count) {
return true;
elseif($this->index == $this->count) {
} elseif ($this->index == $this->count) {
$coll = $this->collection->expand($this->index);
if($coll instanceof Doctrine_Collection) {
if ($coll instanceof Doctrine_Collection) {
$count = count($coll);
if($count > 0) {
if ($count > 0) {
$this->keys = array_merge($this->keys, $coll->getKeys());
$this->count += $count;
return true;
......@@ -51,4 +50,3 @@ class Doctrine_Collection_Iterator_Expandable extends Doctrine_Collection_Iterat
}
}
}
......@@ -38,4 +38,3 @@ class Doctrine_Collection_Iterator_Normal extends Doctrine_Collection_Iterator {
return ($this->index < $this->count);
}
}
......@@ -33,5 +33,3 @@ Doctrine::autoload('Doctrine_Collection_Iterator');
class Doctrine_Collection_Iterator_Offset extends Doctrine_Collection_Iterator {
public function valid() { }
}
......@@ -22,4 +22,3 @@ class Doctrine_Collection_Lazy extends Doctrine_Collection_Batch {
parent::setBatchSize(1);
}
}
......@@ -56,4 +56,3 @@ class Doctrine_Collection_Offset extends Doctrine_Collection {
return new Doctrine_Collection_Iterator_Expandable($this);
}
}
......@@ -127,17 +127,17 @@ class Doctrine_Compiler {
$ret = array();
foreach($classes as $class) {
if($class !== 'Doctrine')
foreach ($classes as $class) {
if ($class !== 'Doctrine')
$class = 'Doctrine_'.$class;
$file = $path.DIRECTORY_SEPARATOR.str_replace("_",DIRECTORY_SEPARATOR,$class).".php";
echo "Adding $file" . PHP_EOL;
if( ! file_exists($file))
if ( ! file_exists($file)) {
throw new Doctrine_Compiler_Exception("Couldn't compile $file. File $file does not exists.");
}
Doctrine::autoload($class);
$refl = new ReflectionClass ( $class );
$lines = file( $file );
......@@ -160,9 +160,9 @@ class Doctrine_Compiler {
// that we can use php_strip_whitespace (which only works on files)
$fp = @fopen($target, 'w');
if ($fp === false)
if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $target");
}
fwrite($fp, "<?php".
" class InvalidKeyException extends Exception { }".
implode('', $ret)
......@@ -171,8 +171,9 @@ class Doctrine_Compiler {
$stripped = php_strip_whitespace($target);
$fp = @fopen($target, 'w');
if ($fp === false)
if ($fp === false) {
throw new Doctrine_Compiler_Exception("Couldn't write compiled data. Failed to open $file");
}
fwrite($fp, $stripped);
fclose($fp);
}
......
......@@ -61,29 +61,32 @@ abstract class Doctrine_Configurable {
* @return void
*/
public function setAttribute($attribute,$value) {
switch($attribute):
switch ($attribute) {
case Doctrine::ATTR_BATCH_SIZE:
if($value < 0)
if ($value < 0) {
throw new Doctrine_Exception("Batch size should be greater than or equal to zero");
}
break;
case Doctrine::ATTR_FETCHMODE:
if($value < 0)
if ($value < 0) {
throw new Doctrine_Exception("Unknown fetchmode. See Doctrine::FETCH_* constants.");
}
break;
case Doctrine::ATTR_LISTENER:
$this->setEventListener($value);
break;
case Doctrine::ATTR_LOCKMODE:
if($this instanceof Doctrine_Connection) {
if($this->transaction->getState() != Doctrine_Transaction::STATE_SLEEP)
if ($this instanceof Doctrine_Connection) {
if ($this->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) {
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
} elseif($this instanceof Doctrine_Manager) {
foreach($this as $connection) {
if($connection->transaction->getState() != Doctrine_Transaction::STATE_SLEEP)
}
} elseif ($this instanceof Doctrine_Manager) {
foreach ($this as $connection) {
if ($connection->transaction->getState() != Doctrine_Transaction::STATE_SLEEP) {
throw new Doctrine_Exception("Couldn't set lockmode. There are transactions open.");
}
}
} else {
throw new Doctrine_Exception("Lockmode attribute can only be set at the global or connection level.");
}
......@@ -94,23 +97,23 @@ abstract class Doctrine_Configurable {
case Doctrine::ATTR_ACCESSORS:
$accessors = array('none','get','set','both');
// if( ! in_array($value,$accessors))
// if ( ! in_array($value,$accessors)) {
// throw new Doctrine_Exception();
// }
break;
case Doctrine::ATTR_COLL_LIMIT:
if($value < 1) {
if ($value < 1) {
throw new Doctrine_Exception("Collection limit should be a value greater than or equal to 1.");
}
break;
case Doctrine::ATTR_COLL_KEY:
if( ! ($this instanceof Doctrine_Table))
if ( ! ($this instanceof Doctrine_Table)) {
throw new Doctrine_Exception("This attribute can only be set at table level.");
if( ! $this->hasColumn($value))
}
if ( ! $this->hasColumn($value)) {
throw new Doctrine_Exception("Couldn't set collection key attribute. No such column '$value'");
}
break;
case Doctrine::ATTR_VLD:
case Doctrine::ATTR_AUTO_LENGTH_VLD:
......@@ -124,24 +127,24 @@ abstract class Doctrine_Configurable {
break;
case Doctrine::ATTR_SEQCOL_NAME:
if( ! is_string($value))
if ( ! is_string($value)) {
throw new Doctrine_Exception('Sequence column name attribute only accepts string values');
}
break;
case Doctrine::ATTR_FIELD_CASE:
if($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER)
if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER)
throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.');
break;
case Doctrine::ATTR_SEQNAME_FORMAT:
case Doctrine::ATTR_IDXNAME_FORMAT:
if($this instanceof Doctrine_Table) {
if ($this instanceof Doctrine_Table) {
throw new Doctrine_Exception('Sequence / index name format attributes cannot be set'
. 'at table level (only at connection or global level).');
}
break;
default:
throw new Doctrine_Exception("Unknown attribute.");
endswitch;
};
$this->attributes[$attribute] = $value;
......@@ -160,9 +163,9 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db
*/
public function addListener($listener, $name = null) {
if( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain))
if ( ! ($this->attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) {
$this->attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain();
}
$this->attributes[Doctrine::ATTR_LISTENER]->add($listener, $name);
return $this;
......@@ -173,10 +176,10 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db_EventListener_Interface|Doctrine_Overloadable
*/
public function getListener() {
if( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
if(isset($this->parent))
if ( ! isset($this->attributes[Doctrine::ATTR_LISTENER])) {
if (isset($this->parent)) {
return $this->parent->getListener();
}
return null;
}
return $this->attributes[Doctrine::ATTR_LISTENER];
......@@ -188,10 +191,11 @@ abstract class Doctrine_Configurable {
* @return Doctrine_Db
*/
public function setListener($listener) {
if( ! ($listener instanceof Doctrine_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
if ( ! ($listener instanceof Doctrine_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable");
}
$this->attributes[Doctrine::ATTR_LISTENER] = $listener;
return $this;
......@@ -205,13 +209,13 @@ abstract class Doctrine_Configurable {
public function getAttribute($attribute) {
$attribute = (int) $attribute;
if($attribute < 1 || $attribute > 23)
if ($attribute < 1 || $attribute > 23)
throw new Doctrine_Exception('Unknown attribute.');
if( ! isset($this->attributes[$attribute])) {
if(isset($this->parent))
if ( ! isset($this->attributes[$attribute])) {
if (isset($this->parent)) {
return $this->parent->getAttribute($attribute);
}
return null;
}
return $this->attributes[$attribute];
......@@ -245,4 +249,3 @@ abstract class Doctrine_Configurable {
return $this->parent;
}
}
This diff is collapsed.
......@@ -19,15 +19,14 @@ class Doctrine_Connection_Common extends Doctrine_Connection {
* @param mixed $offset
*/
public function modifyLimitQuery($query,$limit = false,$offset = false,$isManip=false) {
if($limit && $offset) {
if ($limit && $offset) {
$query .= " LIMIT ".$limit." OFFSET ".$offset;
} elseif($limit && ! $offset) {
} elseif ($limit && ! $offset) {
$query .= " LIMIT ".$limit;
} elseif( ! $limit && $offset) {
} elseif ( ! $limit && $offset) {
$query .= " LIMIT 999999999999 OFFSET ".$offset;
}
return $query;
}
}
......@@ -40,13 +40,12 @@ class Doctrine_Connection_Db2 extends Doctrine_Connection {
* @return string the modified query
*/
public function modifyLimitQuery($query, $limit, $offset) {
if($limit <= 0)
if ($limit <= 0)
return $sql;
if($offset == 0) {
if ($offset == 0) {
return $sql . ' FETCH FIRST '. $count .' ROWS ONLY';
} else {
$sqlPieces = explode('from', $sql);
$select = $sqlPieces[0];
$table = $sqlPieces[1];
......
......@@ -95,7 +95,7 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
* @return string modified query
*/
public function modifyLimitQuery($query, $limit, $offset) {
if($limit > 0) {
if ($limit > 0) {
$query = preg_replace('/^([\s(])*SELECT(?!\s*FIRST\s*\d+)/i',
"SELECT FIRST $limit SKIP $offset", $query);
}
......@@ -112,4 +112,3 @@ class Doctrine_Connection_Firebird extends Doctrine_Connection {
return $data[0];
}
}
......@@ -118,15 +118,15 @@ class Doctrine_Connection_Firebird_Exception extends Doctrine_Connection_Excepti
}
*/
foreach(self::$errorRegexps as $regexp => $code) {
foreach (self::$errorRegexps as $regexp => $code) {
if (preg_match($regexp, $errorInfo[2])) {
$errorInfo[3] = $code;
break;
}
}
if(isset(self::$errorCodeMap[$errorInfo[1]]))
if (isset(self::$errorCodeMap[$errorInfo[1]])) {
$errorInfo[3] = self::$errorCodeMap[$errorInfo[1]];
}
return $errorInfo;
}
}
......@@ -44,9 +44,9 @@ class Doctrine_Connection_Module {
* module holds an instance of Doctrine_Connection
*/
public function __construct($conn = null) {
if( ! ($conn instanceof Doctrine_Connection))
if ( ! ($conn instanceof Doctrine_Connection)) {
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
}
$this->conn = $conn;
$e = explode('_', get_class($this));
......
......@@ -104,13 +104,12 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
* @return string
*/
public function modifyLimitQuery($query, $limit, $offset, $isManip = false) {
if($limit > 0) {
if ($limit > 0) {
// we need the starting SELECT clause for later
$select = 'SELECT ';
if (preg_match('/^[[:space:]*SELECT[[:space:]]*DISTINCT/i', $query, $matches) == 1)
if (preg_match('/^[[:space:]*SELECT[[:space:]]*DISTINCT/i', $query, $matches) == 1) {
$select .= 'DISTINCT ';
}
$length = strlen($select);
// is there an offset?
......@@ -168,4 +167,3 @@ class Doctrine_Connection_Mssql extends Doctrine_Connection {
return $this->queryOne($query);
}
}
......@@ -63,7 +63,7 @@ class Doctrine_Connection_Mssql_Exception extends Doctrine_Connection_Exception
*/
public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) {
if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code];
return true;
}
......
......@@ -85,7 +85,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$this->properties['varchar_max_length'] = 255;
parent::__construct($manager, $adapter);
}
/**
......@@ -118,7 +117,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$value = $this->dbh->lastInsertId();
if(is_numeric($value)) {
if (is_numeric($value)) {
$query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
$result = $this->dbh->query($query);
}
......@@ -205,17 +204,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$query = $values = '';
$keys = $colnum = 0;
for(reset($fields); $colnum < $count; next($fields), $colnum++) {
for (reset($fields); $colnum < $count; next($fields), $colnum++) {
$name = key($fields);
if($colnum > 0) {
if ($colnum > 0) {
$query .= ',';
$values.= ',';
}
$query .= $name;
if(isset($fields[$name]['null']) && $fields[$name]['null']) {
if (isset($fields[$name]['null']) && $fields[$name]['null']) {
$value = 'NULL';
} else {
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
......@@ -224,18 +223,17 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
$values .= $value;
if(isset($fields[$name]['key']) && $fields[$name]['key']) {
if($value === 'NULL')
if (isset($fields[$name]['key']) && $fields[$name]['key']) {
if ($value === 'NULL') {
throw new Doctrine_Connection_Mysql_Exception('key value '.$name.' may not be NULL');
}
$keys++;
}
}
if($keys == 0)
if ($keys == 0) {
throw new Doctrine_Connection_Mysql_Exception('not specified which fields are keys');
}
$query = 'REPLACE INTO ' . $table . ' (' . $query . ') VALUES (' . $values . ')';
return $this->dbh->exec($query);
......
......@@ -73,7 +73,7 @@ class Doctrine_Connection_Mysql_Exception extends Doctrine_Connection_Exception
*/
public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) {
if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code];
return true;
}
......
......@@ -36,7 +36,6 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
*/
protected $driverName = 'Oracle';
public function __construct(Doctrine_Manager $manager, $adapter) {
$this->supported = array(
'sequences' => true,
......@@ -127,4 +126,3 @@ class Doctrine_Connection_Oracle extends Doctrine_Connection {
return $data[0];
}
}
......@@ -68,7 +68,7 @@ class Doctrine_Connection_Oracle_Exception extends Doctrine_Connection_Exception
*/
public function processErrorInfo(array $errorInfo) {
$code = $errorInfo[1];
if(isset(self::$errorCodeMap[$code])) {
if (isset(self::$errorCodeMap[$code])) {
$this->portableCode = self::$errorCodeMap[$code];
return true;
}
......
......@@ -132,10 +132,10 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
. $from . ' ' . $where . ' LIMIT ' . $limit . ')';
} else {
if($limit !== false) {
if ($limit !== false) {
$query .= ' LIMIT ' . $limit;
}
if($offset !== false) {
if ($offset !== false) {
$query .= ' OFFSET ' . $offset;
}
}
......@@ -153,12 +153,12 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common {
$serverInfo = $this->fetchOne($query);
if( ! $native) {
if ( ! $native) {
$tmp = explode('.', $server_info, 3);
if(empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)) {
if (empty($tmp[2]) && isset($tmp[1])
&& preg_match('/(\d+)(.*)/', $tmp[1], $tmp2)
) {
$serverInfo = array(
'major' => $tmp[0],
'minor' => $tmp2[1],
......
......@@ -96,4 +96,3 @@ class Doctrine_Connection_Sqlite extends Doctrine_Connection_Common {
return $data[0];
}
}
......@@ -63,8 +63,8 @@ class Doctrine_Connection_Sqlite_Exception extends Doctrine_Connection_Exception
* (the process is successfull if portable error code was found)
*/
public function processErrorInfo(array $errorInfo) {
foreach(self::$errorRegexps as $regexp => $code) {
if(preg_match($regexp, $errorInfo[2])) {
foreach (self::$errorRegexps as $regexp => $code) {
if (preg_match($regexp, $errorInfo[2])) {
$this->portableCode = $code;
return true;
......
This diff is collapsed.
......@@ -54,7 +54,7 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
* declare the specified field.
*/
public function getNativeDeclaration($field) {
switch($field['type']) {
switch ($field['type']) {
case 'varchar':
case 'string':
case 'array':
......@@ -99,7 +99,7 @@ class Doctrine_DataDict_Firebird extends Doctrine_DataDict {
public function getPortableDeclaration($field) {
$length = $field['length'];
if((int) $length <= 0)
if ((int) $length <= 0)
$length = null;
$type = array();
......
......@@ -102,5 +102,4 @@ class Doctrine_DataDict_Informix extends Doctrine_DataDict {
}
return '';
}
}
......@@ -143,7 +143,7 @@ class Doctrine_DataDict_Mysql extends Doctrine_DataDict {
case 'string':
if ( ! isset($field['length'])) {
if(array_key_exists('default', $field)) {
if (array_key_exists('default', $field)) {
$field['length'] = $this->conn->varchar_max_length;
} else {
$field['length'] = false;
......
......@@ -561,7 +561,7 @@ class Doctrine_DataDict_Pgsql extends Doctrine_DataDict {
}
*/
if( ! empty($field['autoincrement'])) {
if ( ! empty($field['autoincrement'])) {
$name = $this->conn->quoteIdentifier($name, true);
return $name.' '.$this->getNativeDeclaration($field);
}
......
......@@ -254,10 +254,10 @@ class Doctrine_DataDict_Sqlite extends Doctrine_DataDict {
$default = $autoinc = '';
$type = $this->getNativeDeclaration($field);
if(isset($field['autoincrement']) && $field['autoincrement']) {
if (isset($field['autoincrement']) && $field['autoincrement']) {
$autoinc = ' PRIMARY KEY AUTOINCREMENT';
$type = 'INTEGER';
} elseif(array_key_exists('default', $field)) {
} elseif (array_key_exists('default', $field)) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull']) ? null : 0;
}
......
......@@ -84,7 +84,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
'sqlite2' => 'sqlite',
'sqlite3' => 'sqlite');
/**
* constructor
*
......@@ -93,7 +92,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @param string $pass database password
*/
public function __construct($dsn, $user, $pass) {
if( ! isset($user)) {
if ( ! isset($user)) {
$a = self::parseDSN($dsn);
extract($a);
......@@ -104,7 +103,6 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->listener = new Doctrine_Db_EventListener();
}
public function nextQuerySequence() {
return ++$this->querySequence;
}
......@@ -121,9 +119,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
return $this->dbh;
}
public function getOption($name) {
if( ! array_key_exists($name, $this->options))
if ( ! array_key_exists($name, $this->options)) {
throw new Doctrine_Db_Exception('Unknown option ' . $name);
}
return $this->options[$name];
}
/**
......@@ -133,9 +131,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return Doctrine_Db
*/
public function addListener($listener, $name = null) {
if( ! ($this->listener instanceof Doctrine_Db_EventListener_Chain))
if ( ! ($this->listener instanceof Doctrine_Db_EventListener_Chain)) {
$this->listener = new Doctrine_Db_EventListener_Chain();
}
$this->listener->add($listener, $name);
return $this;
......@@ -155,10 +153,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return Doctrine_Db
*/
public function setListener($listener) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't set eventlistener for database handler. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
$this->listener = $listener;
return $this;
......@@ -171,7 +170,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return boolean
*/
public function connect() {
if($this->isConnected)
if ($this->isConnected)
return false;
$this->dbh = new PDO($this->options['dsn'], $this->options['username'], $this->options['password']);
......@@ -201,9 +200,9 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return string
*/
public static function driverName($name) {
if(isset(self::$driverMap[$name]))
if (isset(self::$driverMap[$name])) {
return self::$driverMap[$name];
}
return $name;
}
/**
......@@ -218,24 +217,25 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$names = array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach($names as $name) {
if( ! isset($parts[$name]))
foreach ($names as $name) {
if ( ! isset($parts[$name])) {
$parts[$name] = null;
}
}
if(count($parts) == 0 || ! isset($parts['scheme']))
if (count($parts) == 0 || ! isset($parts['scheme'])) {
throw new Doctrine_Db_Exception('Empty data source name');
}
$drivers = self::getAvailableDrivers();
$parts['scheme'] = self::driverName($parts['scheme']);
if( ! in_array($parts['scheme'], $drivers))
if ( ! in_array($parts['scheme'], $drivers)) {
throw new Doctrine_Db_Exception('Driver '.$parts['scheme'].' not availible or extension not loaded');
switch($parts['scheme']) {
}
switch ($parts['scheme']) {
case 'sqlite':
if(isset($parts['host']) && $parts['host'] == ':memory') {
if (isset($parts['host']) && $parts['host'] == ':memory') {
$parts['database'] = ':memory:';
$parts['dsn'] = 'sqlite::memory:';
}
......@@ -248,15 +248,15 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
case 'firebird':
case 'pgsql':
case 'odbc':
if( ! isset($parts['path']) || $parts['path'] == '/')
if ( ! isset($parts['path']) || $parts['path'] == '/') {
throw new Doctrine_Db_Exception('No database availible in data source name');
if(isset($parts['path']))
}
if (isset($parts['path'])) {
$parts['database'] = substr($parts['path'], 1);
if( ! isset($parts['host']))
}
if ( ! isset($parts['host'])) {
throw new Doctrine_Db_Exception('No hostname set in data source name');
}
$parts['dsn'] = $parts["scheme"].":host=".$parts["host"].";dbname=".$parts["database"];
break;
default:
......@@ -327,11 +327,11 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
$this->listener->onPreQuery($event);
if( ! empty($params))
if ( ! empty($params)) {
$stmt = $this->dbh->query($statement)->execute($params);
else
} else {
$stmt = $this->dbh->query($statement);
}
$this->listener->onQuery($event);
$this->querySequence++;
......@@ -468,7 +468,7 @@ class Doctrine_Db implements Countable, IteratorAggregate, Doctrine_Adapter_Inte
* @return ArrayIterator
*/
public function getIterator() {
if($this->listener instanceof Doctrine_Db_Profiler)
if ($this->listener instanceof Doctrine_Db_Profiler)
return $this->listener;
}
/**
......
......@@ -78,9 +78,9 @@ class Doctrine_Db_Event {
* @return mixed
*/
public function getElapsedSecs() {
if (is_null($this->endedMicrotime))
if (is_null($this->endedMicrotime)) {
return false;
}
return ($this->endedMicrotime - $this->startedMicrotime);
}
......
......@@ -35,104 +35,107 @@ class Doctrine_Db_EventListener_Chain extends Doctrine_Access implements Doctrin
private $listeners = array();
public function add($listener, $name = null) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't add eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
if($name === null)
}
if ($name === null) {
$this->listeners[] = $listener;
else
} else {
$this->listeners[$name] = $listener;
}
}
public function get($name) {
if( ! isset($this->listeners[$name]))
if ( ! isset($this->listeners[$name])) {
throw new Doctrine_Db_Exception("Unknown listener $name");
}
return $this->listeners[$name];
}
public function set($name, $listener) {
if( ! ($listener instanceof Doctrine_Db_EventListener_Interface) &&
! ($listener instanceof Doctrine_Overloadable))
if ( ! ($listener instanceof Doctrine_Db_EventListener_Interface)
&& ! ($listener instanceof Doctrine_Overloadable)
) {
throw new Doctrine_Db_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_Db_EventListener_Interface or Doctrine_Overloadable");
}
$this->listeners[$name] = $listener;
}
public function onQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onQuery($event);
}
}
public function onPreQuery(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreQuery($event);
}
}
public function onPreExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreExec($event);
}
}
public function onExec(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onExec($event);
}
}
public function onPrePrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPrePrepare($event);
}
}
public function onPrepare(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPrepare($event);
}
}
public function onPreCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreCommit($event);
}
}
public function onCommit(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onCommit($event);
}
}
public function onPreRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreRollBack($event);
}
}
public function onRollBack(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onRollBack($event);
}
}
public function onPreBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreBeginTransaction($event);
}
}
public function onBeginTransaction(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onBeginTransaction($event);
}
}
public function onPreExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onPreExecute($event);
}
}
public function onExecute(Doctrine_Db_Event $event) {
foreach($this->listeners as $listener) {
foreach ($this->listeners as $listener) {
$listener->onExecute($event);
}
}
......
......@@ -62,7 +62,8 @@ class Doctrine_Db_Mock extends Doctrine_Db {
public function getAttribute($attribute)
{
if($attribute == PDO::ATTR_DRIVER_NAME)
if ($attribute == PDO::ATTR_DRIVER_NAME) {
return 'mock';
}
}
}
......@@ -58,14 +58,15 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
*/
public function __call($m, $a) {
// first argument should be an instance of Doctrine_Db_Event
if( ! ($a[0] instanceof Doctrine_Db_Event))
if ( ! ($a[0] instanceof Doctrine_Db_Event)) {
throw new Doctrine_Db_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Db_Event.");
}
// event methods should start with 'on'
if(substr($m, 0, 2) !== 'on')
if (substr($m, 0, 2) !== 'on') {
throw new Doctrine_Db_Profiler_Exception("Couldn't invoke listener $m.");
if(substr($m, 2, 3) === 'Pre' && in_array(strtolower(substr($m, 3)), $this->listeners)) {
}
if (substr($m, 2, 3) === 'Pre' && in_array(strtolower(substr($m, 3)), $this->listeners)) {
// pre-event listener found
$a[0]->start();
} else {
......@@ -76,7 +77,6 @@ class Doctrine_Db_Profiler implements Doctrine_Overloadable {
$this->events[] = $a[0];
}
/**
* Get the Doctrine_Db_Event object for the last query that was run, regardless if it has
* ended or not. If the event has not ended, it's end time will be Null.
......
......@@ -39,7 +39,6 @@ class Doctrine_Db_Profiler_Query {
*/
protected $queryType = 0;
protected $prepareTime;
/**
......@@ -54,7 +53,6 @@ class Doctrine_Db_Profiler_Query {
*/
protected $endedMicrotime;
/**
* Class constructor. A query is about to be started, save the query text ($query) and its
* type (one of the Zend_Db_Profiler::* constants).
......@@ -64,7 +62,7 @@ class Doctrine_Db_Profiler_Query {
*/
public function __construct($query, $prepareTime = null) {
$this->query = $query;
if($prepareTime !== null) {
if ($prepareTime !== null) {
$this->prepareTime = $prepareTime;
} else {
$this->startedMicrotime = microtime(true);
......@@ -96,7 +94,6 @@ class Doctrine_Db_Profiler_Query {
return ($this->endedMicrotime != null);
}
/**
* Get the original SQL text of the query.
*
......@@ -106,7 +103,6 @@ class Doctrine_Db_Profiler_Query {
return $this->query;
}
/**
* Get the type of this query (one of the Zend_Db_Profiler::* constants)
*
......@@ -129,4 +125,3 @@ class Doctrine_Db_Profiler_Query {
return ($this->prepareTime + ($this->endedMicrotime - $this->startedMicrotime));
}
}
......@@ -53,7 +53,7 @@ class Doctrine_Db_Statement extends PDOStatement {
return $this->queryString;
}
public function isExecuted($executed = null) {
if($executed === null)
if ($executed === null)
return $this->executed;
$this->executed = (bool) $executed;
......@@ -68,8 +68,6 @@ class Doctrine_Db_Statement extends PDOStatement {
$this->dbh->getListener()->onExecute($event);
return $this;
}
}
This diff is collapsed.
......@@ -52,7 +52,6 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
return $this->debug;
}
public function onLoad(Doctrine_Record $record) {
$this->debug[] = new Doctrine_DebugMessage($record,self::EVENT_LOAD);
}
......@@ -149,4 +148,3 @@ class Doctrine_EventListener_Debugger extends Doctrine_EventListener {
$this->debug[] = new Doctrine_DebugMessage($collection,self::EVENT_PRECOLLDELETE);
}
}
......@@ -10,4 +10,3 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_EventListener_Empty extends Doctrine_EventListener { }
......@@ -130,9 +130,9 @@ class Doctrine_Export extends Doctrine_Connection_Module {
if ( ! $name)
throw new Doctrine_Export_Exception('no valid table name specified');
if (empty($fields))
if (empty($fields)) {
throw new Doctrine_Export_Exception('no fields specified for table '.$name);
}
$queryFields = $this->getFieldDeclarationList($fields);
if (!empty($options['primary'])) {
......@@ -522,8 +522,8 @@ class Doctrine_Export extends Doctrine_Connection_Module {
public function getDeclaration($name, array $field) {
$default = '';
if(isset($field['default'])) {
if($field['default'] === '') {
if (isset($field['default'])) {
if ($field['default'] === '') {
$field['default'] = empty($field['notnull'])
? null : $this->valid_default_values[$field['type']];
if ($field['default'] === ''
......@@ -537,7 +537,7 @@ class Doctrine_Export extends Doctrine_Connection_Module {
}
/**
TODO: is this really needed for portability?
elseif(empty($field['notnull'])) {
elseif (empty($field['notnull'])) {
$default = ' DEFAULT NULL';
}
*/
......@@ -552,11 +552,11 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$method = 'get' . $field['type'] . 'Declaration';
if(method_exists($this->conn->dataDict, $method))
if (method_exists($this->conn->dataDict, $method)) {
return $this->conn->dataDict->$method($name, $field);
else
} else {
$dec = $this->conn->dataDict->getNativeDeclaration($field);
}
return $this->conn->quoteIdentifier($name, true) . ' ' . $dec . $charset . $default . $notnull . $collation;
}
/**
......@@ -594,39 +594,40 @@ class Doctrine_Export extends Doctrine_Connection_Module {
$conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, true);
foreach(get_declared_classes() as $name) {
foreach (get_declared_classes() as $name) {
$class = new ReflectionClass($name);
if($class->isSubclassOf($parent) && ! $class->isAbstract())
if ($class->isSubclassOf($parent) && ! $class->isAbstract()) {
$obj = new $class();
}
}
$conn->setAttribute(Doctrine::ATTR_CREATE_TABLES, $old);
}
public function export($record) {
if( ! $record instanceof Doctrine_Record)
if ( ! $record instanceof Doctrine_Record)
$record = new $record();
$table = $record->getTable();
$reporter = new Doctrine_Reporter();
if( ! Doctrine::isValidClassname($table->getComponentName())) {
if ( ! Doctrine::isValidClassname($table->getComponentName())) {
$reporter->add(E_WARNING, 'Badly named class.');
}
try {
$columns = array();
foreach($table->getColumns() as $name => $column) {
foreach ($table->getColumns() as $name => $column) {
$definition = $column[2];
$definition['type'] = $column[0];
$definition['length'] = $column[1];
if($definition['type'] == 'enum' && isset($definition['default']))
if ($definition['type'] == 'enum' && isset($definition['default'])) {
$definition['default'] = $table->enumIndex($name, $definition['default']);
if($definition['type'] == 'boolean' && isset($definition['default']))
}
if ($definition['type'] == 'boolean' && isset($definition['default'])) {
$definition['default'] = (int) $definition['default'];
}
$columns[$name] = $definition;
}
......
......@@ -158,8 +158,8 @@ class Doctrine_Export_Firebird extends Doctrine_Export {
parent::createTable($name, $fields, $options);
// TODO ? $this->_silentCommit();
foreach($fields as $field_name => $field) {
if( ! empty($field['autoincrement'])) {
foreach ($fields as $field_name => $field) {
if ( ! empty($field['autoincrement'])) {
//create PK constraint
$pk_definition = array(
'fields' => array($field_name => array()),
......
......@@ -209,7 +209,6 @@ class Doctrine_Export_Mssql extends Doctrine_Export {
return true;
}
$query = 'SET IDENTITY_INSERT $sequence_name ON ' .
'INSERT INTO $sequence_name (' . $seqcol_name . ') VALUES ( ' . $start . ')';
$res = $db->exec($query);
......
......@@ -90,29 +90,28 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return void
*/
public function createTable($name, array $fields, array $options = array()) {
if( ! $name)
if ( ! $name)
throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
if(empty($fields))
if (empty($fields)) {
throw new Doctrine_Export_Mysql_Exception('no fields specified for table "'.$name.'"');
}
$query_fields = $this->getFieldDeclarationList($fields);
if( ! empty($options['primary']))
if ( ! empty($options['primary'])) {
$query_fields.= ', PRIMARY KEY(' . implode(', ', array_values($options['primary'])) . ')';
}
$name = $this->conn->quoteIdentifier($name, true);
$query = 'CREATE TABLE ' . $name . ' (' . $query_fields . ')';
$optionStrings = array();
if(isset($options['comment']))
if (isset($options['comment'])) {
$optionStrings['comment'] = 'COMMENT = '.$this->dbh->quote($options['comment'], 'text');
if(isset($options['charset'])) {
}
if (isset($options['charset'])) {
$optionsSting['charset'] = 'DEFAULT CHARACTER SET '.$options['charset'];
if(isset($options['collate'])) {
if (isset($options['collate'])) {
$optionStrings['charset'].= ' COLLATE '.$options['collate'];
}
}
......@@ -223,7 +222,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
* @return boolean
*/
public function alterTable($name, array $changes, $check) {
if( ! $name)
if ( ! $name)
throw new Doctrine_Export_Mysql_Exception('no valid table name specified');
foreach ($changes as $changeName => $change) {
......@@ -239,17 +238,17 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if($check) {
if ($check) {
return true;
}
$query = '';
if( ! empty($changes['name'])) {
if ( ! empty($changes['name'])) {
$change_name = $this->conn->quoteIdentifier($changes['name'], true);
$query .= 'RENAME TO ' . $change_name;
}
if( ! empty($changes['add']) && is_array($changes['add'])) {
if ( ! empty($changes['add']) && is_array($changes['add'])) {
foreach ($changes['add'] as $field_name => $field) {
if ($query) {
$query.= ', ';
......@@ -258,7 +257,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if( ! empty($changes['remove']) && is_array($changes['remove'])) {
if ( ! empty($changes['remove']) && is_array($changes['remove'])) {
foreach ($changes['remove'] as $field_name => $field) {
if ($query) {
$query.= ', ';
......@@ -269,13 +268,13 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
$rename = array();
if( ! empty($changes['rename']) && is_array($changes['rename'])) {
if ( ! empty($changes['rename']) && is_array($changes['rename'])) {
foreach ($changes['rename'] as $field_name => $field) {
$rename[$field['name']] = $field_name;
}
}
if( ! empty($changes['change']) && is_array($changes['change'])) {
if ( ! empty($changes['change']) && is_array($changes['change'])) {
foreach ($changes['change'] as $field_name => $field) {
if ($query) {
$query.= ', ';
......@@ -291,7 +290,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if( ! empty($rename) && is_array($rename)) {
if ( ! empty($rename) && is_array($rename)) {
foreach ($rename as $rename_name => $renamed_field) {
if ($query) {
$query.= ', ';
......@@ -302,7 +301,7 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
}
}
if( ! $query) {
if ( ! $query) {
return MDB2_OK;
}
......@@ -329,7 +328,6 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
if ($start == 1)
return true;
$query = 'INSERT INTO ' . $sequenceName
. ' (' . $seqcol_name . ') VALUES (' . ($start-1) . ')';
......@@ -418,4 +416,4 @@ class Doctrine_Export_Mysql extends Doctrine_Export {
$this->conn->exec('DROP TABLE ' . $table);
}
}
?>
......@@ -45,7 +45,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE))
throw new Doctrine_Export_Oracle_Exception('database creation is only supported if the "emulate_database" attribute is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
$password = $this->conn->dsn['password'] ? $this->conn->dsn['password'] : $name;
......@@ -81,7 +80,6 @@ class Doctrine_Export_Oracle extends Doctrine_Export {
throw new Doctrine_Export_Oracle_Exception('database dropping is only supported if the
"emulate_database" option is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
return $this->conn->query('DROP USER ' . $username . ' CASCADE');
......@@ -174,7 +172,7 @@ END;
$query.= ' WHERE trigger_name='.$trigger_name_quoted.' OR trigger_name='.strtoupper($trigger_name_quoted);
$trigger = $this->conn->fetchOne($query);
if($trigger) {
if ($trigger) {
$trigger_name = $this->conn->quoteIdentifier($table . '_AI_PK', true);
$trigger_sql = 'DROP TRIGGER ' . $trigger_name;
......@@ -227,8 +225,8 @@ END;
$result = parent::createTable($name, $fields, $options);
foreach($fields as $field_name => $field) {
if(isset($field['autoincrement']) && $field['autoincrement']) {
foreach ($fields as $field_name => $field) {
if (isset($field['autoincrement']) && $field['autoincrement']) {
$result = $this->_makeAutoincrement($field_name, $name);
}
}
......
......@@ -182,9 +182,9 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
if (!empty($field['type'])) {
$server_info = $db->getServerVersion();
if (is_array($server_info) && $server_info['major'] < 8)
if (is_array($server_info) && $server_info['major'] < 8) {
throw new Doctrine_Export_Pgsql_Exception('changing column type for "'.$change_name.'\" requires PostgreSQL 8.0 or above');
}
$query = "ALTER $field_name TYPE ".$db->datatype->getTypeDeclaration($field['definition']);
$this->dbh->query("ALTER TABLE $name $query");
}
......@@ -214,4 +214,4 @@ class Doctrine_Export_Pgsql extends Doctrine_Export {
}
}
}
?>
......@@ -71,7 +71,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export {
$fields = array();
foreach ($definition['fields'] as $fieldName => $field) {
$fieldString = $fieldName;
if(isset($field['sorting'])) {
if (isset($field['sorting'])) {
switch ($field['sorting']) {
case 'ascending':
$fieldString .= ' ASC';
......
......@@ -284,9 +284,9 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
*/
private function basicMath($type, array $args) {
$elements = $this->getIdentifiers($args);
if (count($elements) < 1)
if (count($elements) < 1) {
return '';
}
if (count($elements) == 1) {
return $elements[0];
} else {
......@@ -539,15 +539,15 @@ class Doctrine_Expression extends Doctrine_Connection_Module {
* @return string logical expression
*/
public function in($column, $values) {
if( ! is_array($values))
if ( ! is_array($values)) {
$values = array($values);
}
$values = $this->getIdentifiers($values);
$column = $this->getIdentifier($column);
if(count($values) == 0)
if (count($values) == 0) {
throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.');
}
return $column . ' IN (' . implode(', ', $values) . ')';
}
/**
......
......@@ -56,9 +56,9 @@ class Doctrine_Expression_Mssql extends Doctrine_Expression {
* @return string to call a function to get a substring
*/
public function substring($value, $position, $length = null) {
if (!is_null($length))
if (!is_null($length)) {
return "SUBSTRING($value, $position, $length)";
}
return "SUBSTRING($value, $position, LEN($value) - $position + 1)";
}
/**
......
......@@ -57,7 +57,7 @@ class Doctrine_Expression_Oracle extends Doctrine_Expression {
* @return string SQL substring function with given parameters
*/
public function substring($value, $position, $length = null) {
if($length !== null)
if ($length !== null)
return "SUBSTR($value, $position, $length)";
return "SUBSTR($value, $position)";
......
......@@ -52,11 +52,12 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
public function md5($column) {
$column = $this->getIdentifier($column);
if ($this->version > 7)
if ($this->version > 7) {
return 'MD5(' . $column . ')';
else
} else {
return 'encode(digest(' . $column .', md5), hex)';
}
}
/**
* Returns part of a string.
......@@ -74,9 +75,10 @@ class Doctrine_Expression_Pgsql extends Doctrine_Expression {
if ($len === null) {
$len = $this->getIdentifier($len);
return 'SUBSTR(' . $value . ', ' . $from . ')';
} else
} else {
return 'SUBSTR(' . $value . ', ' . $from . ', ' . $len . ')';
}
}
/**
* Returns a series of strings concatinated
......
......@@ -143,9 +143,9 @@ class Doctrine_Expression_Sqlite extends Doctrine_Expression {
* @return string SQL substring function with given parameters
*/
public function substring($value, $position, $length = null) {
if($length !== null)
if ($length !== null) {
return 'SUBSTR(' . $value . ', ' . $position . ', ' . $length . ')';
}
return 'SUBSTR(' . $value . ', ' . $position . ', LENGTH(' . $value . '))';
}
}
......@@ -70,10 +70,10 @@ class Doctrine_Hook {
* @param Doctrine_Query $query the base query
*/
public function __construct($query) {
if(is_string($query)) {
if (is_string($query)) {
$this->query = new Doctrine_Query();
$this->query->parseQuery($query);
} elseif($query instanceof Doctrine_Query) {
} elseif ($query instanceof Doctrine_Query) {
$this->query = $query;
}
}
......@@ -95,21 +95,20 @@ class Doctrine_Hook {
* @return boolean whether or not the hooking was
*/
public function hookWhere($params) {
if( ! is_array($params))
if ( ! is_array($params)) {
return false;
foreach($params as $name => $value) {
}
foreach ($params as $name => $value) {
$e = explode('.', $name);
if(count($e) == 2) {
if (count($e) == 2) {
list($alias, $column) = $e;
$tableAlias = $this->query->getTableAlias($alias);
$table = $this->query->getTable($tableAlias);
if($def = $table->getDefinitionOf($column)) {
if(isset($this->typeParsers[$def[0]])) {
if ($def = $table->getDefinitionOf($column)) {
if (isset($this->typeParsers[$def[0]])) {
$name = $this->typeParsers[$def[0]];
$parser = new $name;
}
......@@ -134,27 +133,27 @@ class Doctrine_Hook {
* @return boolean whether or not the hooking was
*/
public function hookOrderby($params) {
if( ! is_array($params))
if ( ! is_array($params)) {
return false;
foreach($params as $name) {
}
foreach ($params as $name) {
$e = explode(' ', $name);
$order = 'ASC';
if(count($e) > 1) {
if (count($e) > 1) {
$order = ($e[1] == 'DESC') ? 'DESC' : 'ASC';
}
$e = explode('.', $e[0]);
if(count($e) == 2) {
if (count($e) == 2) {
list($alias, $column) = $e;
$tableAlias = $this->query->getTableAlias($alias);
$table = $this->query->getTable($tableAlias);
if($def = $table->getDefinitionOf($column)) {
if ($def = $table->getDefinitionOf($column)) {
$this->query->addOrderBy($alias . '.' . $column . ' ' . $order);
}
}
......
......@@ -46,14 +46,14 @@ class Doctrine_Hook_Integer extends Doctrine_Hook_Parser_Complex {
public function parseSingle($alias, $field, $value) {
$e = explode(' ', $value);
foreach($e as $v) {
foreach ($e as $v) {
$v = trim($v);
$e2 = explode('-', $v);
$name = $alias. '.' . $field;
if(count($e2) == 1) {
if (count($e2) == 1) {
// one '-' found
$a[] = $name . ' = ?';
......
......@@ -57,9 +57,9 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
public function parseClause($alias, $field, $value) {
$parts = Doctrine_Query::bracketExplode($value, ' AND ', '(', ')');
if(count($parts) > 1) {
if (count($parts) > 1) {
$ret = array();
foreach($parts as $part) {
foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parseSingle($alias, $field, $part);
}
......@@ -67,16 +67,16 @@ abstract class Doctrine_Hook_Parser_Complex extends Doctrine_Hook_Parser {
$r = implode(' AND ', $ret);
} else {
$parts = Doctrine_Query::bracketExplode($value, ' OR ', '(', ')');
if(count($parts) > 1) {
if (count($parts) > 1) {
$ret = array();
foreach($parts as $part) {
foreach ($parts as $part) {
$part = Doctrine_Query::bracketTrim($part, '(', ')');
$ret[] = $this->parseClause($alias, $field, $part);
}
$r = implode(' OR ', $ret);
} else {
if(substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') {
if (substr($parts[0],0,1) == '(' && substr($parts[0],-1) == ')') {
return $this->parseClause(substr($parts[0],1,-1));
} else {
$ret = $this->parseSingle($alias, $field, $parts[0]);
......
......@@ -46,7 +46,7 @@ class Doctrine_Hook_WordLike extends Doctrine_Hook_Parser_Complex {
public function parseSingle($alias, $field, $value) {
$e2 = explode(' ',$value);
foreach($e2 as $v) {
foreach ($e2 as $v) {
$v = trim($v);
$a[] = $alias. '.' . $field . ' LIKE ?';
$this->params[] = $v . '%';
......
This diff is collapsed.
......@@ -42,12 +42,12 @@ class Doctrine_Hydrate_Alias {
}
public function generateNewAlias($alias) {
if(isset($this->shortAliases[$alias])) {
if (isset($this->shortAliases[$alias])) {
// generate a new alias
$name = substr($alias, 0, 1);
$i = ((int) substr($alias, 1));
if($i == 0)
if ($i == 0)
$i = 1;
$newIndex = ($this->shortAliasIndexes[$name] + $i);
......@@ -62,9 +62,9 @@ class Doctrine_Hydrate_Alias {
return (isset($this->shortAliases[$tableName]));
}
public function getShortAliasIndex($alias) {
if( ! isset($this->shortAliasIndexes[$alias]))
if ( ! isset($this->shortAliasIndexes[$alias])) {
return 0;
}
return $this->shortAliasIndexes[$alias];
}
public function generateShortAlias($tableName) {
......@@ -72,10 +72,10 @@ class Doctrine_Hydrate_Alias {
$alias = $char;
if( ! isset($this->shortAliasIndexes[$alias]))
if ( ! isset($this->shortAliasIndexes[$alias])) {
$this->shortAliasIndexes[$alias] = 1;
while(isset($this->shortAliases[$alias])) {
}
while (isset($this->shortAliases[$alias])) {
$alias = $char . ++$this->shortAliasIndexes[$alias];
}
$this->shortAliases[$alias] = $tableName;
......@@ -86,9 +86,9 @@ class Doctrine_Hydrate_Alias {
public function getShortAlias($tableName) {
$alias = array_search($tableName, $this->shortAliases);
if($alias !== false)
if ($alias !== false) {
return $alias;
}
return $this->generateShortAlias($tableName);
}
}
......@@ -47,4 +47,3 @@ class Doctrine_Identifier {
*/
const COMPOSITE = 4;
}
......@@ -44,7 +44,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
public function listDatabases()
{
if( ! isset($this->sql['listDatabases'])) {
if ( ! isset($this->sql['listDatabases'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
......@@ -57,7 +57,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
public function listFunctions()
{
if( ! isset($this->sql['listFunctions'])) {
if ( ! isset($this->sql['listFunctions'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
......@@ -81,7 +81,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
public function listSequences($database = null)
{
if( ! isset($this->sql['listSequences'])) {
if ( ! isset($this->sql['listSequences'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
......@@ -154,7 +154,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
public function listUsers()
{
if( ! isset($this->sql['listUsers'])) {
if ( ! isset($this->sql['listUsers'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
......@@ -168,7 +168,7 @@ class Doctrine_Import extends Doctrine_Connection_Module
*/
public function listViews($database = null)
{
if( ! isset($this->sql['listViews'])) {
if ( ! isset($this->sql['listViews'])) {
throw new Doctrine_Import_Exception(__FUNCTION__ . ' not supported by this driver.');
}
......
......@@ -42,13 +42,14 @@ class Doctrine_Import_Builder {
private static $tpl;
public function __construct() {
if( ! isset(self::$tpl))
if ( ! isset(self::$tpl)) {
self::$tpl = file_get_contents(Doctrine::getPath()
. DIRECTORY_SEPARATOR . 'Doctrine'
. DIRECTORY_SEPARATOR . 'Import'
. DIRECTORY_SEPARATOR . 'Builder'
. DIRECTORY_SEPARATOR . 'Record.tpl');
}
}
/**
*
......@@ -57,7 +58,7 @@ class Doctrine_Import_Builder {
* @access public
*/
public function setTargetPath($path) {
if( ! file_exists($path)) {
if ( ! file_exists($path)) {
mkdir($path, 0777);
}
......@@ -79,14 +80,13 @@ class Doctrine_Import_Builder {
return $this->suffix;
}
public function buildRecord(Doctrine_Schema_Table $table) {
if (empty($this->path))
if (empty($this->path)) {
throw new Doctrine_Import_Builder_Exception('No build target directory set.');
if (is_writable($this->path) === false)
}
if (is_writable($this->path) === false) {
throw new Doctrine_Import_Builder_Exception('Build target directory ' . $this->path . ' is not writable.');
}
$created = date('l dS \of F Y h:i:s A');
$className = Doctrine::classify($table->get('name'));
$fileName = $this->path . DIRECTORY_SEPARATOR . $className . $this->suffix;
......@@ -94,41 +94,42 @@ class Doctrine_Import_Builder {
$i = 0;
foreach($table as $name => $column) {
foreach ($table as $name => $column) {
$columns[$i] = ' $this->hasColumn(\'' . $column['name'] . '\', \'' . $column['type'] . '\'';
if($column['length'])
if ($column['length']) {
$columns[$i] .= ', ' . $column['length'];
else
} else {
$columns[$i] .= ', null';
}
$a = array();
if($column['default']) {
if ($column['default']) {
$a[] = '\'default\' => ' . var_export($column['default'], true);
}
if($column['notnull']) {
if ($column['notnull']) {
$a[] = '\'notnull\' => true';
}
if($column['primary']) {
if ($column['primary']) {
$a[] = '\'primary\' => true';
}
if($column['autoinc']) {
if ($column['autoinc']) {
$a[] = '\'autoincrement\' => true';
}
if($column['unique']) {
if ($column['unique']) {
$a[] = '\'unique\' => true';
}
if( ! empty($a))
if ( ! empty($a)) {
$columns[$i] .= ', ' . 'array(' . implode(',
', $a) . ')';
}
$columns[$i] .= ');';
if($i < (count($table) - 1))
if ($i < (count($table) - 1)) {
$columns[$i] .= '
';
}
$i++;
}
......@@ -136,8 +137,7 @@ class Doctrine_Import_Builder {
$bytes = file_put_contents($fileName, $content);
if($bytes === false)
if ($bytes === false)
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName);
}
/**
......@@ -147,8 +147,8 @@ class Doctrine_Import_Builder {
* @return void
*/
public function build(Doctrine_Schema_Object $schema) {
foreach($schema->getDatabases() as $database){
foreach($database->getTables() as $table){
foreach ($schema->getDatabases() as $database){
foreach ($database->getTables() as $table){
$this->buildRecord($table);
}
}
......
......@@ -109,7 +109,7 @@ class Doctrine_Import_Firebird extends Doctrine_Import {
WHERE RDB$SYSTEM_FLAG IS NULL
OR RDB$SYSTEM_FLAG = 0';
if( ! is_null($table)) {
if ( ! is_null($table)) {
$table = $db->quote(strtoupper($table), 'text');
$query .= 'WHERE UPPER(RDB$RELATION_NAME) = ' . $table;
}
......
......@@ -143,7 +143,7 @@ class Doctrine_Import_Mysql extends Doctrine_Import {
$description = array();
foreach ($result as $key => $val2) {
$val = array();
foreach(array_keys($val2) as $valKey){ // lowercase the key names
foreach (array_keys($val2) as $valKey){ // lowercase the key names
$val[strtolower($valKey)] = $val2[$valKey];
}
$description = array(
......
......@@ -46,7 +46,6 @@ abstract class Doctrine_Import_Reader
/*** Attributes: ***/
/**
*
* @return Doctrine_Schema
......@@ -55,9 +54,4 @@ abstract class Doctrine_Import_Reader
*/
abstract public function read( );
} // end of Doctrine_Import_Reader
......@@ -52,7 +52,6 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
*/
private $pdo;
/**
*
* @param object pdo * @return
......@@ -62,7 +61,6 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
} // end of member function setPdo
/**
*
* @return Doctrine_Schema
......@@ -80,16 +78,16 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
$db->set("name",$dbName);
$tableNames = $dataDict->listTables();
foreach($tableNames as $tableName){
foreach ($tableNames as $tableName){
$table = new Doctrine_Schema_Table();
$table->set("name",$tableName);
$tableColumns = $dataDict->listTableColumns($tableName);
foreach($tableColumns as $tableColumn){
foreach ($tableColumns as $tableColumn){
$table->addColumn($tableColumn);
}
$db->addTable($table);
if ($fks = $dataDict->listTableConstraints($tableName)){
foreach($fks as $fk){
foreach ($fks as $fk){
$relation = new Doctrine_Schema_Relation();
$relation->setRelationBetween($fk['referencingColumn'],$fk['referencedTable'],$fk['referencedColumn']);
$table->setRelation($relation);
......@@ -100,7 +98,4 @@ class Doctrine_Import_Reader_Db extends Doctrine_Import_Reader
return $schema;
}
} // end of Doctrine_Import_Reader_Db
......@@ -44,10 +44,4 @@ class Doctrine_Import_Reader_Exception
/*** Attributes: ***/
} // end of Doctrine_Import_Reader_Exception
......@@ -50,7 +50,6 @@ class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader
*/
private $xml;
/**
*
* @param string xml * @return
......@@ -62,7 +61,4 @@ class Doctrine_Import_Reader_Xml_Propel extends Doctrine_Import_Reader
public function read() { }
} // end of Doctrine_Import_Reader_Xml_Propel
......@@ -136,7 +136,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$description = array();
$columns = array();
foreach($result as $key => $val) {
foreach ($result as $key => $val) {
$description = array(
'name' => $val['name'],
'type' => $val['type'],
......@@ -159,7 +159,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$result = $this->dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$indexes = array();
foreach($result as $key => $val) {
foreach ($result as $key => $val) {
}
}
......@@ -179,7 +179,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import {
$data = $stmt->fetchAll(PDO::FETCH_COLUMN);
foreach($data as $table) {
foreach ($data as $table) {
$tables[] = new Doctrine_Schema_Table(array('name' => $table));
}
return $tables;
......
......@@ -36,7 +36,7 @@ class Doctrine_Lib {
* @return string string representation of given state
*/
public static function getRecordStateAsString($state) {
switch($state):
switch ($state) {
case Doctrine_Record::STATE_PROXY:
return "proxy";
break;
......@@ -52,7 +52,7 @@ class Doctrine_Lib {
case Doctrine_Record::STATE_TCLEAN:
return "transient clean";
break;
endswitch;
};
}
/**
* returns a string representation of Doctrine_Record object
......@@ -75,7 +75,7 @@ class Doctrine_Lib {
* @param integer $state connection state
*/
public static function getConnectionStateAsString($state) {
switch($state):
switch ($state) {
case Doctrine_Transaction::STATE_SLEEP:
return "open";
break;
......@@ -85,7 +85,7 @@ class Doctrine_Lib {
case Doctrine_Transaction::STATE_ACTIVE:
return "active";
break;
endswitch;
};
}
/**
* returns a string representation of Doctrine_Connection object
......@@ -100,17 +100,18 @@ class Doctrine_Lib {
$r[] = "Table in memory : ".$connection->count();
$queries = false;
if($connection->getDBH() instanceof Doctrine_Db) {
if ($connection->getDBH() instanceof Doctrine_Db) {
$handler = "Doctrine Database Handler";
$queries = count($connection->getDBH()->getQueries());
$sum = array_sum($connection->getDBH()->getExecTimes());
} elseif($connection->getDBH() instanceof PDO) {
} elseif ($connection->getDBH() instanceof PDO) {
$handler = "PHP Native PDO Driver";
} else
} else {
$handler = "Unknown Database Handler";
}
$r[] = "DB Handler : ".$handler;
if($queries) {
if ($queries) {
$r[] = "Executed Queries : ".$queries;
$r[] = "Sum of Exec Times : ".$sum;
}
......@@ -162,11 +163,10 @@ class Doctrine_Lib {
$r[] = "<pre>";
$r[] = get_class($collection);
foreach($collection as $key => $record) {
foreach ($collection as $key => $record) {
$r[] = "Key : ".$key." ID : ".$record->obtainIdentifier();
}
$r[] = "</pre>";
return implode("\n",$r);
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment