ImageExtension::getBase64()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * ImageExtension.php
4
 *
5
 * @author Bram de Leeuw
6
 * Date: 27/03/17
7
 */
8
9
namespace Broarm\EventTickets;
10
11
use DataExtension;
12
use Director;
13
use Image;
14
15
/**
16
 * Class ImageExtension
17
 * 
18
 * @property ImageExtension|Image $owner
19
 */
20
class ImageExtension extends DataExtension
21
{
22
    /**
23
     * Get a base 64 encoded variant of the image
24
     *
25
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
26
     */
27
    public function getBase64()
28
    {
29
        if ($this->owner->exists()) {
30
            $file = $this->owner->getFullPath();
31
            $mime = mime_content_type($file);
32
            $fileContent = file_get_contents($file);
33
            return "data://$mime;base64," . base64_encode($fileContent);
34
        }
35
        
36
        return null;
37
    }
38
}
39