Skip to content

Commit 4f6606b

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

32 files changed

+351
-276
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
16-
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
16+
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
1717
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
1818
steps:
1919
- name: Checkout
@@ -28,7 +28,7 @@ jobs:
2828
run: php -v
2929
- name: Cache Composer packages
3030
id: composer-cache
31-
uses: actions/cache@v3
31+
uses: actions/cache@v4
3232
with:
3333
path: vendor
3434
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111
command: phpcs-run
1212
use_website_config: false
1313
environment:
14-
php: 7.4.0
14+
php: 8.0
1515
filter:
1616
excluded_paths:
1717
- 'tests/*'

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/852e352455644c8abd8209f2036eaab2)](https://app.codacy.com/gh/platine-php/orm/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
1313

1414
### Requirements
15-
- **PHP >= 7.4**, **PHP 8**
15+
- **PHP >= 8.0**
1616

1717
### Installation
1818
#### Using composer (recommended)

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
},
2020

2121
"require": {
22-
"php": "^7.4 || ^8",
23-
"platine-php/database": "^1.0"
22+
"php": "^8",
23+
"platine-php/database": "^2.0"
2424
},
2525

2626
"require-dev": {
2727
"phpmd/phpmd": "@stable",
28-
"phpstan/phpstan": "^1.8",
29-
"phpunit/phpunit": "^9.5",
30-
"platine-php/dev": "^1.0",
28+
"phpstan/phpstan": "^2.0",
29+
"phpunit/phpunit": "^9.6",
30+
"platine-php/dev": "^2.0",
3131
"squizlabs/php_codesniffer": "3.*"
3232
},
3333

src/Entity.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@
5252
use Platine\Orm\Mapper\DataMapperInterface;
5353
use Platine\Orm\Mapper\EntityMapper;
5454
use Platine\Orm\Mapper\EntityMapperInterface;
55+
use Stringable;
5556

5657
/**
5758
* @class Entity
5859
* @package Platine\Orm
5960
* @template TEntity as Entity
6061
*/
61-
abstract class Entity implements JsonSerializable
62+
abstract class Entity implements JsonSerializable, Stringable
6263
{
6364
/**
6465
* The instance of data mapper
65-
* @var DataMapper<TEntity> |null
66+
* @var DataMapper<TEntity>|null
6667
*/
6768
private ?DataMapper $dataMapper = null;
6869

@@ -103,7 +104,7 @@ final public function __construct(
103104
* Convert entity to JSON array
104105
* @return array<string, mixed>
105106
*/
106-
public function jsonSerialize()
107+
public function jsonSerialize(): mixed
107108
{
108109
$rawColumns = $this->mapper()->getRawColumns();
109110
$data = [];
@@ -130,7 +131,7 @@ public function jsonSerialize()
130131
* @param string $name
131132
* @return mixed
132133
*/
133-
public function __get(string $name)
134+
public function __get(string $name): mixed
134135
{
135136
if ($this->mapper()->hasRelation($name)) {
136137
return $this->mapper()->getRelated($name);
@@ -152,7 +153,7 @@ public function __get(string $name)
152153
* @param mixed $value
153154
* @return void
154155
*/
155-
public function __set(string $name, $value)
156+
public function __set(string $name, mixed $value): void
156157
{
157158
if ($this->mapper()->hasRelation($name)) {
158159
if (is_array($value)) {
@@ -172,7 +173,7 @@ public function __set(string $name, $value)
172173
* @param string $name
173174
* @return bool
174175
*/
175-
public function __isset(string $name)
176+
public function __isset(string $name): bool
176177
{
177178
return $this->mapper()->hasRelation($name)
178179
|| $this->mapper()->hasColumn($name);
@@ -181,9 +182,9 @@ public function __isset(string $name)
181182
/**
182183
* Shortcut to DataMapper clearColumn
183184
* @param string $name
184-
* @return bool
185+
* @return void
185186
*/
186-
public function __unset(string $name)
187+
public function __unset(string $name): void
187188
{
188189
$this->mapper()->clearColumn($name, true);
189190
}
@@ -216,7 +217,10 @@ abstract public static function mapEntity(EntityMapperInterface $mapper): void;
216217
final protected function mapper(): DataMapperInterface
217218
{
218219
if ($this->dataMapper === null) {
219-
$this->dataMapper = new DataMapper(...$this->dataMapperArgs);
220+
/** @var DataMapper<TEntity> $dataMapper */
221+
$dataMapper = new DataMapper(...$this->dataMapperArgs);
222+
223+
$this->dataMapper = $dataMapper;
220224
}
221225

222226
return $this->dataMapper;

src/EntityManager.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@
6060
*/
6161
class EntityManager
6262
{
63-
/**
64-
* The connection
65-
* @var Connection
66-
*/
67-
protected Connection $connection;
68-
6963
/**
7064
* The date format
7165
* @var string
@@ -82,9 +76,8 @@ class EntityManager
8276
* Create new instance
8377
* @param Connection $connection
8478
*/
85-
public function __construct(Connection $connection)
79+
public function __construct(protected Connection $connection)
8680
{
87-
$this->connection = $connection;
8881
$this->dateFormat = $connection->getDriver()->getDateFormat();
8982
}
9083

@@ -131,16 +124,13 @@ public function getEntityMapper(string $entityClass): EntityMapper
131124
$reflection = new ReflectionClass($entityClass);
132125
} catch (ReflectionException $ex) {
133126
throw new RuntimeException(
134-
sprintf(
135-
'Error when build the mapper for entity [%s]',
136-
$entityClass
137-
),
127+
sprintf('Error when build the mapper for entity [%s]', $entityClass),
138128
0,
139129
$ex
140130
);
141131
}
142132

143-
if (!$reflection->isSubclassOf(Entity::class)) {
133+
if ($reflection->isSubclassOf(Entity::class) === false) {
144134
throw new RuntimeException(sprintf(
145135
'[%s] must extend [%s]',
146136
$entityClass,

src/Exception/EntityStateException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
use RuntimeException;
3636

3737
/**
38-
* Class EntityStateException
38+
* @class EntityStateException
3939
* @package Platine\Orm\Exception
4040
*/
4141
class EntityStateException extends RuntimeException

src/Exception/PropertyNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
use RuntimeException;
3636

3737
/**
38-
* Class PropertyNotFoundException
38+
* @class PropertyNotFoundException
3939
* @package Platine\Orm\Exception
4040
*/
4141
class PropertyNotFoundException extends RuntimeException

src/Exception/RelationNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
use RuntimeException;
3636

3737
/**
38-
* Class RelationNotFoundException
38+
* @class RelationNotFoundException
3939
* @package Platine\Orm\Exception
4040
*/
4141
class RelationNotFoundException extends RuntimeException

src/Mapper/DataMapper.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class DataMapper implements DataMapperInterface
8282

8383
/**
8484
* The list of relation loaders
85-
* @var array<string, RelationLoader<TEntity>>
85+
* @var array<string, \Platine\Orm\Relation\RelationLoader<TEntity>>
8686
*/
8787
protected array $loaders = [];
8888

@@ -170,7 +170,7 @@ public function __construct(
170170
$this->isNew = $isNew;
171171
$this->rawColumns = $columns;
172172

173-
if ($isNew && !empty($columns)) {
173+
if ($isNew && count($columns) > 0) {
174174
$this->rawColumns = [];
175175
$this->fill($columns);
176176
}
@@ -223,13 +223,13 @@ public function isReadOnly(): bool
223223
*/
224224
public function wasModified(): bool
225225
{
226-
return !empty($this->modified) || !empty($this->pendingLinks);
226+
return count($this->modified) > 0 || count($this->pendingLinks) > 0;
227227
}
228228

229229
/**
230230
* {@inheritedoc}
231231
*/
232-
public function getColumn(string $name)
232+
public function getColumn(string $name): mixed
233233
{
234234
if ($this->refresh) {
235235
$this->hydrate();
@@ -274,7 +274,7 @@ public function getColumn(string $name)
274274
/**
275275
* {@inheritedoc}
276276
*/
277-
public function setColumn(string $name, $value): void
277+
public function setColumn(string $name, mixed $value): void
278278
{
279279
if ($this->isReadOnly) {
280280
throw new EntityStateException('The record is readonly');
@@ -345,7 +345,7 @@ public function getRawColumns(): array
345345
/**
346346
* {@inheritedoc}
347347
*/
348-
public function setRawColumn(string $name, $value): void
348+
public function setRawColumn(string $name, mixed $value): void
349349
{
350350
$this->modified[$name] = true;
351351
unset($this->columns[$name]);
@@ -355,7 +355,7 @@ public function setRawColumn(string $name, $value): void
355355
/**
356356
* {@inheritedoc}
357357
*/
358-
public function getRelated(string $name, callable $callback = null)
358+
public function getRelated(string $name, callable $callback = null): mixed
359359
{
360360
if (array_key_exists($name, $this->relations)) {
361361
return $this->relations[$name];
@@ -408,7 +408,7 @@ public function setRelated(string $name, ?Entity $entity = null): void
408408
));
409409
}
410410

411-
/** @var Relation<TEntity> $rel */
411+
/** @var \Platine\Orm\Relation\Relation<TEntity> $rel */
412412
$rel = $relations[$name];
413413

414414
if (!($rel instanceof BelongsTo) && !($rel instanceof HasRelation)) {
@@ -499,7 +499,7 @@ public function fill(array $columns): void
499499
* @param mixed $id
500500
* @return bool
501501
*/
502-
public function markAsSaved($id): bool
502+
public function markAsSaved(mixed $id): bool
503503
{
504504
$primaryKey = $this->mapper->getPrimaryKey();
505505
if (!$primaryKey->isComposite()) {
@@ -560,7 +560,7 @@ public function markAsDeleted(): bool
560560
public function executePendingLinkage(): void
561561
{
562562
foreach ($this->pendingLinks as $item) {
563-
/** @var ShareOne<TEntity>|ShareMany<TEntity> $rel */
563+
/** @var \Platine\Orm\Relation\ShareOne<TEntity>|\Platine\Orm\Relation\ShareMany<TEntity> $rel */
564564
$rel = $item['relation'];
565565

566566
if (isset($item['link'])) {
@@ -581,7 +581,7 @@ public function executePendingLinkage(): void
581581
*/
582582
protected function hydrate(): void
583583
{
584-
if (!$this->refresh) {
584+
if ($this->refresh === false) {
585585
return;
586586
}
587587

@@ -615,7 +615,7 @@ protected function hydrate(): void
615615
*
616616
* @return mixed
617617
*/
618-
protected function castGet($value, string $type)
618+
protected function castGet(mixed $value, string $type): mixed
619619
{
620620
$original = $type;
621621

@@ -668,7 +668,7 @@ protected function castGet($value, string $type)
668668
*
669669
* @return mixed
670670
*/
671-
protected function castSet($value, string $type)
671+
protected function castSet(mixed $value, string $type): mixed
672672
{
673673
$original = $type;
674674

@@ -730,7 +730,7 @@ private function setLink(string $relation, Entity $entity, bool $link): void
730730
));
731731
}
732732

733-
/** @var ShareRelation<TEntity> $rel */
733+
/** @var \Platine\Orm\Relation\Relation<TEntity> $rel */
734734
$rel = $relations[$relation];
735735
if (!($rel instanceof ShareRelation)) {
736736
throw new RuntimeException('Unsupported relation type');

0 commit comments

Comments
 (0)