Skip to content

Commit

Permalink
[zendframework#6446] CS + Review
Browse files Browse the repository at this point in the history
- Formatted several conditionals to 1 per line
- Formatted several arrays to 1 per line
- Removed unnecessary whitespace
- Slight logic modifications for readability, consistency
- Ensured docblocks are correct
  • Loading branch information
weierophinney committed Jul 21, 2014
1 parent 4dcf3ef commit 277fbca
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 42 deletions.
36 changes: 16 additions & 20 deletions library/Zend/Db/Adapter/Driver/IbmDb2/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function __construct($connectionParameters = null)
public function setDriver(IbmDb2 $driver)
{
$this->driver = $driver;

return $this;
}

Expand All @@ -95,7 +94,6 @@ public function setDriver(IbmDb2 $driver)
public function setProfiler(Profiler\ProfilerInterface $profiler)
{
$this->profiler = $profiler;

return $this;
}

Expand All @@ -114,7 +112,6 @@ public function getProfiler()
public function setConnectionParameters(array $connectionParameters)
{
$this->connectionParameters = $connectionParameters;

return $this;
}

Expand All @@ -136,7 +133,6 @@ public function setResource($resource)
throw new Exception\InvalidArgumentException('The resource provided must be of type "DB2 Connection"');
}
$this->resource = $resource;

return $this;
}

Expand All @@ -152,7 +148,6 @@ public function getCurrentSchema()
}

$info = db2_server_info($this->resource);

return (isset($info->DB_NAME) ? $info->DB_NAME : '');
}

Expand All @@ -169,7 +164,7 @@ public function getResource()
/**
* Connect
*
* @return ConnectionInterface
* @return self
*/
public function connect()
{
Expand All @@ -196,12 +191,9 @@ public function connect()
$password = $findParameterValue(array('password', 'pwd', 'PWD'));
$isPersistent = $findParameterValue(array('persistent', 'PERSISTENT', 'Persistent'));
$options = (isset($p['driver_options']) ? $p['driver_options'] : array());
$connect = ((bool) $isPersistent) ? 'db2_pconnect' : 'db2_connect';

if ($isPersistent) {
$this->resource = db2_pconnect($database, $username, $password, $options);
} else {
$this->resource = db2_connect($database, $username, $password, $options);
}
$this->resource = $connect($database, $username, $password, $options);

if ($this->resource === false) {
throw new Exception\RuntimeException(sprintf(
Expand Down Expand Up @@ -250,13 +242,14 @@ public function beginTransaction()
'DB2 transactions are not enabled, you need to set the ibm_db2.i5_allow_commit=1 in your php.ini'
);
}

if (!$this->isConnected()) {
$this->connect();
}

$this->prevAutocommit = db2_autocommit($this->resource);
db2_autocommit($this->resource, DB2_AUTOCOMMIT_OFF);
$this->inTransaction = true;

return $this;
}

Expand All @@ -280,14 +273,16 @@ public function commit()
if (!$this->isConnected()) {
$this->connect();
}

if (!db2_commit($this->resource)) {
throw new Exception\RuntimeException("The commit has not been successful");
}

if ($this->prevAutocommit) {
db2_autocommit($this->resource, $this->prevAutocommit);
}
$this->inTransaction = false;

$this->inTransaction = false;
return $this;
}

Expand All @@ -305,14 +300,16 @@ public function rollback()
if (!$this->inTransaction) {
throw new Exception\RuntimeException('Must call beginTransaction() before you can rollback.');
}

if (!db2_rollback($this->resource)) {
throw new Exception\RuntimeException('The rollback has not been successful');
}

if ($this->prevAutocommit) {
db2_autocommit($this->resource, $this->prevAutocommit);
}
$this->inTransaction = false;

$this->inTransaction = false;
return $this;
}

Expand Down Expand Up @@ -345,9 +342,7 @@ public function execute($sql)
throw new Exception\InvalidQueryException(db2_stmt_errormsg());
}

$resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource);

return $resultPrototype;
return $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource);
}

/**
Expand All @@ -364,14 +359,15 @@ public function getLastGeneratedValue($name = null)
/**
* Determine if the OS is OS400 (AS400, IBM i)
*
* @return boolean
* @return bool
*/
protected function isI5()
{
if (!isset($this->i5)) {
$this->i5 = php_uname('s') == 'OS400' ? true : false;
if (isset($this->i5)) {
return $this->i5;
}

$this->i5 = php_uname('s') == 'OS400' ? true : false;
return $this->i5;
}
}
5 changes: 3 additions & 2 deletions library/Zend/Db/Sql/Platform/IbmDb2/IbmDb2.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

class IbmDb2 extends AbstractPlatform
{

/**
* @param SelectDecorator $selectDecorator
*/
public function __construct(SelectDecorator $selectDecorator = null)
{
$this->setTypeDecorator('Zend\Db\Sql\Select', ($selectDecorator) ?: new SelectDecorator());
}

}
45 changes: 26 additions & 19 deletions library/Zend/Db/Sql/Platform/IbmDb2/SelectDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ class SelectDecorator extends Select implements PlatformDecoratorInterface
protected $select = null;

/**
* @return the $isSelectContainDistinct
*/
* @return bool
*/
public function getIsSelectContainDistinct()
{
return $this->isSelectContainDistinct;
}

/**
* @param boolean $isSelectContainDistinct
*/
* @param boolean $isSelectContainDistinct
*/
public function setIsSelectContainDistinct($isSelectContainDistinct)
{
$this->isSelectContainDistinct = $isSelectContainDistinct;
Expand All @@ -54,7 +54,7 @@ public function setSubject($select)
}

/**
* @see \Zend\Db\Sql\Select::renderTable
* @see Select::renderTable
*/
protected function renderTable($table, $alias = null)
{
Expand Down Expand Up @@ -101,25 +101,27 @@ public function getSqlString(PlatformInterface $platform = null)
* @param PlatformInterface $platform
* @param DriverInterface $driver
* @param ParameterContainer $parameterContainer
* @param $sqls
* @param $parameters
* @return null
* @param array $sqls
* @param array $parameters
*/

protected function processLimitOffset(PlatformInterface $platform, DriverInterface $driver = null, ParameterContainer $parameterContainer = null, &$sqls, &$parameters)
{
if ($this->limit === null && $this->offset === null) {
return null;
return;
}

$selectParameters = $parameters[self::SELECT];

$starSuffix = $platform->getIdentifierSeparator() . self::SQL_STAR;
foreach ($selectParameters[0] as $i => $columnParameters) {
if ($columnParameters[0] == self::SQL_STAR || (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR) || strpos($columnParameters[0], $starSuffix)) {
if ($columnParameters[0] == self::SQL_STAR
|| (isset($columnParameters[1]) && $columnParameters[1] == self::SQL_STAR)
|| strpos($columnParameters[0], $starSuffix)
) {
$selectParameters[0] = array(array(self::SQL_STAR));
break;
}

if (isset($columnParameters[1])) {
array_shift($columnParameters);
$selectParameters[0][$i] = $columnParameters;
Expand All @@ -128,40 +130,44 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa

// first, produce column list without compound names (using the AS portion only)
array_unshift($sqls, $this->createSqlFromSpecificationAndParameters(
array('SELECT %1$s FROM (' => current($this->specifications[self::SELECT])),
$selectParameters
array('SELECT %1$s FROM (' => current($this->specifications[self::SELECT])),
$selectParameters
));

if (preg_match('/DISTINCT/i',$sqls[0],$match)) {
if (preg_match('/DISTINCT/i', $sqls[0])) {
$this->setIsSelectContainDistinct(true);
}

if ($parameterContainer) {
// create bottom part of query, with offset and limit using row_number
$limitParamName = $driver->formatParameterName('limit');
$offsetParamName = $driver->formatParameterName('offset');
$limitParamName = $driver->formatParameterName('limit');
$offsetParamName = $driver->formatParameterName('offset');
$offsetForSumParamName = $driver->formatParameterName('offsetForSum');

array_push($sqls, sprintf(
") AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN %s AND %s",
$offsetParamName, $limitParamName
$offsetParamName,
$limitParamName
));

if ((int) $this->offset > 0) {
$parameterContainer->offsetSet('offset', (int) $this->offset + 1);
} else {
$parameterContainer->offsetSet('offset', (int) $this->offset);
}

$parameterContainer->offsetSet('limit', (int) $this->limit + (int) $this->offset);
} else {
if ( (int) $this->offset > 0) {
if ((int) $this->offset > 0) {
$offset = (int) $this->offset + 1;
} else {
$offset = (int) $this->offset;
}

array_push($sqls, sprintf(
") AS ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION WHERE ZEND_IBMDB2_SERVER_LIMIT_OFFSET_EMULATION.ZEND_DB_ROWNUM BETWEEN %d AND %d",
$offset, (int) $this->limit + (int) $this->offset
$offset,
(int) $this->limit + (int) $this->offset
));
}

Expand All @@ -178,6 +184,7 @@ protected function processLimitOffset(PlatformInterface $platform, DriverInterfa
} else {
$parameters[self::SELECT][0][] = array('ROW_NUMBER() OVER (' . $orderBy . ')', 'ZEND_DB_ROWNUM');
}

$sqls[self::SELECT] = $this->createSqlFromSpecificationAndParameters(
$this->specifications[self::SELECT],
$parameters[self::SELECT]
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Db/Sql/Platform/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class Platform extends AbstractPlatform
{

/**
* @var AdapterInterface
*/
Expand All @@ -37,6 +36,7 @@ public function __construct(AdapterInterface $adapter)
$this->decorators = $platform->decorators;
break;
case 'ibm db2':
case 'ibm_db2':
case 'ibmdb2':
$platform = new IbmDb2\IbmDb2();
$this->decorators = $platform->decorators;
Expand Down

0 comments on commit 277fbca

Please sign in to comment.