Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Using the new trait and simplifying code
  • Loading branch information
lorenzo committed Mar 26, 2016
1 parent a5e410c commit 770016d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Database/Expression/BetweenExpression.php
Expand Up @@ -15,7 +15,7 @@
namespace Cake\Database\Expression;

use Cake\Database\ExpressionInterface;
use Cake\Database\Type\TypeExpressionCasterTrait;
use Cake\Database\Type\ExpressionTypeCasterTrait;
use Cake\Database\ValueBinder;

/**
Expand All @@ -27,7 +27,7 @@ class BetweenExpression implements ExpressionInterface, FieldInterface
{

use FieldTrait;
use TypeExpressionCasterTrait;
use ExpressionTypeCasterTrait;

/**
* The first value in the expression
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Expression/CaseExpression.php
Expand Up @@ -15,7 +15,7 @@
namespace Cake\Database\Expression;

use Cake\Database\ExpressionInterface;
use Cake\Database\Type\TypeExpressionCasterTrait;
use Cake\Database\Type\ExpressionTypeCasterTrait;
use Cake\Database\ValueBinder;

/**
Expand All @@ -26,7 +26,7 @@
class CaseExpression implements ExpressionInterface
{

use TypeExpressionCasterTrait;
use ExpressionTypeCasterTrait;

/**
* A list of strings or other expression objects that represent the conditions of
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Expression/Comparison.php
Expand Up @@ -16,7 +16,7 @@

use Cake\Database\Exception as DatabaseException;
use Cake\Database\ExpressionInterface;
use Cake\Database\Type\TypeExpressionCasterTrait;
use Cake\Database\Type\ExpressionTypeCasterTrait;
use Cake\Database\ValueBinder;

/**
Expand All @@ -30,7 +30,7 @@ class Comparison implements ExpressionInterface, FieldInterface
{

use FieldTrait;
use TypeExpressionCasterTrait;
use ExpressionTypeCasterTrait;

/**
* The value to be used in the right hand side of the operation
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Expression/FunctionExpression.php
Expand Up @@ -15,7 +15,7 @@
namespace Cake\Database\Expression;

use Cake\Database\ExpressionInterface;
use Cake\Database\Type\TypeExpressionCasterTrait;
use Cake\Database\Type\ExpressionTypeCasterTrait;
use Cake\Database\TypedResultInterface;
use Cake\Database\TypedResultTrait;
use Cake\Database\ValueBinder;
Expand All @@ -32,7 +32,7 @@ class FunctionExpression extends QueryExpression implements TypedResultInterface
{

use TypedResultTrait;
use TypeExpressionCasterTrait;
use ExpressionTypeCasterTrait;

/**
* The name of the function to be constructed when generating the SQL string
Expand Down
8 changes: 2 additions & 6 deletions src/Database/Type/ExpressionTypeCasterTrait.php
Expand Up @@ -22,7 +22,7 @@
* if the type they should be converted to implements ExpressionTypeInterface
*
*/
trait TypeExpressionCasterTrait
trait ExpressionTypeCasterTrait
{

/**
Expand Down Expand Up @@ -50,11 +50,7 @@ protected function _castToExpression($value, $type)
$multi = $type !== $baseType;

if ($multi) {
$result = [];
foreach ($value as $k => $v) {
$result[$k] = $converter->toExpression($v);
}
return $result;
return array_map([$converter, 'toExpression'], $value);
}

return $converter->toExpression($value);
Expand Down

0 comments on commit 770016d

Please sign in to comment.