Completed
Pull Request — develop (#207)
by Franck
06:53
created

Image   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 9
c 3
b 0
f 1
lcom 1
cbo 1
dl 0
loc 90
ccs 16
cts 17
cp 0.9412
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 4 1
A getFilename() 0 4 1
A getExtension() 0 6 1
A getIndexedFilename() 0 4 1
B setPath() 0 15 5
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
                throw new \Exception("File $pValue not found!");
54
            }
55
56 2
            if ($this->width == 0 && $this->height == 0) {
57
                // Get width/height
58 2
                list($this->width, $this->height) = getimagesize($pValue);
59
            }
60
        }
61 2
        $this->path = $pValue;
62 2
        return $this;
63
    }
64
65
    /**
66
     * Get Filename
67
     *
68
     * @return string
69
     */
70 1
    public function getFilename()
71
    {
72 1
        return basename($this->path);
73
    }
74
75
    /**
76
     * Get Extension
77
     *
78
     * @return string
79
     */
80 2
    public function getExtension()
81
    {
82 2
        $exploded = explode('.', basename($this->path));
83
84 2
        return $exploded[count($exploded) - 1];
85
    }
86
87
    /**
88
     * Get indexed filename (using image index)
89
     *
90
     * @return string
91
     */
92 2
    public function getIndexedFilename($numSlide)
93
    {
94 2
        return 'background_' . $numSlide . '.' . $this->getExtension();
95
    }
96
}
97