PlainAvatar::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Dwr\AvatarBundle\Model;
4
5
class PlainAvatar extends Avatar {
6
    
7
    /**
8
     * @var int 
9
     */
10
    protected $size;
11
    
12
    /**
13
     * @var string 
14
     */
15
    protected $picture;
16
    
17
    /**
18
     * @var resource
19
     */
20
    protected $canvas;
21
    
22
23
    /**
24
     * @param int $size
25
     */
26
    public function __construct($size) 
27
    {
28
        $this->size = $size;
29
        $this->canvas = imagecreatetruecolor($this->getSize(), $this->getSize());
30
    }
31
    
32
    /**
33
     * @return Avatar
34
     */
35
    public function getAvatar() 
36
    {
37
        return $this;
38
    }
39
    
40
    protected function draw()
41
    {
42
        $this->createBackground();
43
        
44
        ob_start(); 
45
            imagejpeg($this->canvas);
46
            $image = ob_get_contents(); 
47
        ob_end_clean();
48
        
49
        $this->picture = $image;
50
        
51
        return $this->picture;
52
    }
53
    
54
    private function createBackground()
55
    {
56
        $backgroundColor = $this->randomizeColor($this->canvas, Avatar::$WHITE);
57
        imagefill($this->canvas, 0, 0, $backgroundColor);
58
    }
59
    
60
}
61