Completed
Push — master ( d70125...de36ed )
by Oliver
14:14
created

DocumentTransformer::single_line_breaks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
        $type = config('webfactor.documents.body_type');
23
        $options = config('webfactor.documents.transform_options.'.$type, []);
24
        $options = is_array($options)? $options : [$options];
25
26
        $body = $document->body;
27
28
        foreach($options as $option) {
29
            $body = method_exists($this, $option) ? $this->{$option}($body) : $body;
30
        }
31
32
        return $this->primitive($body);
33
    }
34
35
    // body transformations
36
    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...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

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