Passed
Pull Request — master (#9)
by nguereza
02:20
created

Product::mapEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Platine\App\Model\Entity;
6
7
use Platine\Orm\Entity;
8
use Platine\Orm\Mapper\EntityMapperInterface;
9
use Platine\Orm\Query\Query;
10
11
/**
12
* @class Product
13
* @package Platine\App\Model\Entity
14
* @extends Entity<Product>
15
*/
16
class Product extends Entity
17
{
18
    /**
19
    * @param EntityMapperInterface<Product> $mapper
20
    * @return void
21
    */
22
    public static function mapEntity(EntityMapperInterface $mapper): void
23
    {
24
         $mapper->useTimestamp();
25
         $mapper->casts([
26
            'created_at' => 'date',
27
            'updated_at' => '?date',
28
         ]);
29
30
         $mapper->relation('category')->belongsTo(ProductCategory::class);
31
32
         $mapper->filter('category', function (Query $q, $value) {
33
             $q->where('product_category_id')->is($value);
34
         });
35
    }
36
}
37