Passed
Pull Request — master (#49)
by
unknown
14:38
created

UserController::profile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 19
rs 9.9
1
<?php
2
namespace App\Controller;
3
4
use App\Controller;
5
use App\Entity\User;
6
use Cycle\ORM\ORMInterface;
7
use Psr\Http\Message\ResponseInterface as Response;
8
use Psr\Http\Message\ServerRequestInterface as Request;
9
10
class UserController extends Controller
11
{
12
    protected function getId(): string
13
    {
14
        return 'user';
15
    }
16
17
    public function index(ORMInterface $orm): Response
18
    {
19
        $repository = $orm->getRepository(User::class);
20
        $response = $this->responseFactory->createResponse();
21
22
        $data = [
23
            'items' => $repository->findAll(),
24
        ];
25
26
        $output = $this->render('index', $data);
27
28
        $response->getBody()->write($output);
29
        return $response;
30
    }
31
32
    public function profile(Request $request, ORMInterface $orm): Response
33
    {
34
        $userRepo = $orm->getRepository(User::class);
35
        $login = $request->getAttribute('login', null);
36
37
        $item = $userRepo->findByLogin($login);
0 ignored issues
show
Bug introduced by
The method findByLogin() does not exist on Cycle\ORM\RepositoryInterface. It seems like you code against a sub-type of Cycle\ORM\RepositoryInterface such as App\Repository\UserRepository. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        /** @scrutinizer ignore-call */ 
38
        $item = $userRepo->findByLogin($login);
Loading history...
38
        if ($item === null) {
39
            return $this->responseFactory->createResponse(404);
40
        }
41
42
        $data = [
43
            'item' => $item,
44
        ];
45
        $response = $this->responseFactory->createResponse();
46
47
        $output = $this->render('profile', $data);
48
        $response->getBody()->write($output);
49
50
        return $response;
51
    }
52
}
53