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

Robot::generateRandomLetters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 13
rs 9.4286
c 1
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
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