Skip to content

Commit

Permalink
Merge pull request #31 from tattersoftware/types
Browse files Browse the repository at this point in the history
Typed Properties
  • Loading branch information
MGatner committed Feb 18, 2022
2 parents 3dcc9ae + 9acac92 commit 7621c64
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ jobs:
- name: Analyze for refactoring
run: |
composer global require --dev rector/rector:^0.12.10
composer global require --dev rector/rector
rector process --dry-run --no-progress-bar
2 changes: 1 addition & 1 deletion depfile.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
paths:
- ./src/
- ./vendor/codeigniter4/framework/system
- ./vendor/codeigniter4/framework/system/
exclude_files:
- '#.*test.*#i'
layers:
Expand Down
1 change: 0 additions & 1 deletion infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"src/"
],
"excludes": [
"Accounts",
"Config",
"Database/Migrations",
"Views"
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parameters:
ignoreErrors:
- '#Call to an undefined static method Config\\Services::[A-Za-z]+\(\)#'
universalObjectCratesClasses:
- CodeIgniter\Entity
- CodeIgniter\Entity\Entity
- Faker\Generator
scanDirectories:
Expand Down
5 changes: 5 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector;
use Rector\Set\ValueObject\LevelSetList;
Expand Down Expand Up @@ -122,4 +123,8 @@
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
$services->set(SimplifyEmptyArrayCheckRector::class);
$services->set(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
$services->set(TypedPropertyRector::class)
->configure([
TypedPropertyRector::INLINE_PUBLIC => true,
]);
};
12 changes: 3 additions & 9 deletions src/Components/Caller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,18 @@ class Caller
{
/**
* UID of the user to make the request.
*
* @var string
*/
protected $uid;
protected string $uid = '';

/**
* A Firebase ID token for the user identified by $this->uid.
*
* @var string|null
*/
protected $token;
protected ?string $token = null;

/**
* Error messages from the last call
*
* @var array
*/
protected $errors = [];
protected array $errors = [];

/**
* Get and clear any error messsages
Expand Down
16 changes: 3 additions & 13 deletions src/Firebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ class Firebase

/**
* A pre-authenticated instance of the factory
*
* @var Factory
*/
protected $factory;
protected ?Factory $factory = null;

/**
* Cache for instances that have already been loaded.
*
* @var array
*/
protected $instances = [];
protected array $instances = [];

/**
* Stores the path to the optional service account credentials file.
Expand All @@ -54,13 +50,7 @@ protected function factory(): Factory
}

// If credentials were specified then use them
if ($this->serviceAccount) {
$this->factory = (new Factory())->withServiceAccount($this->serviceAccount);
}
// Create a new instance
else {
$this->factory = new Factory();
}
$this->factory = $this->serviceAccount ? (new Factory())->withServiceAccount($this->serviceAccount) : new Factory();

return $this->factory;
}
Expand Down
20 changes: 5 additions & 15 deletions src/Firestore/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,30 @@ abstract class Collection

/**
* The table's primary key.
*
* @var string
*/
protected $primaryKey = 'uid';
protected string $primaryKey = 'uid';

/**
* An array of field names that are allowed
* to be set by the user in inserts/updates.
*
* @var array
*/
protected $allowedFields = [];
protected array $allowedFields = [];

/**
* If true, will set createdField, and updatedField
* values on created Entities.
*
* @var bool
*/
protected $useTimestamps = true;
protected bool $useTimestamps = true;

/**
* The column used for insert timestamps.
*
* @var string|null
*/
protected $createdField = 'createdAt';
protected ?string $createdField = 'createdAt';

/**
* The column used for update timestamps.
*
* @var string|null
*/
protected $updatedField = 'updatedAt';
protected ?string $updatedField = 'updatedAt';

final public function __construct(?CollectionReference $collection = null, ?ValidationInterface $validation = null)
{
Expand Down
16 changes: 5 additions & 11 deletions src/Firestore/ValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,35 @@ trait ValidationTrait
/**
* Whether we should limit fields in inserts
* and updates to those available in $allowedFields or not.
*
* @var bool
*/
protected $protectFields = true;
protected bool $protectFields = true;

/**
* Our validator instance.
*
* @var ValidationInterface
*/
protected $validation;
protected ValidationInterface $validation;

/**
* Rules used to validate data in add and update methods.
* The array must match the format of data passed to the Validation library.
*
* @var array<string,string>
*/
protected $validationRules = [];
protected array $validationRules = [];

/**
* Contains any custom error messages to be
* used during data validation.
*
* @var array<string,string>
*/
protected $validationMessages = [];
protected array $validationMessages = [];

/**
* Skip the model's validation. Used in conjunction with skipValidation()
* to skip data validation for any future calls.
*
* @var bool
*/
protected $skipValidation = false;
protected bool $skipValidation = false;

/**
* @return $this
Expand Down
2 changes: 1 addition & 1 deletion src/Test/AuthenticationTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait AuthenticationTestTrait
*
* @var string[]
*/
protected $firebaseUserCache = [];
protected array $firebaseUserCache = [];

/**
* Creates a random Firebase UserRecord.
Expand Down
11 changes: 11 additions & 0 deletions src/Test/FirestoreTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,16 @@ protected function deleteCollection($collection, ?FirestoreClient $firestore = n
}
$documents = $collection->limit(30)->documents();
}

// Repeat for any lingering deleted documents (not pagination safe)
$documents = $collection->listDocuments();

foreach ($documents as $document) {
foreach ($document->collections() as $subcollection) {
$this->deleteCollection($subcollection, $firestore);
}

$document->delete();
}
}
}
4 changes: 1 addition & 3 deletions tests/AuthenticationTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ final class AuthenticationTestTraitTest extends TestCase

/**
* Instance of the Firebase SDK.
*
* @var Auth
*/
protected $auth;
protected Auth $auth;

protected function setUp(): void
{
Expand Down
6 changes: 3 additions & 3 deletions tests/_support/Collections/FruitCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ final class FruitCollection extends Collection
public const NAME = 'fruits';
public const ENTITY = Fruit::class;

protected $allowedFields = [
protected array $allowedFields = [
'name',
'taste',
'weight',
'zero',
];
protected $validationRules = [
protected array $validationRules = [
'name' => 'required|string',
'taste' => 'permit_empty|string',
'weight' => 'is_natural_no_zero',
'zero' => 'numeric|in_list[0]',
];
protected $validationMessages = [
protected array $validationMessages = [
'zero' => 'The zero field should be supplied by attributes.',
];

Expand Down
11 changes: 2 additions & 9 deletions tests/_support/FirestoreTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ abstract class FirestoreTestCase extends TestCase
{
use FirestoreTestTrait;

/**
* @var FirestoreClient
*/
protected $firestore;

/**
* @var FruitCollection
*/
protected $collection;
protected FirestoreClient $firestore;
protected FruitCollection $collection;

protected function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/firestore/FirestoreTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function testDeleteCollection()
$collections = firestore()->collections();
$this->assertCount(1, $collections);

$this->deleteCollection('fruits');
$this->deleteCollection($this->collection::NAME);
$collections = firestore()->collections();
$this->assertCount(0, $collections);
}
Expand Down

0 comments on commit 7621c64

Please sign in to comment.