Total Complexity | 3 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
11 | class Model |
||
12 | { |
||
13 | /** @var Record The database record for the model */ |
||
14 | protected $record; |
||
15 | |||
16 | /** |
||
17 | * Model constructor. |
||
18 | * @param Record $record The database record for the model |
||
19 | */ |
||
20 | 15 | protected function __construct(Record $record) |
|
23 | 15 | } |
|
24 | |||
25 | /** |
||
26 | * Initializes the model with the given database record instead of calling the default constructor. |
||
27 | * @param Record $record The database record for the model |
||
28 | * @return Model A new initialized model with the given database record |
||
29 | */ |
||
30 | 20 | public static function createFromDatabaseRecord(Record $record): self |
|
31 | { |
||
32 | /** @var Model $model */ |
||
33 | 20 | $model = (new \ReflectionClass(static::class))->newInstanceWithoutConstructor(); |
|
34 | 20 | $model->record = $record; |
|
35 | |||
36 | 20 | return $model; |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * Returns the database record for the model. |
||
41 | * @return Record The database record for the model |
||
42 | */ |
||
43 | 18 | public function getDatabaseRecord(): Record |
|
46 | } |
||
47 | } |
||
48 |