EscapeHtmlDecorator::make()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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