Browse Source

fixes phpcs issues

thinkingmedia 9 years ago
parent
commit
e9d904edee
2 changed files with 35 additions and 35 deletions
  1. 9 9
      src/ORM/Table.php
  2. 26 26
      tests/TestCase/ORM/TableTest.php

+ 9 - 9
src/ORM/Table.php

@@ -1217,7 +1217,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
      * If the $search properties do not match the properties of the entity, then you
      * should disable defaults and define all default values using the callback.
      *
-     * If your find conditions require custom order, associations or conditions. The $search
+     * If your find conditions require custom order, associations or conditions, then the $search
      * parameter can be a callable that takes the Query as the argument. Allowing you to
      * customize the find results.
      *
@@ -1229,7 +1229,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
      *   transaction (default: true)
      * - defaults: Whether to use the search criteria as default values for the new entity (default: true)
      *
-     * @param array|callable $search The criteria to find an existing record by, or a callable tha will
+     * @param array|callable $search The criteria to find an existing record by, or a callable that will
      *   customize the find query.
      * @param callable|null $callback A callback that will be invoked for newly
      *   created entities. This callback will be called *before* the entity
@@ -1240,9 +1240,9 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     public function findOrCreate($search, callable $callback = null, $options = [])
     {
         $options = array_merge([
-                'atomic' => true,
-                'defaults' => true
-            ], $options);
+            'atomic' => true,
+            'defaults' => true
+        ], $options);
 
         if ($options['atomic']) {
             return $this->connection()->transactional(function () use ($search, $callback, $options) {
@@ -1264,12 +1264,12 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
      * @param array $options The options to use when saving.
      * @return EntityInterface An entity.
      */
-    protected function _processFindOrCreate($search, callable $callback = null, $options)
+    protected function _processFindOrCreate($search, callable $callback = null, $options = [])
     {
         $query = $this->find();
-        if(is_callable($search)) {
+        if (is_callable($search)) {
             call_user_func($search, $query);
-        } else if(is_array($search)) {
+        } elseif (is_array($search)) {
             $query->where($search);
         } else {
             throw new InvalidArgumentException('Search criteria must be an array or callable');
@@ -1279,7 +1279,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
             return $row;
         }
         $entity = $this->newEntity();
-        if($options['defaults'] && is_array($search)) {
+        if ($options['defaults'] && is_array($search)) {
             $entity->set($search, ['guard' => false]);
         }
         if ($callback) {

+ 26 - 26
tests/TestCase/ORM/TableTest.php

@@ -5364,25 +5364,25 @@ class TableTest extends TestCase
     {
         $articles = TableRegistry::get('Articles');
 
-        $callback_executed = false;
-        $first_article = $articles->findOrCreate(['title' => 'Not there'], function ($article) use (&$callback_executed) {
+        $callbackExecuted = false;
+        $firstArticle = $articles->findOrCreate(['title' => 'Not there'], function ($article) use (&$callbackExecuted) {
             $this->assertTrue($article instanceof EntityInterface);
             $article->body = 'New body';
-            $callback_executed = true;
+            $callbackExecuted = true;
         });
-        $this->assertTrue($callback_executed);
-        $this->assertFalse($first_article->isNew());
-        $this->assertNotNull($first_article->id);
-        $this->assertEquals('Not there', $first_article->title);
-        $this->assertEquals('New body', $first_article->body);
+        $this->assertTrue($callbackExecuted);
+        $this->assertFalse($firstArticle->isNew());
+        $this->assertNotNull($firstArticle->id);
+        $this->assertEquals('Not there', $firstArticle->title);
+        $this->assertEquals('New body', $firstArticle->body);
 
-        $second_article = $articles->findOrCreate(['title' => 'Not there'], function ($article) {
+        $secondArticle = $articles->findOrCreate(['title' => 'Not there'], function ($article) {
             $this->fail('Should not be called for existing entities.');
         });
-        $this->assertFalse($second_article->isNew());
-        $this->assertNotNull($second_article->id);
-        $this->assertEquals('Not there', $second_article->title);
-        $this->assertEquals($first_article->id, $second_article->id);
+        $this->assertFalse($secondArticle->isNew());
+        $this->assertNotNull($secondArticle->id);
+        $this->assertEquals('Not there', $secondArticle->title);
+        $this->assertEquals($firstArticle->id, $secondArticle->id);
     }
 
     /**
@@ -5411,16 +5411,16 @@ class TableTest extends TestCase
     {
         $articles = TableRegistry::get('Articles');
 
-        $callback_executed = false;
+        $callbackExecuted = false;
         $article = $articles->findOrCreate(
             ['author_id' => 2, 'title' => 'First Article'],
-            function ($article) use (&$callback_executed) {
+            function ($article) use (&$callbackExecuted) {
                 $this->assertInstanceOf('Cake\Datasource\EntityInterface', $article);
                 $article->set(['published' => 'N', 'body' => 'New body']);
-                $callback_executed = true;
+                $callbackExecuted = true;
             }
         );
-        $this->assertTrue($callback_executed);
+        $this->assertTrue($callbackExecuted);
         $this->assertFalse($article->isNew());
         $this->assertNotNull($article->id);
         $this->assertEquals('First Article', $article->title);
@@ -5438,7 +5438,7 @@ class TableTest extends TestCase
     {
         $articles = TableRegistry::get('Articles');
 
-        $article = $articles->findOrCreate(['title'=>'Just Something New']);
+        $article = $articles->findOrCreate(['title' => 'Just Something New']);
         $this->assertFalse($article->isNew());
         $this->assertNotNull($article->id);
         $this->assertEquals('Just Something New', $article->title);
@@ -5453,19 +5453,19 @@ class TableTest extends TestCase
     {
         $articles = TableRegistry::get('Articles');
 
-        $called_1 = false;
-        $called_2 = false;
-        $article = $articles->findOrCreate(function ($query) use (&$called_1) {
+        $calledOne = false;
+        $calledTwo = false;
+        $article = $articles->findOrCreate(function ($query) use (&$calledOne) {
             $this->assertInstanceOf('Cake\ORM\Query', $query);
             $query->where(['title' => 'Something Else']);
-            $called_1 = true;
-        }, function ($article) use (&$called_2) {
+            $calledOne = true;
+        }, function ($article) use (&$calledTwo) {
             $this->assertInstanceOf('Cake\Datasource\EntityInterface', $article);
             $article->title = 'Set Defaults Here';
-            $called_2 = true;
+            $calledTwo = true;
         });
-        $this->assertTrue($called_1);
-        $this->assertTrue($called_2);
+        $this->assertTrue($calledOne);
+        $this->assertTrue($calledTwo);
         $this->assertFalse($article->isNew());
         $this->assertNotNull($article->id);
         $this->assertEquals('Set Defaults Here', $article->title);