Completed
Push — master ( 6242f2...1d29a1 )
by Petr
03:18
created

Robot   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 4
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A generateRandomLetters() 0 13 2
1
<?php
2
3
namespace Rottenwood\KingdomBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Rottenwood\KingdomBundle\Entity\Infrastructure\User;
7
use Rottenwood\KingdomBundle\Entity\Infrastructure\PlayableCharacter;
8
9
/**
10
 * Робот
11
 * @ORM\Entity()
12
 */
13
class Robot extends User implements PlayableCharacter
14
{
15
16
    public function __construct()
17
    {
18
        parent::__construct();
19
20
        $username = 'Robot_' . $this->generateRandomLetters();
21
        $this->setUsername($username);
22
        $this->setEmail($username . '@' . $this->generateRandomLetters() . '.bot');
23
        $this->setPlainPassword($this->generateRandomLetters());
24
    }
25
26
    /**
27
     * Генератор случайных наборов букв
28
     * @return string
29
     */
30
    private function generateRandomLetters()
31
    {
32
        $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
33
        $pass = [];
34
        $alphaLength = strlen($alphabet) - 1;
35
36
        for ($i = 0; $i < 8; $i++) {
37
            $n = rand(0, $alphaLength);
38
            $pass[] = $alphabet[$n];
39
        }
40
41
        return implode($pass);
42
    }
43
}
44