Skip to content

Commit 4230636

Browse files
chore(deps): add types
1 parent 102e9bd commit 4230636

File tree

8 files changed

+58
-57
lines changed

8 files changed

+58
-57
lines changed

composer.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LaravelCacheComponent.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ class LaravelCacheComponent implements CacheComponentInterface
2020

2121
/**
2222
* Copy cache result in memory array.
23-
*
24-
* @var mixed[]
2523
*/
26-
private $inMemoryCache = [];
24+
private array $inMemoryCache = [];
2725

2826
/**
2927
* Injects the dependencies of LaravelCacheComponent.
@@ -42,7 +40,7 @@ public function __construct(Repository $laravelCache)
4240
*
4341
* @return mixed
4442
*/
45-
public function get(string $key)
43+
public function get(string $key): mixed
4644
{
4745
if (isset($this->inMemoryCache[$key])) {
4846
return $this->inMemoryCache[$key];
@@ -61,7 +59,7 @@ public function get(string $key)
6159
* @param mixed $value value being stored in cache
6260
* @param float $minutes cache ttl
6361
*/
64-
public function put(string $key, $value, float $minutes)
62+
public function put(string $key, $value, float $minutes): void
6563
{
6664
if (is_array($value)) {
6765
foreach ($value as $index => $document) {

src/LegacyMongolidModel.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use MongoDB\Collection;
1111
use Mongolid\Cursor\CursorInterface;
1212
use Mongolid\LegacyRecord;
13+
use Mongolid\Model\ModelInterface;
1314

1415
/**
1516
* This class extends the Mongolid\LegacyRecord, so, in order
@@ -114,7 +115,7 @@ public function delete(): bool
114115
*
115116
* @return bool
116117
*/
117-
public function isValid()
118+
public function isValid(): bool
118119
{
119120
if (!$rules = $this->rules()) {
120121
return true;
@@ -208,7 +209,7 @@ public static function first(
208209
$query = [],
209210
array $projection = [],
210211
bool $useCache = false
211-
) {
212+
): ?LegacyRecord {
212213
return static::callMockOrParent('first', func_get_args());
213214
}
214215

@@ -228,7 +229,7 @@ public static function firstOrFail(
228229
$query = [],
229230
array $projection = [],
230231
bool $useCache = false
231-
): mixed {
232+
): ?ModelInterface {
232233
return static::callMockOrParent('firstOrFail', func_get_args());
233234
}
234235

@@ -241,7 +242,7 @@ public static function firstOrFail(
241242
*
242243
* @return LegacyRecord
243244
*/
244-
public static function firstOrNew($id)
245+
public static function firstOrNew($id): ?LegacyRecord
245246
{
246247
return static::callMockOrParent('firstOrNew', func_get_args());
247248
}

src/MongolidModel.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
77
use Illuminate\Support\MessageBag;
88
use Mockery;
9+
use Mockery\CompositeExpectation;
910
use Mockery\Expectation;
1011
use MongoDB\Collection;
1112
use Mongolid\Cursor\CursorInterface;
1213
use Mongolid\LegacyRecord;
1314
use Mongolid\Model\AbstractModel;
14-
use stdClass;
15+
use Mongolid\Model\ModelInterface;
1516

1617
/**
1718
* This class extends the Mongolid\LegacyRecord, so, in order
@@ -182,7 +183,7 @@ public function messages(): array
182183
*
183184
* @return Expectation
184185
*/
185-
public function shouldReceiveSave(): Expectation
186+
public function shouldReceiveSave(): CompositeExpectation
186187
{
187188
return $this->localMockShouldReceive('save');
188189
}
@@ -192,7 +193,7 @@ public function shouldReceiveSave(): Expectation
192193
*
193194
* @return Expectation
194195
*/
195-
public function shouldReceiveDelete(): Expectation
196+
public function shouldReceiveDelete(): CompositeExpectation
196197
{
197198
return $this->localMockShouldReceive('delete');
198199
}
@@ -210,7 +211,7 @@ public static function first(
210211
$query = [],
211212
array $projection = [],
212213
bool $useCache = false
213-
): stdClass|static|null {
214+
): ?ModelInterface {
214215
return static::callMockOrParent('first', func_get_args());
215216
}
216217

@@ -230,7 +231,7 @@ public static function firstOrFail(
230231
$query = [],
231232
array $projection = [],
232233
bool $useCache = false
233-
): stdClass|static|null {
234+
): ?ModelInterface {
234235
return static::callMockOrParent('firstOrFail', func_get_args());
235236
}
236237

@@ -241,9 +242,9 @@ public static function firstOrFail(
241242
*
242243
* @param mixed $id document id
243244
*
244-
* @return LegacyRecord
245+
* @return AbstractModel
245246
*/
246-
public static function firstOrNew(mixed $id): stdClass|static|null
247+
public static function firstOrNew(mixed $id): AbstractModel
247248
{
248249
return static::callMockOrParent('firstOrNew', func_get_args());
249250
}

tests/MongolidModelTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function testShouldSave()
138138
$dataMapper = $this->instance(Builder::class, m::mock(Builder::class));
139139

140140
$model = new class () extends MongolidModel {
141-
protected $collection = 'users';
141+
protected ?string $collection = 'users';
142142
};
143143

144144
// Expectations
@@ -185,7 +185,7 @@ public function testShouldHashAttributesOnSaveAndUpdate($method)
185185
$hasher = $this->instance(Hasher::class, m::mock(Hasher::class));
186186

187187
$model = new class () extends MongolidModel {
188-
protected $collection = 'users';
188+
protected ?string $collection = 'users';
189189

190190
protected $hashedAttributes = ['password'];
191191
};
@@ -280,7 +280,7 @@ public function testShouldDelete()
280280
$dataMapper = $this->instance(Builder::class, m::mock(Builder::class));
281281

282282
$model = new class () extends MongolidModel {
283-
protected $collection = 'collection_name';
283+
protected ?string $collection = 'collection_name';
284284
};
285285

286286
// Expectations
@@ -323,7 +323,7 @@ public function testShouldGetFirst()
323323
$dataMapper = $this->instance(Builder::class, m::mock(Builder::class));
324324

325325
$model = new class () extends MongolidModel {
326-
protected $collection = 'collection_name';
326+
protected ?string $collection = 'collection_name';
327327
};
328328

329329
// Expectations
@@ -345,7 +345,7 @@ public function testShouldMockFirst()
345345
{
346346
// Set
347347
$model = new class () extends MongolidModel {
348-
protected $collection = 'collection_name';
348+
protected ?string $collection = 'collection_name';
349349
};
350350

351351
// Expectations
@@ -367,7 +367,7 @@ public function testShouldGetFirstOrNew()
367367
$dataMapper = $this->instance(Builder::class, m::mock(Builder::class));
368368

369369
$model = new class () extends MongolidModel {
370-
protected $collection = 'collection_name';
370+
protected ?string $collection = 'collection_name';
371371
};
372372

373373
// Expectations
@@ -389,7 +389,7 @@ public function testShouldMockFirstOrNew()
389389
{
390390
// Set
391391
$model = new class () extends MongolidModel {
392-
protected $collection = 'collection_name';
392+
protected ?string $collection = 'collection_name';
393393
};
394394

395395
// Expectations
@@ -411,7 +411,7 @@ public function testShouldGetFirstOrFailAndFoundIt()
411411
$dataMapper = $this->instance(Builder::class, m::mock(Builder::class));
412412

413413
$model = new class () extends MongolidModel {
414-
protected $collection = 'collection_name';
414+
protected ?string $collection = 'collection_name';
415415
};
416416

417417
// Expectations
@@ -435,7 +435,7 @@ public function testShouldGetFirstOrFailAndFail()
435435
$dataMapper = $this->instance(Builder::class, m::mock(Builder::class));
436436

437437
$model = new class () extends MongolidModel {
438-
protected $collection = 'collection_name';
438+
protected ?string $collection = 'collection_name';
439439
};
440440

441441
// Expectations
@@ -456,7 +456,7 @@ public function testShouldMockFirstOrFail()
456456
{
457457
// Set
458458
$model = new class () extends MongolidModel {
459-
protected $collection = 'collection_name';
459+
protected ?string $collection = 'collection_name';
460460
};
461461

462462
// Expectations
@@ -479,7 +479,7 @@ public function testShouldGetWhere()
479479
$cursor = m::mock(CursorInterface::class);
480480

481481
$model = new class () extends MongolidModel {
482-
protected $collection = 'collection_name';
482+
protected ?string $collection = 'collection_name';
483483
};
484484

485485
// Expectations
@@ -504,7 +504,7 @@ public function testShouldGetAll()
504504
$cursor = m::mock(CursorInterface::class);
505505

506506
$model = new class () extends MongolidModel {
507-
protected $collection = 'collection_name';
507+
protected ?string $collection = 'collection_name';
508508
};
509509

510510
// Expectations
@@ -547,7 +547,7 @@ public function testShouldGetCollection()
547547
$client = m::mock(Client::class);
548548

549549
$model = new class () extends MongolidModel {
550-
protected $collection = 'collection_name';
550+
protected ?string $collection = 'collection_name';
551551

552552
public function rawCollection()
553553
{

tests/MongolidUserProviderTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Illuminate\Foundation\Auth\User;
77
use Mockery as m;
88
use MongoDB\BSON\ObjectID;
9+
use Mongolid\LegacyRecord;
10+
use Mongolid\Model\ModelInterface;
11+
use stdClass;
912

1013
class MongolidUserProviderTest extends TestCase
1114
{
@@ -78,7 +81,8 @@ public static function first(
7881
$query = [],
7982
array $projection = [],
8083
bool $useCache = false
81-
) {
84+
): ?ModelInterface {
85+
return null;
8286
}
8387
};
8488

@@ -114,14 +118,14 @@ public function testShouldUpdateRememberToken()
114118
/**
115119
* @return MongolidUserProvider
116120
*/
117-
protected function getProvider()
121+
protected function getProvider(): MongolidUserProvider
118122
{
119123
$model = new class () extends MongolidModel {
120124
public static function first(
121125
$query = [],
122126
array $projection = [],
123127
bool $useCache = false
124-
) {
128+
): ?ModelInterface {
125129
return m::mock(MongolidModel::class);
126130
}
127131
};

0 commit comments

Comments
 (0)