Passed
Pull Request — master (#72)
by Dmitriy
10:56
created

ApiUserController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A profile() 0 17 2
1
<?php
2
3
namespace App\Controller;
4
5
use App\DeferredResponse;
6
use App\Entity\User;
7
use App\Repository\UserRepository;
8
use Cycle\ORM\ORMInterface;
9
use Psr\Container\ContainerInterface;
10
use Psr\Http\Message\ServerRequestInterface as Request;
11
use Yiisoft\Factory\Factory;
12
13
class ApiUserController
14
{
15
    public function profile(
16
        Request $request,
17
        ORMInterface $orm,
18
        Factory $factory
19
    ) {
20
        /** @var UserRepository $userRepo */
21
        $userRepo = $orm->getRepository(User::class);
22
        $login = $request->getAttribute('login', null);
23
24
        $item = $userRepo->findByLogin($login);
25
        if ($item === null) {
26
            return $factory->create(DeferredResponse::class, [['error' => 'Page not found']])->withStatus(404);
27
        }
28
29
        return  $factory->create(
30
            DeferredResponse::class,
31
            [['login' => $item->getLogin(), 'created_at' => $item->getCreatedAt()->format('H:i:s d.m.Y')]]
0 ignored issues
show
Bug introduced by
The method getCreatedAt() does not exist on Yiisoft\Auth\IdentityInterface. It seems like you code against a sub-type of Yiisoft\Auth\IdentityInterface such as App\Entity\User. ( Ignorable by Annotation )

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

31
            [['login' => $item->getLogin(), 'created_at' => $item->/** @scrutinizer ignore-call */ getCreatedAt()->format('H:i:s d.m.Y')]]
Loading history...
Bug introduced by
The method getLogin() does not exist on Yiisoft\Auth\IdentityInterface. It seems like you code against a sub-type of Yiisoft\Auth\IdentityInterface such as App\Entity\User. ( Ignorable by Annotation )

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

31
            [['login' => $item->/** @scrutinizer ignore-call */ getLogin(), 'created_at' => $item->getCreatedAt()->format('H:i:s d.m.Y')]]
Loading history...
32
        );
33
    }
34
}
35