Passed
Push — master ( 5b5c00...4c0c12 )
by Julien
04:52
created

Expose   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 39
ccs 0
cts 15
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A listExpose() 0 10 2
A exportExpose() 0 4 1
A expose() 0 10 2
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc\Controller\Rest;
13
14
use Phalcon\Mvc\ModelInterface;
15
use Zemit\Support\Exposer\Exposer;
16
17
trait Expose
18
{
19
    /**
20
     * Expose a single model
21
     */
22
    public function expose(ModelInterface $item, ?array $expose = null): array
23
    {
24
        $expose ??= $this->getExpose();
0 ignored issues
show
Bug introduced by
It seems like getExpose() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $expose ??= $this->/** @scrutinizer ignore-call */ getExpose();
Loading history...
25
        
26
        if ($item instanceof \Zemit\Mvc\Model) {
27
            return $item->expose($expose);
28
        }
29
        
30
        $exposeBuilder = Exposer::createBuilder($item, $expose);
31
        return Exposer::expose($exposeBuilder);
32
    }
33
    
34
    /**
35
     * Expose a list of models
36
     */
37
    public function listExpose(iterable $items, ?array $listExpose = null): array
38
    {
39
        $listExpose ??= $this->getListExpose();
0 ignored issues
show
Bug introduced by
It seems like getListExpose() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $listExpose ??= $this->/** @scrutinizer ignore-call */ getListExpose();
Loading history...
40
        $ret = [];
41
        
42
        foreach ($items as $item) {
43
            $ret [] = $this->expose($item, $listExpose);
44
        }
45
        
46
        return $ret;
47
    }
48
    
49
    /**
50
     * Expose a list of model
51
     */
52
    public function exportExpose(iterable $items, $exportExpose = null): array
53
    {
54
        $exportExpose ??= $this->getExportExpose();
0 ignored issues
show
Bug introduced by
It seems like getExportExpose() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $exportExpose ??= $this->/** @scrutinizer ignore-call */ getExportExpose();
Loading history...
55
        return $this->listExpose($items, $exportExpose);
56
    }
57
}
58