Skip to content

Commit

Permalink
Apply Rector
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Jan 21, 2022
1 parent 5120bb2 commit e8250ac
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 44 deletions.
6 changes: 6 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Rector\Core\ValueObject\PhpVersion;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
Expand Down Expand Up @@ -77,6 +78,11 @@
__DIR__ . '/tests',
],

// Ignore tests that should always call parent setUp/tearDown
RemoveParentCallWithoutParentRector::class => [
__DIR__ . '/tests',
],

// May load view files directly when detecting classes
StringClassNameToClassConstantRector::class,

Expand Down
6 changes: 1 addition & 5 deletions src/Components/Caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ public function call(string $url, $data)
$client = service('curlrequest');

// Check if $data is already JSON
if (is_string($data) && json_decode($data, true)) {
$body = $data;
} else {
$body = json_encode(['data' => $data]);
}
$body = is_string($data) && json_decode($data, true) ? $data : json_encode(['data' => $data]);
unset($data);

// Check for authorization
Expand Down
5 changes: 3 additions & 2 deletions src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tatter\Firebase;

use CodeIgniter\Entity\Entity as BaseEntity;
use CodeIgniter\I18n\Time;
use Exception;
use Google\Cloud\Core\Timestamp;
use Google\Cloud\Firestore\DocumentReference;
Expand Down Expand Up @@ -33,11 +34,11 @@ class Entity extends BaseEntity
* Converts the given item into a \CodeIgniter\I18n\Time object.
* Adds support for Google\Cloud\Core\Timestamp
*
* @param \CodeIgniter\I18n\Time|Timestamp $value
* @param Time|Timestamp $value
*
* @throws Exception
*
* @return \CodeIgniter\I18n\Time
* @return Time
*/
protected function mutateDate($value)
{
Expand Down
25 changes: 7 additions & 18 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Model
/**
* Our validator instance.
*
* @var \CodeIgniter\Validation\ValidationInterface
* @var ValidationInterface
*/
protected $validation;

Expand Down Expand Up @@ -301,11 +301,7 @@ public function get(?int $limit = null, int $offset = 0, bool $reset = true)
$snapshot = $this->builder()->documents();

// If nothing matched then we're done
if ($snapshot->isEmpty()) {
$this->documents = [];
} else {
$this->documents = $snapshot->rows();
}
$this->documents = $snapshot->isEmpty() ? [] : $snapshot->rows();

return $reset ? $this->reset() : $this;
}
Expand Down Expand Up @@ -624,7 +620,7 @@ public function reset(): self
* @param string $table
* @param bool $refresh Resets the builder back to a clean CollectionReference
*
* @throws \CodeIgniter\Exceptions\ModelException;
* @throws ModelException ;
*
* @return CollectionReference|Query
*/
Expand Down Expand Up @@ -697,15 +693,14 @@ protected function parseWhere(string $str): array
}

//--------------------------------------------------------------------

/**
* Ensures that only the fields that are allowed to be updated
* are in the data array.
*
* Used by insert() and update() to protect against mass assignment
* vulnerabilities.
*
* @throws \CodeIgniter\Database\Exceptions\DataException
* @throws DataException
*/
protected function doProtectFields(array $data): array
{
Expand All @@ -718,7 +713,7 @@ protected function doProtectFields(array $data): array
}

if (is_array($data) && count($data)) {
foreach ($data as $key => $val) {
foreach (array_keys($data) as $key) {
if (! in_array($key, $this->allowedFields, true)) {
unset($data[$key]);
}
Expand Down Expand Up @@ -767,13 +762,7 @@ public function countAllResults(bool $reset = true, bool $test = false): int
*/
public static function classToArray($data, $primaryKey = null, string $dateFormat = 'datetime'): array
{
if (method_exists($data, 'toRawArray')) {
$properties = $data->toRawArray();
} else {
$properties = (array) $data;
}

return $properties;
return method_exists($data, 'toRawArray') ? $data->toRawArray() : (array) $data;
}

/**
Expand Down Expand Up @@ -823,6 +812,6 @@ public function __isset(string $name): bool
return true;
}

return (bool) (isset($this->builder()->{$name}));
return isset($this->builder()->{$name});
}
}
3 changes: 2 additions & 1 deletion tests/_support/FirestoreTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Fabricator;
use Tatter\Firebase\Test\FirestoreTrait;
use Tests\Support\Models\ColorModel;
use Tests\Support\Models\ProfileModel;

Expand All @@ -12,7 +13,7 @@
*/
abstract class FirestoreTestCase extends CIUnitTestCase
{
use \Tatter\Firebase\Test\FirestoreTrait;
use FirestoreTrait;

/**
* UID of the Profile with a subcollection.
Expand Down
4 changes: 2 additions & 2 deletions tests/_support/Models/ProfileModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function fake(Generator &$faker): object
return new Profile([
'firstName' => $faker->firstName,
'lastName' => $faker->lastName,
'age' => mt_rand(5, 90),
'weight' => mt_rand(110, 280),
'age' => random_int(5, 90),
'weight' => random_int(110, 280),
]);
}
}
4 changes: 2 additions & 2 deletions tests/_support/Models/WithCollectionsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function fake(Generator &$faker): object
return new Profile([
'firstName' => $faker->firstName,
'lastName' => $faker->lastName,
'age' => mt_rand(5, 90),
'weight' => mt_rand(110, 280),
'age' => random_int(5, 90),
'weight' => random_int(110, 280),
]);
}
}
11 changes: 2 additions & 9 deletions tests/database/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@
*/
final class ModelTest extends FirestoreTestCase
{
/**
* @var ProfileModel
*/
private $model;

/**
* @var Fabricator
*/
private $fabricator;
private ProfileModel $model;
private Fabricator $fabricator;

protected function setUp(): void
{
Expand Down
13 changes: 8 additions & 5 deletions tests/unit/FirebaseUserTraitTest.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?php

use CodeIgniter\Test\CIUnitTestCase;
use Kreait\Firebase\Auth;
use Kreait\Firebase\Auth\UserRecord;
use Kreait\Firebase\Exception\Auth\UserNotFound;
use Tatter\Firebase\Test\FirebaseUserTrait;

/**
* @internal
*/
final class FirebaseUserTraitTest extends \CodeIgniter\Test\CIUnitTestCase
final class FirebaseUserTraitTest extends CIUnitTestCase
{
use \Tatter\Firebase\Test\FirebaseUserTrait;
use FirebaseUserTrait;

/**
* Instance of the Firebase SDK.
*
* @var Kreait\Firebase\Auth
* @var Auth
*/
protected $firebase;

Expand Down Expand Up @@ -55,7 +58,7 @@ public function testRemoveUserRemovesUser()

$this->expectException(UserNotFound::class);

$test = $this->firebase->getUser($user->uid);
$this->firebase->getUser($user->uid);
}

public function testTearDownRemovesUser()
Expand All @@ -65,6 +68,6 @@ public function testTearDownRemovesUser()

$this->expectException(UserNotFound::class);

$test = $this->firebase->getUser($user->uid);
$this->firebase->getUser($user->uid);
}
}

0 comments on commit e8250ac

Please sign in to comment.