AbstractImage::getWebPath()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 0
crap 12
1
<?php
2
3
namespace SumoCoders\FrameworkCoreBundle\ValueObject;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
/**
8
 * The following things are mandatory to use this class.
9
 *
10
 * You need to implement the method getUploadDir.
11
 * When using this class in an entity certain life cycle callbacks should be called
12
 * prepareToUpload for PrePersist() and PreUpdate()
13
 * upload for PostPersist() and PostUpdate()
14
 * remove for PostRemove()
15
 *
16
 * The following things are optional
17
 * A fallback image can be set by setting the full path of the image to the FALLBACK_IMAGE constant
18
 */
19
abstract class AbstractImage extends AbstractFile
20
{
21
    /**
22
     * @var string|null
23
     */
24
    const FALLBACK_IMAGE = null;
25
26
    public function getWebPath(): string
27
    {
28
        $webPath = parent::getWebPath();
29
30
        $file = $this->getAbsolutePath();
31
32
        if (is_file($file) && file_exists($file)) {
33
            return $webPath;
34
        }
35
36
        return static::FALLBACK_IMAGE;
37
    }
38
39
    public function getFallbackImage(): ?string
40
    {
41
        return static::FALLBACK_IMAGE;
42
    }
43
}
44