DocumentTransformer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 34
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 8 1
A includeBody() 0 14 4
A single_line_breaks() 0 4 1
1
<?php
2
3
namespace Webfactor\Laravel\Backpack\Documents\Transformers;
4
5
use League\Fractal\TransformerAbstract;
6
use Webfactor\Laravel\Backpack\Documents\Models\Document;
7
8
class DocumentTransformer extends TransformerAbstract
9
{
10
    protected $defaultIncludes = ['body'];
11
12
    public function transform(Document $document)
13
    {
14
        return [
15
            'type'      => $document->type,
16
            'title'     => $document->title,
17
            'updatedAt' => $document->updated_at->toIso8601String()
18
        ];
19
    }
20
21
    public function includeBody(Document $document)
22
    {
23
        $type = config('webfactor.documents.body_type');
24
        $options = config('webfactor.documents.transform_options.'.$type, []);
25
        $options = is_array($options)? $options : [$options];
26
27
        $body = $document->body;
28
29
        foreach ($options as $option) {
30
            $body = method_exists($this, $option) ? $this->{$option}($body) : $body;
31
        }
32
33
        return $this->primitive($body);
34
    }
35
36
    // body transformations
37
    protected function single_line_breaks($body)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
38
    {
39
        return str_replace("\r\n", "  \r\n", $body);
40
    }
41
}
42