Skip to content
Permalink
Browse files

Typehint against the interface.

Typehinting against an implementation is generally not a good idea.
  • Loading branch information...
markstory committed Jun 17, 2015
1 parent 7bb51c4 commit 50816e2af9b752a2d2941906606800b8580f5943
Showing with 10 additions and 9 deletions.
  1. +2 −1 src/ORM/ResultSet.php
  2. +8 −8 src/View/Form/EntityContext.php
@@ -19,6 +19,7 @@
use Cake\Database\Exception;
use Cake\Database\Type;
use Cake\Datasource\ResultSetInterface;
use Cake\Datasource\EntityInterface;
use SplFixedArray;
/**
@@ -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);
}
@@ -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;
@@ -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();
@@ -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;
@@ -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;
@@ -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;
@@ -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) {
@@ -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();
}
@@ -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 [];

0 comments on commit 50816e2

Please sign in to comment.
You can’t perform that action at this time.