AbstractImage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 25
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getWebPath() 0 12 3
A getFallbackImage() 0 4 1
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