Passed
Push — master ( e01d3a...41a950 )
by Luiz Kim
02:37
created

SkyNetService::getBotUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace ControleOnline\Service;
4
5
use ControleOnline\Entity\User;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class SkyNetService
9
{
10
11
    private static ?User $botUser = null;
12
13
    public function __construct(
14
        private EntityManagerInterface $manager
15
    ) {}
16
17
    public function discoveryBotUser(): User
18
    {
19
        if (!self::$botUser)
20
            $bots = ['R2D2', 'C3PO', 'T800', 'SkyNet'];
21
22
        $online = array_rand($bots);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $bots does not seem to be defined for all execution paths leading up to this point.
Loading history...
23
        $bot = $bots[$online];
24
25
        self::$botUser = $this->manager->getRepository(User::class)->findOneBy(['username' => $bot]);
26
        if (!self::$botUser) {
27
            self::$botUser = new User();
28
            self::$botUser->setUserName($bot);
29
            self::$botUser->setHash('872844840.0');
30
            $this->manager->persist(self::$botUser);
31
            $this->manager->flush();
32
        }
33
        return self::$botUser;
34
    }
35
    public function getBotUser(): ?User
36
    {
37
        return self::$botUser;
38
    }
39
}
40