Completed
Pull Request — develop (#197)
by Franck
08:11
created

Image::getFilename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PhpOffice\PhpPresentation\Slide\Background;
4
5
use PhpOffice\PhpPresentation\Slide\AbstractBackground;
6
7
class Image extends AbstractBackground
8
{
9
    /**
10
     * @var string
11
     */
12
    public $relationId;
13
14
    /**
15
     * Path
16
     *
17
     * @var string
18
     */
19
    protected $path;
20
21
    /**
22
     * @var int
23
     */
24
    protected $height;
25
26
    /**
27
     * @var int
28
     */
29
    protected $width;
30
31
    /**
32
     * Get Path
33
     *
34
     * @return string
35
     */
36 2
    public function getPath()
37
    {
38 2
        return $this->path;
39
    }
40
41
    /**
42
     * Set Path
43
     *
44
     * @param  string                      $pValue      File path
45
     * @param  boolean                     $pVerifyFile Verify file
46
     * @throws \Exception
47
     * @return \PhpOffice\PhpPresentation\Shape\Drawing
48
     */
49 2
    public function setPath($pValue = '', $pVerifyFile = true)
50
    {
51 2
        if ($pVerifyFile) {
52 2
            if (file_exists($pValue)) {
53 2
                $this->path = $pValue;
54
55 2
                if ($this->width == 0 && $this->height == 0) {
56
                    // Get width/height
57 2
                    list($this->width, $this->height) = getimagesize($pValue);
58 2
                }
59 2
            } else {
60
                throw new \Exception("File $pValue not found!");
61
            }
62 2
        } else {
63 1
            $this->path = $pValue;
64
        }
65
66 2
        return $this;
67
    }
68
69
    /**
70
     * Get Filename
71
     *
72
     * @return string
73
     */
74 1
    public function getFilename()
75
    {
76 1
        return basename($this->path);
77
    }
78
79
    /**
80
     * Get Extension
81
     *
82
     * @return string
83
     */
84 2
    public function getExtension()
85
    {
86 2
        $exploded = explode('.', basename($this->path));
87
88 2
        return $exploded[count($exploded) - 1];
89
    }
90
91
    /**
92
     * Get indexed filename (using image index)
93
     *
94
     * @return string
95
     */
96 2
    public function getIndexedFilename($numSlide)
97
    {
98 2
        return 'background_' . $numSlide . '.' . $this->getExtension();
99
    }
100
}
101