Passed
Push — master ( 623891...a57e97 )
by Alexander
01:13
created

EscapeHtmlDecorator::make()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 1
nop 3
dl 0
loc 10
ccs 0
cts 3
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Support;
4
5
use Flugg\Responder\Http\Responses\Decorators\ResponseDecorator;
6
use Illuminate\Http\JsonResponse;
7
8
/**
9
 * A decorator class which escapes HTML entities in strings returned by your API.
10
 *
11
 * @package flugger/laravel-responder
12
 * @author  Paolo Caleffi <[email protected]>
13
 * @license The MIT License
14
 */
15
class EscapeHtmlDecorator extends ResponseDecorator
16
{
17
    /**
18
     * Generate a JSON response.
19
     *
20
     * @param  array $data
21
     * @param  int $status
22
     * @param  array $headers
23
     * @return \Illuminate\Http\JsonResponse
24
     */
25
    public function make(array $data, int $status, array $headers = []): JsonResponse
26
    {
27
        array_walk_recursive($data, function (&$value) {
28
            if(is_string($value)) {
29
                $value = e($value);
30
            }
31
        });
32
33
        return $this->factory->make($data, $status, $headers);
34
    }
35
}