Passed
Push — master ( f3426b...21e202 )
by Petr
03:26
created

EntityService::createEntityNotFoundResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
namespace AppBundle\Service\Entity;
4
5
use AppBundle\Exception\EntityNotFoundException;
6
use AppBundle\Response\ApiError;
7
use Symfony\Component\HttpFoundation\Response;
8
9
/**
10
 * @author Vehsamrak
11
 */
12
class EntityService
13
{
14
15
    /**
16
     * @param string $entityFullName Entity class name
17
     * @param string|int $id Entity id
18
     * @return ApiError
19
     * @throws EntityNotFoundException
20
     */
21 3
    public function createEntityNotFoundResponse(string $entityFullName, $id): ApiError
22
    {
23 3
        $entityName = (new \ReflectionClass($entityFullName))->getShortName();
24
25 3
        return new ApiError(
26 3
            sprintf('%s "%s" was not found.', $entityName, $id),
27 3
            Response::HTTP_NOT_FOUND
28
        );
29
    }
30
}
31