Skip to content

Commit 79afb5a

Browse files
committed
Update PHP minimum version to 8.0 and dependencies to latest compatible version
1 parent 4f6606b commit 79afb5a

File tree

6 files changed

+73
-13
lines changed

6 files changed

+73
-13
lines changed

phpstan.neon.dist

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ parameters:
33
paths:
44
- src
55
universalObjectCratesClasses:
6-
- Platine\Orm\Entity
6+
- Platine\Orm\Entity
7+
ignoreErrors:
8+
-
9+
identifier: missingType.generics

src/Entity.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ final public function __construct(
100100
];
101101
}
102102

103+
/**
104+
* Clone the object
105+
* @return void
106+
*/
107+
public function __clone(): void
108+
{
109+
if ($this->dataMapper !== null) {
110+
$this->dataMapper = clone $this->dataMapper;
111+
}
112+
}
113+
103114
/**
104115
* Convert entity to JSON array
105116
* @return array<string, mixed>

src/Relation/ForeignKey.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function isComposite(): bool
103103
*/
104104
public function getValue(array $columns, bool $map = false): mixed
105105
{
106-
if (!$map && !$this->composite) {
106+
if ($map === false && $this->composite === false) {
107107
$column = array_keys($this->columns);
108108

109109
return isset($columns[$column[0]])
@@ -131,7 +131,7 @@ public function getValue(array $columns, bool $map = false): mixed
131131
*/
132132
public function getInverseValue(array $columns, bool $map = false): mixed
133133
{
134-
if (!$map && !$this->composite) {
134+
if ($map === false && $this->composite === false) {
135135
$column = array_values($this->columns);
136136

137137
return isset($columns[$column[0]])
@@ -158,7 +158,7 @@ public function getInverseValue(array $columns, bool $map = false): mixed
158158
*/
159159
public function extractValue(array $columns, bool $map = false): mixed
160160
{
161-
if (!$map && !$this->composite) {
161+
if ($map === false && $this->composite === false) {
162162
$column = array_values($this->columns);
163163

164164
return isset($columns[$column[0]])

src/Repository.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ public function query(string|array $with = [], bool $immediate = false): EntityQ
162162

163163
/**
164164
* {@inheritedoc}
165-
* @return self<TEntity>
166165
*/
167166
public function with(string|array $with, bool $immediate = false): self
168167
{
@@ -177,7 +176,6 @@ public function with(string|array $with, bool $immediate = false): self
177176

178177
/**
179178
* {@inheritedoc}
180-
* @return self<TEntity>
181179
*/
182180
public function orderBy(
183181
string|Closure|Expression|array $columns,
@@ -191,7 +189,6 @@ public function orderBy(
191189

192190
/**
193191
* {@inheritedoc}
194-
* @return self<TEntity>
195192
*/
196193
public function limit(int $offset, int $limit): self
197194
{
@@ -203,7 +200,6 @@ public function limit(int $offset, int $limit): self
203200

204201
/**
205202
* {@inheritedoc}
206-
* @return self<TEntity>
207203
*/
208204
public function filters(string|array $filters = []): self
209205
{
@@ -218,6 +214,7 @@ public function filters(string|array $filters = []): self
218214

219215
/**
220216
* {@inheritedoc}
217+
* @return TEntity[]
221218
*/
222219
public function all(array $columns = []): array
223220
{
@@ -243,6 +240,7 @@ public function create(array $columns = []): Entity
243240

244241
/**
245242
* {@inheritedoc}
243+
* @return TEntity|null
246244
*/
247245
public function find(array|string|int|float $id): ?Entity
248246
{

src/RepositoryInterface.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ interface RepositoryInterface
6161
* Return the instance of EntityQuery
6262
* @param string|array<int, string>|array<string, Closure> $with
6363
* @param bool $immediate
64-
* @return EntityQuery<TEntity>
64+
* @return EntityQuery
6565
*/
6666
public function query(string|array $with = [], bool $immediate = false): EntityQuery;
6767

6868
/**
6969
* Load with relation
7070
* @param string|array<int, string>|array<string, Closure> $with
7171
* @param bool $immediate
72-
* @return self<TEntity>
72+
* @return $this
7373
*/
7474
public function with(string|array $with, bool $immediate = false): self;
7575

7676
/**
7777
* Set order
7878
* @param string|Closure|Expression|string[]|Expression[]|Closure[] $columns
7979
* @param string $order
80-
* @return self<TEntity>
80+
* @return $this
8181
*/
8282
public function orderBy(
8383
string|Closure|Expression|array $columns,
@@ -88,14 +88,14 @@ public function orderBy(
8888
* Add limit and offset
8989
* @param int $offset
9090
* @param int $limit
91-
* @return self<TEntity>
91+
* @return $this
9292
*/
9393
public function limit(int $offset, int $limit): self;
9494

9595
/**
9696
* Apply an filters on the query
9797
* @param string|array<string, mixed> $filters
98-
* @return self<TEntity>
98+
* @return $this
9999
*/
100100
public function filters(string|array $filters = []): self;
101101

tests/EntityTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,54 @@ public function testJson(): void
7373
$this->assertEquals('{"foo":"bar"}', json_encode($e));
7474
}
7575

76+
public function testClone(): void
77+
{
78+
$eMapper = $this->getEntityMapper(
79+
[
80+
81+
],
82+
[]
83+
);
84+
$eManager = $this->getEntityManager([], []);
85+
$columns = [];
86+
$loaders = [];
87+
$readOnly = false;
88+
$isNew = false;
89+
90+
$e = new MyEntity(
91+
$eManager,
92+
$eMapper,
93+
$columns,
94+
$loaders,
95+
$readOnly,
96+
$isNew
97+
);
98+
99+
// By reference
100+
$e->name = 'foo';
101+
$this->assertEquals('foo', $e->name);
102+
103+
$r = $e;
104+
$this->assertEquals('foo', $r->name);
105+
$e->name = 'bar';
106+
107+
$this->assertEquals('bar', $e->name);
108+
$this->assertEquals('bar', $r->name);
109+
110+
// By copy
111+
$c = clone $e;
112+
$this->assertEquals('bar', $e->name);
113+
$this->assertEquals('bar', $c->name);
114+
115+
$e->name = 'baz';
116+
$this->assertEquals('baz', $e->name);
117+
$this->assertEquals('bar', $c->name);
118+
119+
$c->name = 'fooz';
120+
$this->assertEquals('baz', $e->name);
121+
$this->assertEquals('fooz', $c->name);
122+
}
123+
76124
public function testJsonRealEntity(): void
77125
{
78126
$eMapper = $this->getEntityMapper(

0 commit comments

Comments
 (0)