Completed
Push — master ( 5c0b6f...5c71f2 )
by Oleg
10:16
created

DataValidationResponseFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 17
cp 0
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Stdlib\Validation;
5
6
use Psr\Http\Message\ResponseInterface;
7
use SlayerBirden\DataFlowServer\Notification\DangerMessage;
8
use Zend\Diactoros\Response\JsonResponse;
9
10
final class DataValidationResponseFactory
11
{
12
    /**
13
     * Create Data Validation response object
14
     *
15
     * @param string $dataObjectName
16
     * @param mixed $value
17
     * @return ResponseInterface
18
     */
19
    public function __invoke(
20
        ?string $dataObjectName = null,
21
        $value = null
22
    ): ResponseInterface {
23
24
        if (!empty($dataObjectName)) {
25
            $data = [
26
                $dataObjectName => $value,
27
            ];
28
        } else {
29
            $data = [];
30
        }
31
32
        return new JsonResponse([
33
            'data' => $data,
34
            'success' => false,
35
            'msg' => new DangerMessage('Provided data can not be read.'),
36
        ], 400);
37
    }
38
}
39