Completed
Push — master ( 117507...ef2ad2 )
by Gerard
02:17
created

AbstractCommand::isEnvTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gbere\SimpleAuth\Command;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Gbere\SimpleAuth\Entity\Role;
9
use Gbere\SimpleAuth\Entity\User;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
12
use Symfony\Contracts\Service\ServiceSubscriberInterface;
13
use Symfony\Contracts\Service\ServiceSubscriberTrait;
14
15
abstract class AbstractCommand extends Command implements ServiceSubscriberInterface
16
{
17
    use ServiceSubscriberTrait;
18
19
    protected function findUserByEmail(string $email): ?User
20
    {
21
        return $this->getEntityManager()->getRepository(User::class)->findOneBy(['email' => $email]);
22
    }
23
24
    protected function findRoleByName(string $name): ?Role
25
    {
26
        return $this->getEntityManager()->getRepository(Role::class)->findOneBy(['name' => $name]);
27
    }
28
29
    /**
30
     * @return Role[]
31
     */
32
    protected function findAllRoles()
33
    {
34
        return $this->getEntityManager()->getRepository(Role::class)->findAll();
35
    }
36
37
    protected function getEntityManager(): EntityManagerInterface
38
    {
39
        return $this->container->get(__METHOD__);
40
    }
41
42
    protected function getParameterBag(): ParameterBagInterface
43
    {
44
        return $this->container->get(__METHOD__);
45
    }
46
47
    protected function isTestEnv(): bool
48
    {
49
        return 'test' === $this->getParameterBag()->get('kernel.environment');
50
    }
51
}
52