Skip to content

Commit 68175f2

Browse files
committed
Added generics and some hints for PhpStan
1 parent 1010f9c commit 68175f2

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

src/EntityQuery.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(Entity $entity, $field)
2727

2828
/**
2929
* @return Entity[]
30+
* @phpstan-return array
3031
*/
3132
public function find()
3233
{
@@ -36,6 +37,7 @@ public function find()
3637

3738
/**
3839
* @return Entity|NULL
40+
* @phpstan-return mixed|NULL
3941
*/
4042
public function findOne()
4143
{

src/RepositoryQuery.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use LeanMapper\Repository;
88

99

10+
/**
11+
* @phpstan-template T of \LeanMapper\Entity
12+
*/
1013
class RepositoryQuery extends Query implements \Countable
1114
{
1215
/** @var Repository */
@@ -21,6 +24,7 @@ public function __construct(Repository $repository)
2124

2225
/**
2326
* @return Entity[]
27+
* @phpstan-return T[]
2428
*/
2529
public function find()
2630
{
@@ -30,6 +34,7 @@ public function find()
3034

3135
/**
3236
* @return Entity|NULL
37+
* @phpstan-return T|NULL
3338
*/
3439
public function findOne()
3540
{

src/TQueryableRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
use LeanMapperQuery\Query;
88

99

10+
/**
11+
* @phpstan-template T of \LeanMapper\Entity
12+
*/
1013
trait TQueryableRepository
1114
{
1215
/**
1316
* Creates base query object
1417
* @return RepositoryQuery
18+
* @phpstan-return RepositoryQuery<T>
1519
*/
1620
public function query()
1721
{
@@ -22,6 +26,7 @@ public function query()
2226
/**
2327
* Fetchs entities by Query object
2428
* @return Entity[]
29+
* @phpstan-return T[]
2530
*/
2631
public function find(Query $query)
2732
{
@@ -32,6 +37,7 @@ public function find(Query $query)
3237
/**
3338
* Fetchs one entity by Query object
3439
* @return Entity|NULL
40+
* @phpstan-return T|NULL
3541
*/
3642
public function findOne(Query $query)
3743
{

src/TRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
use LeanMapper\Entity;
66

77

8+
/**
9+
* @phpstan-template T of \LeanMapper\Entity
10+
*/
811
trait TRepository
912
{
1013
/**
1114
* Creates new empty (detached) entity
1215
* @return Entity
16+
* @phpstan-return T
1317
*/
1418
public function createNewEntity()
1519
{
@@ -21,6 +25,7 @@ public function createNewEntity()
2125
/**
2226
* Fetchs entity by primary key
2327
* @return Entity|NULL
28+
* @phpstan-return T|NULL
2429
*/
2530
public function get($id)
2631
{
@@ -31,6 +36,7 @@ public function get($id)
3136
/**
3237
* Fetchs entity by column value
3338
* @return Entity|NULL
39+
* @phpstan-return T|NULL
3440
*/
3541
protected function getByColumn($column, $value)
3642
{

0 commit comments

Comments
 (0)