Passed
Pull Request — master (#10)
by nguereza
02:29
created

Product   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A mapEntity() 0 12 1
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