Completed
Pull Request — develop (#207)
by Franck
12:42 queued 05:23
created

File   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 79
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 4 1
B setPath() 0 15 5
A getContents() 0 4 1
A getExtension() 0 4 1
A getMimeType() 0 5 1
A getIndexedFilename() 0 8 1
1
<?php
2
3
namespace PhpOffice\PhpPresentation\Shape\Drawing;
4
5
use SplFileInfo;
6
7
class File extends AbstractDrawingAdapter
8
{
9
    /**
10
     * @var SplFileInfo
11
     */
12
    protected $oFileInfo;
13
14
    /**
15
     * Get Path
16
     *
17
     * @return string
18
     */
19
    public function getPath()
20
    {
21
        return $this->oFileInfo->getPathname();
22
    }
23
24
    /**
25
     * Set Path
26
     *
27
     * @param  string                      $pValue      File path
28
     * @param  boolean                     $pVerifyFile Verify file
29
     * @throws \Exception
30
     * @return \PhpOffice\PhpPresentation\Shape\Drawing
31
     */
32
    public function setPath($pValue = '', $pVerifyFile = true)
33
    {
34
        if ($pVerifyFile) {
35
            if (!file_exists($pValue)) {
36
                throw new \Exception("File $pValue not found!");
37
            }
38
        }
39
        $this->oFileInfo = new SplFileInfo($pValue);
40
41
        if ($this->width == 0 && $this->height == 0) {
42
            list($this->width, $this->height) = getimagesize($this->getPath());
43
        }
44
45
        return $this;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getContents()
52
    {
53
        return file_get_contents($this->getPath());
54
    }
55
56
57
    /**
58
     * @return string
59
     */
60
    public function getExtension()
61
    {
62
        return $this->oFileInfo->getExtension();
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getMimeType()
69
    {
70
        $image = getimagesize($this->getPath());
71
        return image_type_to_mime_type($image[2]);
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getIndexedFilename()
78
    {
79
        $output = str_replace('.' . $this->getExtension(), '', $this->oFileInfo->getFilename());
80
        $output .= $this->getImageIndex();
81
        $output .= $this->getExtension();
82
        $output = str_replace(' ', '_', $output);
83
        return $output;
84
    }
85
}