1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace App\Repository; |
5
|
|
|
|
6
|
|
|
use App\Entity\ApiToken; |
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
8
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @method ApiToken|null find($id, $lockMode = null, $lockVersion = null) |
12
|
|
|
* @method ApiToken|null findOneBy(array $criteria, array $orderBy = null) |
13
|
|
|
* @method ApiToken[] findAll() |
14
|
|
|
* @method ApiToken[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
15
|
|
|
*/ |
16
|
|
|
class ApiTokenRepository extends ServiceEntityRepository |
17
|
|
|
{ |
18
|
7 |
|
public function __construct(RegistryInterface $registry) |
19
|
|
|
{ |
20
|
7 |
|
parent::__construct($registry, ApiToken::class); |
21
|
7 |
|
} |
22
|
|
|
|
23
|
|
|
//todo user doesn't loaded |
24
|
1 |
|
public function findByToken(string $token): ?ApiToken |
25
|
|
|
{ |
26
|
1 |
|
return $this->findOneByToken($token); |
27
|
|
|
/*return $this->findOneBy([ |
|
|
|
|
28
|
|
|
'token' => $token, |
29
|
|
|
]);*/ |
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
public function findOneByToken(string $token): ?ApiToken |
33
|
|
|
{ |
34
|
1 |
|
$query = $this->getEntityManager() |
35
|
1 |
|
->createQuery( |
36
|
1 |
|
'SELECT t, u FROM App\Entity\ApiToken t JOIN t.user u WHERE t.token = :token' |
37
|
1 |
|
)->setParameter('token', $token); |
38
|
|
|
|
39
|
|
|
try { |
40
|
1 |
|
return $query->getSingleResult(); |
41
|
|
|
} catch (\Doctrine\ORM\NoResultException $e) { |
42
|
|
|
return null; |
43
|
|
|
} catch (\Doctrine\ORM\NonUniqueResultException $e) { |
44
|
|
|
return null; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function findOneByIdJoinedToCategory($productId) |
49
|
|
|
{ |
50
|
|
|
$query = $this->getEntityManager() |
51
|
|
|
->createQuery( |
52
|
|
|
'SELECT p, c FROM AppBundle:Product p |
53
|
|
|
JOIN p.category c |
54
|
|
|
WHERE p.id = :id' |
55
|
|
|
)->setParameter('id', $productId); |
56
|
|
|
|
57
|
|
|
try { |
58
|
|
|
return $query->getSingleResult(); |
59
|
|
|
} catch (\Doctrine\ORM\NoResultException $e) { |
60
|
|
|
return null; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.