Navigation Menu

Skip to content

Commit

Permalink
Typehint against the interface.
Browse files Browse the repository at this point in the history
Typehinting against an implementation is generally not a good idea.
  • Loading branch information
markstory committed Jun 17, 2015
1 parent 7bb51c4 commit 50816e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/ORM/ResultSet.php
Expand Up @@ -19,6 +19,7 @@
use Cake\Database\Exception;
use Cake\Database\Type;
use Cake\Datasource\ResultSetInterface;
use Cake\Datasource\EntityInterface;
use SplFixedArray;

/**
Expand Down Expand Up @@ -589,7 +590,7 @@ protected function _groupResult($row)
if (isset($results[$defaultAlias])) {
$results = $results[$defaultAlias];
}
if ($this->_hydrate && !($results instanceof Entity)) {
if ($this->_hydrate && !($results instanceof EntityInterface)) {
$results = new $this->_entityClass($results, $options);
}

Expand Down
16 changes: 8 additions & 8 deletions src/View/Form/EntityContext.php
Expand Up @@ -15,8 +15,8 @@
namespace Cake\View\Form;

use Cake\Collection\Collection;
use Cake\Datasource\EntityInterface;
use Cake\Network\Request;
use Cake\ORM\Entity;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
use Cake\View\Form\ContextInterface;
Expand Down Expand Up @@ -123,7 +123,7 @@ protected function _prepare()
if (is_array($entity) || $entity instanceof Traversable) {
$entity = (new Collection($entity))->first();
}
$isEntity = $entity instanceof Entity;
$isEntity = $entity instanceof EntityInterface;

if ($isEntity) {
$table = $entity->source();
Expand Down Expand Up @@ -190,7 +190,7 @@ public function isCreate()
if (is_array($entity) || $entity instanceof Traversable) {
$entity = (new Collection($entity))->first();
}
if ($entity instanceof Entity) {
if ($entity instanceof EntityInterface) {
return $entity->isNew() !== false;
}
return true;
Expand Down Expand Up @@ -220,7 +220,7 @@ public function val($field)
return $this->_extractMultiple($entity, $parts);
}

if ($entity instanceof Entity) {
if ($entity instanceof EntityInterface) {
return $entity->get(array_pop($parts));
}
return null;
Expand Down Expand Up @@ -290,7 +290,7 @@ public function entity($path = null)
$isTraversable = (
is_array($next) ||
$next instanceof Traversable ||
$next instanceof Entity
$next instanceof EntityInterface
);
if ($isLast || !$isTraversable) {
return $entity;
Expand All @@ -315,7 +315,7 @@ protected function _getProp($target, $field)
if (is_array($target) && isset($target[$field])) {
return $target[$field];
}
if ($target instanceof Entity) {
if ($target instanceof EntityInterface) {
return $target->get($field);
}
if ($target instanceof Traversable) {
Expand All @@ -340,7 +340,7 @@ public function isRequired($field)
$entity = $this->entity($parts);

$isNew = true;
if ($entity instanceof Entity) {
if ($entity instanceof EntityInterface) {
$isNew = $entity->isNew();
}

Expand Down Expand Up @@ -496,7 +496,7 @@ public function error($field)
$parts = explode('.', $field);
$entity = $this->entity($parts);

if ($entity instanceof Entity) {
if ($entity instanceof EntityInterface) {
return $entity->errors(array_pop($parts));
}
return [];
Expand Down

0 comments on commit 50816e2

Please sign in to comment.