From 7d7954ce181b26a399ea4e09b2eb8bf13d90b226 Mon Sep 17 00:00:00 2001 From: Bryan Crowe Date: Tue, 24 Sep 2013 21:08:06 -0400 Subject: [PATCH] Replaced all is_a() calls with instanceof operator --- lib/Cake/Model/Datasource/DboSource.php | 2 +- .../Case/Console/Command/SchemaShellTest.php | 2 +- .../Test/Case/Controller/ControllerTest.php | 6 ++-- lib/Cake/Test/Case/Routing/RouterTest.php | 2 +- .../Test/Case/Utility/ClassRegistryTest.php | 30 +++++++++---------- lib/Cake/Utility/ClassRegistry.php | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 0d2dd162d0e..159d5a8112f 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -861,7 +861,7 @@ public function isConnected() { * @return boolean True if the result is valid else false */ public function hasResult() { - return is_a($this->_result, 'PDOStatement'); + return $this->_result instanceof PDOStatement; } /** diff --git a/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php b/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php index a78c0fbdd0c..e702e4b16f8 100644 --- a/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/SchemaShellTest.php @@ -137,7 +137,7 @@ public function tearDown() { public function testStartup() { $this->Shell->startup(); $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('schema.php', $this->Shell->Schema->file); diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index 18fccf49e4e..63ed922d0b6 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -482,8 +482,8 @@ public function testConstructClasses() { $Controller = new Controller($request); $Controller->uses = array('ControllerPost', 'ControllerComment'); $Controller->constructClasses(); - $this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost')); - $this->assertTrue(is_a($Controller->ControllerComment, 'ControllerComment')); + $this->assertTrue($Controller->ControllerPost instanceof ControllerPost); + $this->assertTrue($Controller->ControllerComment instanceof ControllerComment); $this->assertEquals('Comment', $Controller->ControllerComment->name); @@ -497,7 +497,7 @@ public function testConstructClasses() { $Controller->constructClasses(); $this->assertTrue(isset($Controller->TestPluginPost)); - $this->assertTrue(is_a($Controller->TestPluginPost, 'TestPluginPost')); + $this->assertTrue($Controller->TestPluginPost instanceof TestPluginPost); } /** diff --git a/lib/Cake/Test/Case/Routing/RouterTest.php b/lib/Cake/Test/Case/Routing/RouterTest.php index 57e4809788d..f843bda0315 100644 --- a/lib/Cake/Test/Case/Routing/RouterTest.php +++ b/lib/Cake/Test/Case/Routing/RouterTest.php @@ -2354,7 +2354,7 @@ public function testUsingCustomRouteClass() { array('controller' => 'posts', 'action' => 'view'), 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'); $routes[0]->expects($this->any()) ->method('parse') diff --git a/lib/Cake/Test/Case/Utility/ClassRegistryTest.php b/lib/Cake/Test/Case/Utility/ClassRegistryTest.php index ff751fe96bf..df656f65292 100644 --- a/lib/Cake/Test/Case/Utility/ClassRegistryTest.php +++ b/lib/Cake/Test/Case/Utility/ClassRegistryTest.php @@ -136,7 +136,7 @@ class ClassRegistryTest extends CakeTestCase { */ public function testAddModel() { $Tag = ClassRegistry::init('RegisterArticleTag'); - $this->assertTrue(is_a($Tag, 'RegisterArticleTag')); + $this->assertTrue($Tag instanceof RegisterArticleTag); $TagCopy = ClassRegistry::isKeySet('RegisterArticleTag'); $this->assertTrue($TagCopy); @@ -145,11 +145,11 @@ public function testAddModel() { $TagCopy = ClassRegistry::getObject('RegisterArticleTag'); - $this->assertTrue(is_a($TagCopy, 'RegisterArticleTag')); + $this->assertTrue($TagCopy instanceof RegisterArticleTag); $this->assertSame($Tag, $TagCopy); $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')); @@ -166,17 +166,17 @@ public function testAddModel() { $this->assertTrue($TagCopy->name === 'SomeOtherName'); $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)); - $this->assertTrue(is_a($UserCopy, 'AppModel')); + $this->assertTrue($UserCopy instanceof AppModel); $this->assertEquals($User, $UserCopy); $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')); - $this->assertTrue(is_a($ParentCategory, 'RegisterCategory')); + $this->assertTrue($ParentCategory instanceof RegisterCategory); $this->assertNotSame($Category, $ParentCategory); $this->assertNotEquals($Category->alias, $ParentCategory->alias); @@ -193,12 +193,12 @@ public function testClassRegistryFlush() { ClassRegistry::init('RegisterArticleTag'); $ArticleTag = ClassRegistry::getObject('RegisterArticleTag'); - $this->assertTrue(is_a($ArticleTag, 'RegisterArticleTag')); + $this->assertTrue($ArticleTag instanceof RegisterArticleTag); ClassRegistry::flush(); $NoArticleTag = ClassRegistry::isKeySet('RegisterArticleTag'); $this->assertFalse($NoArticleTag); - $this->assertTrue(is_a($ArticleTag, 'RegisterArticleTag')); + $this->assertTrue($ArticleTag instanceof RegisterArticleTag); } /** @@ -233,13 +233,13 @@ public function testAddMultipleModels() { $this->assertTrue($Tag); $Article = ClassRegistry::getObject('Article'); - $this->assertTrue(is_a($Article, 'RegisterArticle')); + $this->assertTrue($Article instanceof RegisterArticle); $Featured = ClassRegistry::getObject('Featured'); - $this->assertTrue(is_a($Featured, 'RegisterArticleFeatured')); + $this->assertTrue($Featured instanceof RegisterArticleFeatured); $Tag = ClassRegistry::getObject('Tag'); - $this->assertTrue(is_a($Tag, 'RegisterArticleTag')); + $this->assertTrue($Tag instanceof RegisterArticleTag); } /** @@ -254,15 +254,15 @@ public function testPluginAppModel() { //Faking a plugin CakePlugin::load('RegistryPlugin', array('path' => '/fake/path')); $TestRegistryPluginModel = ClassRegistry::init('RegistryPlugin.TestRegistryPluginModel'); - $this->assertTrue(is_a($TestRegistryPluginModel, 'TestRegistryPluginModel')); + $this->assertTrue($TestRegistryPluginModel instanceof TestRegistryPluginModel); $this->assertEquals('something_', $TestRegistryPluginModel->tablePrefix); $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'); - $this->assertTrue(is_a($PluginUserCopy, 'RegistryPluginAppModel')); + $this->assertTrue($PluginUserCopy instanceof RegistryPluginAppModel); $this->assertSame($PluginUser, $PluginUserCopy); CakePlugin::unload(); } diff --git a/lib/Cake/Utility/ClassRegistry.php b/lib/Cake/Utility/ClassRegistry.php index 3b2a3dc02f2..fb57f7febf0 100644 --- a/lib/Cake/Utility/ClassRegistry.php +++ b/lib/Cake/Utility/ClassRegistry.php @@ -311,7 +311,7 @@ protected function &_duplicate($alias, $class) { $duplicate = false; if ($this->isKeySet($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; } unset($model);