Skip to content

Commit be75022

Browse files
committed
refactor: remove generic type for Model
1 parent e522037 commit be75022

File tree

3 files changed

+35
-42
lines changed

3 files changed

+35
-42
lines changed

phpstan.neon

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ parameters:
44
- src
55

66
reportUnmatchedIgnoredErrors: true
7-
checkGenericClassInNonGenericObjectType: false

src/System/Database/MyModel/Model.php

+29-32
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414
use System\Database\MyQuery\Where;
1515

1616
/**
17-
* @template TKey of array-key
18-
* @template TValue
19-
*
20-
* @implements \ArrayAccess<TKey, TValue>
21-
* @implements \IteratorAggregate<TKey, TValue>
17+
* @implements \ArrayAccess<array-key, mixed>
18+
* @implements \IteratorAggregate<array-key, mixed>
2219
*/
2320
class Model implements \ArrayAccess, \IteratorAggregate
2421
{
@@ -28,7 +25,7 @@ class Model implements \ArrayAccess, \IteratorAggregate
2825

2926
protected string $primery_key = 'id';
3027

31-
/** @var array<array<TKey, TValue>> */
28+
/** @var array<array<array-key, mixed>> */
3229
protected $columns;
3330

3431
/** @var string[] Hide from shoing column */
@@ -37,7 +34,7 @@ class Model implements \ArrayAccess, \IteratorAggregate
3734
/** @var string[] Set Column cant be modify */
3835
protected $resistant = [];
3936

40-
/** @var array<array<TKey, TValue>> Orginal data from database */
37+
/** @var array<array<array-key, mixed>> Orginat data from database */
4138
protected $fresh;
4239

4340
protected ?Where $where = null;
@@ -58,7 +55,7 @@ class Model implements \ArrayAccess, \IteratorAggregate
5855
// magic ----------------------
5956

6057
/**
61-
* @param array<TKey, TValue> $column
58+
* @param array<array-key, mixed> $column
6259
*
6360
* @final
6461
*/
@@ -82,9 +79,9 @@ public function __debugInfo()
8279
}
8380

8481
/**
85-
* @param array<array<TKey, TValue>> $column
86-
* @param string[] $stash
87-
* @param string[] $resistant
82+
* @param array<array<array-key, mixed>> $column
83+
* @param string[] $stash
84+
* @param string[] $resistant
8885
*
8986
* @return static
9087
*/
@@ -111,7 +108,7 @@ public function setUp(
111108
/**
112109
* Getter.
113110
*
114-
* @return TValue
111+
* @return mixed
115112
*/
116113
public function __get(string $name)
117114
{
@@ -121,7 +118,7 @@ public function __get(string $name)
121118
/**
122119
* Setter.
123120
*
124-
* @param TValue $value
121+
* @param mixed $value
125122
*/
126123
public function __set(string $name, $value)
127124
{
@@ -147,7 +144,7 @@ public function has(string $name): bool
147144
/**
148145
* Setter.
149146
*
150-
* @param TValue $value
147+
* @param mixed $value
151148
*
152149
* @return static
153150
*/
@@ -168,7 +165,7 @@ public function setter(string $key, $value): self
168165
*
169166
* @param mixed|null $default
170167
*
171-
* @return TValue
168+
* @return mixed
172169
*/
173170
public function getter(string $key, $default = null)
174171
{
@@ -184,7 +181,7 @@ public function getter(string $key, $default = null)
184181
/**
185182
* Get value of primery key from first collumn/record.
186183
*
187-
* @return TValue
184+
* @return mixed
188185
*
189186
* @throws \Exception No records founds
190187
*/
@@ -211,7 +208,7 @@ public function indentifer(): Where
211208
*
212209
* @param int|string|null $key ByRef key
213210
*
214-
* @return array<TKey, TValue>
211+
* @return array<array-key, mixed>
215212
*/
216213
public function first(&$key = null): array
217214
{
@@ -226,18 +223,18 @@ public function first(&$key = null): array
226223
/**
227224
* Fetch query return as model collection.
228225
*
229-
* @return ModelCollection<static<TKey, TValue>>
226+
* @return ModelCollection<array-key, static>
230227
*/
231228
public function get(): ModelCollection
232229
{
230+
/** @var ModelCollection<array-key, static> */
233231
$collection = new ModelCollection([], $this);
234232
foreach ($this->columns as $column) {
235233
$where = new Where($this->table_name);
236234
if (array_key_exists($this->primery_key, $column)) {
237235
$where->equal($this->primery_key, $column[$this->primery_key]);
238236
}
239237

240-
/* @phpstan-ignore-next-line */
241238
$collection->push((new static($this->pdo, []))->setUp(
242239
$this->table_name,
243240
[$column],
@@ -398,7 +395,7 @@ public function isDirty(?string $column = null): bool
398395
/**
399396
* Get change (diff) between fresh and current column.
400397
*
401-
* @return array<TKey, TValue>
398+
* @return array<array-key, mixed>
402399
*/
403400
public function changes(): array
404401
{
@@ -422,7 +419,7 @@ public function changes(): array
422419
/**
423420
* Convert model column to array.
424421
*
425-
* @return array<array<TKey, TValue>>
422+
* @return array<array<array-key, mixed>>
426423
*/
427424
public function toArray(): array
428425
{
@@ -521,17 +518,17 @@ public function order(string $column_name, int $order_using = MyQuery::ORDER_ASC
521518
// array access --------------
522519

523520
/**
524-
* @param TKey $offset
521+
* @param array-key $offset
525522
*/
526523
public function offsetExists($offset): bool
527524
{
528525
return $this->has($offset);
529526
}
530527

531528
/**
532-
* @param TKey $offset
529+
* @param array-key $offset
533530
*
534-
* @return TValue|null
531+
* @return mixed|null
535532
*/
536533
#[\ReturnTypeWillChange]
537534
public function offsetGet($offset)
@@ -549,7 +546,7 @@ public function offsetUnset($offset): void
549546
}
550547

551548
/**
552-
* @return \Traversable<TKey, TValue>
549+
* @return \Traversable<array-key, mixed>
553550
*/
554551
public function getIterator(): \Traversable
555552
{
@@ -577,8 +574,8 @@ public static function find($id, MyPDO $pdo): static
577574
/**
578575
* Find model using defined primery key.
579576
*
580-
* @param TValue $id
581-
* @param array<TKey, TValue> $column
577+
* @param mixed $id
578+
* @param array<array-key, mixed> $column
582579
*
583580
* @throws \Exception cant inset data
584581
*/
@@ -624,8 +621,8 @@ public static function where(string $where_condition, array $binder, MyPDO $pdo)
624621
/**
625622
* Find model using costume equal.
626623
*
627-
* @param TKey $column_name
628-
* @param TValue $value
624+
* @param array-key $column_name
625+
* @param mixed $value
629626
*/
630627
public static function equal($column_name, $value, MyPDO $pdo): static
631628
{
@@ -640,7 +637,7 @@ public static function equal($column_name, $value, MyPDO $pdo): static
640637
/**
641638
* Fetch all records.
642639
*
643-
* @return ModelCollection<static<TKey, TValue>>
640+
* @return ModelCollection<static<array-key, mixed>>
644641
*/
645642
public static function all(MyPDO $pdo): ModelCollection
646643
{
@@ -655,7 +652,7 @@ public static function all(MyPDO $pdo): ModelCollection
655652
/**
656653
* Get current column without stash.
657654
*
658-
* @return array<array<TKey, TValue>>
655+
* @return array<array<array-key, mixed>>
659656
*/
660657
protected function getColumns(): array
661658
{
@@ -672,7 +669,7 @@ protected function getColumns(): array
672669
*
673670
* @param int|string|null $key ByRef key
674671
*
675-
* @return array<TKey, TValue>
672+
* @return array<array-key, mixed>
676673
*/
677674
protected function firstColumn(&$key = null): array
678675
{

src/System/Database/MyModel/ModelCollection.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@
99
use System\Database\MyQuery\Update;
1010

1111
/**
12-
* @template T of Model<array-key, TValue>
13-
* @template TValue
14-
*
15-
* @extends Collection<array-key, T>
12+
* @extends Collection<array-key, Model>
1613
*/
1714
class ModelCollection extends Collection
1815
{
19-
/** @var T */
16+
/** @var Model */
2017
private $model;
2118

2219
/**
23-
* @param iterable<array-key, T> $models
24-
* @param T $of
20+
* @param iterable<array-key, Model> $models
21+
* @param Model $of
2522
*/
2623
public function __construct($models, $of)
2724
{
@@ -32,7 +29,7 @@ public function __construct($models, $of)
3229
/**
3330
* Get value of primery key from first collumn/record.
3431
*
35-
* @return TValue[]
32+
* @return mixed[]
3633
*
3734
* @throws \Exception No records founds
3835
*/
@@ -59,7 +56,7 @@ public function isDirty(?string $column = null): bool
5956
/**
6057
* Global update (base on primerykey).
6158
*
62-
* @param array<array-key, TValue> $values
59+
* @param array<array-key, mixed> $values
6360
*/
6461
public function update(array $values): bool
6562
{

0 commit comments

Comments
 (0)