Passed
Pull Request — master (#49)
by Alexander
25:24 queued 10:30
created

UserController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 20
c 1
b 1
f 1
dl 0
loc 41
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A profile() 0 19 2
A getId() 0 3 1
1
<?php
2
3
namespace App\Controller;
4
5
use App\Controller;
6
use App\Entity\User;
7
use Cycle\ORM\ORMInterface;
8
use Psr\Http\Message\ResponseInterface as Response;
9
use Psr\Http\Message\ServerRequestInterface as Request;
10
11
class UserController extends Controller
12
{
13
    protected function getId(): string
14
    {
15
        return 'user';
16
    }
17
18
    public function index(ORMInterface $orm): Response
19
    {
20
        $repository = $orm->getRepository(User::class);
21
        $response = $this->responseFactory->createResponse();
22
23
        $data = [
24
            'items' => $repository->findAll(),
25
        ];
26
27
        $output = $this->render('index', $data);
28
29
        $response->getBody()->write($output);
30
        return $response;
31
    }
32
33
    public function profile(Request $request, ORMInterface $orm): Response
34
    {
35
        $userRepo = $orm->getRepository(User::class);
36
        $login = $request->getAttribute('login', null);
37
38
        $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

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