Replaced all is_a() calls with instanceof operator

This commit is contained in:
Bryan Crowe 2013-09-24 21:08:06 -04:00
parent b883202890
commit 7d7954ce18
6 changed files with 22 additions and 22 deletions

View file

@ -861,7 +861,7 @@ class DboSource extends DataSource {
* @return boolean True if the result is valid else false * @return boolean True if the result is valid else false
*/ */
public function hasResult() { public function hasResult() {
return is_a($this->_result, 'PDOStatement'); return $this->_result instanceof PDOStatement;
} }
/** /**

View file

@ -137,7 +137,7 @@ class SchemaShellTest extends CakeTestCase {
public function testStartup() { public function testStartup() {
$this->Shell->startup(); $this->Shell->startup();
$this->assertTrue(isset($this->Shell->Schema)); $this->assertTrue(isset($this->Shell->Schema));
$this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema')); $this->assertTrue($this->Shell->Schema instanceof CakeSchema);
$this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $this->Shell->Schema->name); $this->assertEquals(Inflector::camelize(Inflector::slug(APP_DIR)), $this->Shell->Schema->name);
$this->assertEquals('schema.php', $this->Shell->Schema->file); $this->assertEquals('schema.php', $this->Shell->Schema->file);

View file

@ -482,8 +482,8 @@ class ControllerTest extends CakeTestCase {
$Controller = new Controller($request); $Controller = new Controller($request);
$Controller->uses = array('ControllerPost', 'ControllerComment'); $Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->constructClasses(); $Controller->constructClasses();
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost')); $this->assertTrue($Controller->ControllerPost instanceof ControllerPost);
$this->assertTrue(is_a($Controller->ControllerComment, 'ControllerComment')); $this->assertTrue($Controller->ControllerComment instanceof ControllerComment);
$this->assertEquals('Comment', $Controller->ControllerComment->name); $this->assertEquals('Comment', $Controller->ControllerComment->name);
@ -497,7 +497,7 @@ class ControllerTest extends CakeTestCase {
$Controller->constructClasses(); $Controller->constructClasses();
$this->assertTrue(isset($Controller->TestPluginPost)); $this->assertTrue(isset($Controller->TestPluginPost));
$this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost')); $this->assertTrue($Controller->TestPluginPost instanceof TestPluginPost);
} }
/** /**

View file

@ -2354,7 +2354,7 @@ class RouterTest extends CakeTestCase {
array('controller' => 'posts', 'action' => 'view'), array('controller' => 'posts', 'action' => 'view'),
array('routeClass' => 'MockConnectedRoute', 'slug' => '[a-z_-]+') array('routeClass' => 'MockConnectedRoute', 'slug' => '[a-z_-]+')
); );
$this->assertTrue(is_a($routes[0], 'MockConnectedRoute'), 'Incorrect class used. %s'); $this->assertTrue($routes[0] instanceof MockConnectedRoute, 'Incorrect class used. %s');
$expected = array('controller' => 'posts', 'action' => 'view', 'slug' => 'test'); $expected = array('controller' => 'posts', 'action' => 'view', 'slug' => 'test');
$routes[0]->expects($this->any()) $routes[0]->expects($this->any())
->method('parse') ->method('parse')

View file

@ -136,7 +136,7 @@ class ClassRegistryTest extends CakeTestCase {
*/ */
public function testAddModel() { public function testAddModel() {
$Tag = ClassRegistry::init('RegisterArticleTag'); $Tag = ClassRegistry::init('RegisterArticleTag');
$this->assertTrue(is_a($Tag, 'RegisterArticleTag')); $this->assertTrue($Tag instanceof RegisterArticleTag);
$TagCopy = ClassRegistry::isKeySet('RegisterArticleTag'); $TagCopy = ClassRegistry::isKeySet('RegisterArticleTag');
$this->assertTrue($TagCopy); $this->assertTrue($TagCopy);
@ -145,11 +145,11 @@ class ClassRegistryTest extends CakeTestCase {
$TagCopy = ClassRegistry::getObject('RegisterArticleTag'); $TagCopy = ClassRegistry::getObject('RegisterArticleTag');
$this->assertTrue(is_a($TagCopy, 'RegisterArticleTag')); $this->assertTrue($TagCopy instanceof RegisterArticleTag);
$this->assertSame($Tag, $TagCopy); $this->assertSame($Tag, $TagCopy);
$NewTag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag')); $NewTag = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
$this->assertTrue(is_a($Tag, 'RegisterArticleTag')); $this->assertTrue($Tag instanceof RegisterArticleTag);
$NewTagCopy = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag')); $NewTagCopy = ClassRegistry::init(array('class' => 'RegisterArticleTag', 'alias' => 'NewTag'));
@ -166,17 +166,17 @@ class ClassRegistryTest extends CakeTestCase {
$this->assertTrue($TagCopy->name === 'SomeOtherName'); $this->assertTrue($TagCopy->name === 'SomeOtherName');
$User = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false)); $User = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
$this->assertTrue(is_a($User, 'AppModel')); $this->assertTrue($User instanceof AppModel);
$UserCopy = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false)); $UserCopy = ClassRegistry::init(array('class' => 'RegisterUser', 'alias' => 'User', 'table' => false));
$this->assertTrue(is_a($UserCopy, 'AppModel')); $this->assertTrue($UserCopy instanceof AppModel);
$this->assertEquals($User, $UserCopy); $this->assertEquals($User, $UserCopy);
$Category = ClassRegistry::init(array('class' => 'RegisterCategory')); $Category = ClassRegistry::init(array('class' => 'RegisterCategory'));
$this->assertTrue(is_a($Category, 'RegisterCategory')); $this->assertTrue($Category instanceof RegisterCategory);
$ParentCategory = ClassRegistry::init(array('class' => 'RegisterCategory', 'alias' => 'ParentCategory')); $ParentCategory = ClassRegistry::init(array('class' => 'RegisterCategory', 'alias' => 'ParentCategory'));
$this->assertTrue(is_a($ParentCategory, 'RegisterCategory')); $this->assertTrue($ParentCategory instanceof RegisterCategory);
$this->assertNotSame($Category, $ParentCategory); $this->assertNotSame($Category, $ParentCategory);
$this->assertNotEquals($Category->alias, $ParentCategory->alias); $this->assertNotEquals($Category->alias, $ParentCategory->alias);
@ -193,12 +193,12 @@ class ClassRegistryTest extends CakeTestCase {
ClassRegistry::init('RegisterArticleTag'); ClassRegistry::init('RegisterArticleTag');
$ArticleTag = ClassRegistry::getObject('RegisterArticleTag'); $ArticleTag = ClassRegistry::getObject('RegisterArticleTag');
$this->assertTrue(is_a($ArticleTag, 'RegisterArticleTag')); $this->assertTrue($ArticleTag instanceof RegisterArticleTag);
ClassRegistry::flush(); ClassRegistry::flush();
$NoArticleTag = ClassRegistry::isKeySet('RegisterArticleTag'); $NoArticleTag = ClassRegistry::isKeySet('RegisterArticleTag');
$this->assertFalse($NoArticleTag); $this->assertFalse($NoArticleTag);
$this->assertTrue(is_a($ArticleTag, 'RegisterArticleTag')); $this->assertTrue($ArticleTag instanceof RegisterArticleTag);
} }
/** /**
@ -233,13 +233,13 @@ class ClassRegistryTest extends CakeTestCase {
$this->assertTrue($Tag); $this->assertTrue($Tag);
$Article = ClassRegistry::getObject('Article'); $Article = ClassRegistry::getObject('Article');
$this->assertTrue(is_a($Article, 'RegisterArticle')); $this->assertTrue($Article instanceof RegisterArticle);
$Featured = ClassRegistry::getObject('Featured'); $Featured = ClassRegistry::getObject('Featured');
$this->assertTrue(is_a($Featured, 'RegisterArticleFeatured')); $this->assertTrue($Featured instanceof RegisterArticleFeatured);
$Tag = ClassRegistry::getObject('Tag'); $Tag = ClassRegistry::getObject('Tag');
$this->assertTrue(is_a($Tag, 'RegisterArticleTag')); $this->assertTrue($Tag instanceof RegisterArticleTag);
} }
/** /**
@ -254,15 +254,15 @@ class ClassRegistryTest extends CakeTestCase {
//Faking a plugin //Faking a plugin
CakePlugin::load('RegistryPlugin', array('path' => '/fake/path')); CakePlugin::load('RegistryPlugin', array('path' => '/fake/path'));
$TestRegistryPluginModel = ClassRegistry::init('RegistryPlugin.TestRegistryPluginModel'); $TestRegistryPluginModel = ClassRegistry::init('RegistryPlugin.TestRegistryPluginModel');
$this->assertTrue(is_a($TestRegistryPluginModel, 'TestRegistryPluginModel')); $this->assertTrue($TestRegistryPluginModel instanceof TestRegistryPluginModel);
$this->assertEquals('something_', $TestRegistryPluginModel->tablePrefix); $this->assertEquals('something_', $TestRegistryPluginModel->tablePrefix);
$PluginUser = ClassRegistry::init(array('class' => 'RegistryPlugin.RegisterUser', 'alias' => 'RegistryPluginUser', 'table' => false)); $PluginUser = ClassRegistry::init(array('class' => 'RegistryPlugin.RegisterUser', 'alias' => 'RegistryPluginUser', 'table' => false));
$this->assertTrue(is_a($PluginUser, 'RegistryPluginAppModel')); $this->assertTrue($PluginUser instanceof RegistryPluginAppModel);
$PluginUserCopy = ClassRegistry::getObject('RegistryPluginUser'); $PluginUserCopy = ClassRegistry::getObject('RegistryPluginUser');
$this->assertTrue(is_a($PluginUserCopy, 'RegistryPluginAppModel')); $this->assertTrue($PluginUserCopy instanceof RegistryPluginAppModel);
$this->assertSame($PluginUser, $PluginUserCopy); $this->assertSame($PluginUser, $PluginUserCopy);
CakePlugin::unload(); CakePlugin::unload();
} }

View file

@ -311,7 +311,7 @@ class ClassRegistry {
$duplicate = false; $duplicate = false;
if ($this->isKeySet($alias)) { if ($this->isKeySet($alias)) {
$model = $this->getObject($alias); $model = $this->getObject($alias);
if (is_object($model) && (is_a($model, $class) || $model->alias === $class)) { if (is_object($model) && ($model instanceof $class || $model->alias === $class)) {
$duplicate = $model; $duplicate = $model;
} }
unset($model); unset($model);