Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
OLEObject
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
6 / 6
10
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
5
 getSource
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStyle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIcon
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getImageRelationId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setImageRelationId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * This file is part of PHPWord - A pure PHP library for reading and writing
5 * word processing documents.
6 *
7 * PHPWord is free software distributed under the terms of the GNU Lesser
8 * General Public License version 3 as published by the Free Software Foundation.
9 *
10 * For the full copyright and license information, please read the LICENSE
11 * file that was distributed with this source code. For the full list of
12 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
13 *
14 * @see         https://github.com/PHPOffice/PHPWord
15 *
16 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19namespace PhpOffice\PhpWord\Element;
20
21use PhpOffice\PhpWord\Exception\InvalidObjectException;
22use PhpOffice\PhpWord\Style\Image as ImageStyle;
23
24/**
25 * OLEObject element.
26 */
27class OLEObject extends AbstractElement
28{
29    /**
30     * Ole-Object Src.
31     *
32     * @var string
33     */
34    private $source;
35
36    /**
37     * Image Style.
38     *
39     * @var ?ImageStyle
40     */
41    private $style;
42
43    /**
44     * Icon.
45     *
46     * @var string
47     */
48    private $icon;
49
50    /**
51     * Image Relation ID.
52     *
53     * @var int
54     */
55    private $imageRelationId;
56
57    /**
58     * Has media relation flag; true for Link, Image, and Object.
59     *
60     * @var bool
61     */
62    protected $mediaRelation = true;
63
64    /**
65     * Create a new Ole-Object Element.
66     *
67     * @param string $source
68     * @param mixed $style
69     */
70    public function __construct($source, $style = null)
71    {
72        $supportedTypes = ['xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx'];
73        $pathInfo = pathinfo($source);
74
75        if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) {
76            $ext = $pathInfo['extension'];
77            if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
78                $ext = substr($ext, 0, -1);
79            }
80
81            $this->source = $source;
82            $this->style = $this->setNewStyle(new ImageStyle(), $style, true);
83            $this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
84
85            return;
86        }
87
88        throw new InvalidObjectException();
89    }
90
91    /**
92     * Get object source.
93     *
94     * @return string
95     */
96    public function getSource()
97    {
98        return $this->source;
99    }
100
101    /**
102     * Get object style.
103     *
104     * @return ?ImageStyle
105     */
106    public function getStyle()
107    {
108        return $this->style;
109    }
110
111    /**
112     * Get object icon.
113     *
114     * @return string
115     */
116    public function getIcon()
117    {
118        return $this->icon;
119    }
120
121    /**
122     * Get image relation ID.
123     *
124     * @return int
125     */
126    public function getImageRelationId()
127    {
128        return $this->imageRelationId;
129    }
130
131    /**
132     * Set Image Relation ID.
133     *
134     * @param int $rId
135     */
136    public function setImageRelationId($rId): void
137    {
138        $this->imageRelationId = $rId;
139    }
140}