Passed
Pull Request — master (#127)
by Garion
03:26
created

JSONResponse   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonResponse() 0 6 1
1
<?php declare(strict_types=1);
2
3
namespace SilverStripe\MFA;
4
5
use SilverStripe\Control\HTTPResponse;
6
7
/**
8
 * Provides a simplified method for creating JSON-based HTTPResponses.
9
 *
10
 * @package SilverStripe\MFA
11
 */
12
trait JSONResponse
13
{
14
    public function jsonResponse(array $body, int $status = 200): HTTPResponse
15
    {
16
        return HTTPResponse::create()
17
            ->setStatusCode($status)
18
            ->addHeader('Content-Type', 'application/json')
19
            ->setBody(json_encode($body));
20
    }
21
}
22