Completed
Pull Request — develop (#230)
by Franck
08:45
created

AbstractLayoutPack::findLayout()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.2
cc 4
eloc 5
nc 3
nop 2
crap 4
1
<?php
2
/**
3
 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4
 * presentations documents.
5
 *
6
 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7
 * General Public License version 3 as published by the Free Software Foundation.
8
 *
9
 * For the full copyright and license information, please read the LICENSE
10
 * file that was distributed with this source code. For the full list of
11
 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12
 *
13
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack;
19
20
/**
21
 * \PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack
22
 * @deprecated 0.7
23
 */
24
abstract class AbstractLayoutPack
25
{
26
    /**
27
     * Master slides
28
     *
29
     * Structure:
30
     * - masterid
31
     * - body
32
     *
33
     * @var array
34
     */
35
    protected $masterSlides = array();
36
37
    /**
38
     * Master slide relations
39
     *
40
     * Structure:
41
     * - master id
42
     * - id (relation id)
43
     * - type
44
     * - contentType
45
     * - target (full path in OpenXML package)
46
     * - contents (body)
47
     *
48
     * @var array
49
     */
50
    protected $masterSlideRels = array();
51
52
    /**
53
     * Themes
54
     *
55
     * Structure:
56
     * - masterid
57
     * - body
58
     *
59
     * @var array
60
     */
61
    protected $themes = '';
62
63
    /**
64
     * Theme relations
65
     *
66
     * Structure:
67
     * - masterid
68
     * - id (relation id)
69
     * - type
70
     * - contentType
71
     * - target (full path in OpenXML package)
72
     * - contents (body)
73
     *
74
     * @var array
75
     */
76
    protected $themeRelations = array();
77
78
    /**
79
     * Array of slide layouts.
80
     *
81
     * These are all an array consisting of:
82
     * - id (int)
83
     * - masterid (int)
84
     * - name (string)
85
     * - body (string)
86
     *
87
     * @var array
88
     */
89
    protected $layouts = array();
90
91
    /**
92
     * Layout relations
93
     *
94
     * Structure:
95
     * - layoutId (referencing layout id in layouts array)
96
     * - id (relation id)
97
     * - type
98
     * - contentType
99
     * - target (full path in OpenXML package)
100
     * - contents (body)
101
     *
102
     * @var array
103
     */
104
    protected $layoutRelations = array();
105
106
    /**
107
     * Get master slides
108
     *
109
     * @return array
110
     */
111
    public function getMasterSlides()
112
    {
113
        return $this->masterSlides;
114
    }
115
116
    /**
117
     * Get master slide relations
118
     *
119
     * @return array
120
     */
121
    public function getMasterSlideRelations()
122
    {
123
        return $this->masterSlideRels;
124
    }
125
126
    /**
127
     * Get themes
128
     *
129
     * @return array
130
     */
131
    public function getThemes()
132
    {
133
        return $this->themes;
134
    }
135
136
    /**
137
     * Get theme relations
138
     *
139
     * @return array
140
     */
141
    public function getThemeRelations()
142
    {
143
        return $this->themeRelations;
144
    }
145
146
    /**
147
     * Get array of slide layouts
148
     *
149
     * @return array
150
     */
151 3
    public function getLayouts()
152
    {
153 3
        return $this->layouts;
154
    }
155
156
    /**
157
     * Get array of slide layout relations
158
     *
159
     * @return array
160
     */
161
    public function getLayoutRelations()
162
    {
163
        return $this->layoutRelations;
164
    }
165
166
    /**
167
     * Find specific slide layout.
168
     *
169
     * This is an array consisting of:
170
     * - masterid
171
     * - name (string)
172
     * - body (string)
173
     *
174
     * @param string $name
175
     * @param int $masterId
176
     * @return array
177
     * @throws \Exception
178
     */
179 2
    public function findLayout($name = '', $masterId = 1)
180
    {
181 2
        foreach ($this->layouts as $layout) {
182 2
            if ($layout['name'] == $name && $layout['masterid'] == $masterId) {
183 1
                return $layout;
184
            }
185 2
        }
186
187 1
        throw new \Exception("Could not find slide layout $name in current layout pack.");
188
    }
189
190
    /**
191
     * Find specific slide layout id.
192
     *
193
     * @param string $name
194
     * @param int $masterId
0 ignored issues
show
Bug introduced by
There is no parameter named $masterId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
195
     * @return int
196
     * @throws \Exception
197
     */
198 2
    public function findLayoutId($name = '')
199
    {
200 2
        foreach ($this->layouts as $layoutId => $layout) {
201 2
            if ($layout['name'] == $name) {
202 1
                return $layoutId;
203
            }
204 2
        }
205
206 1
        throw new \Exception("Could not find slide layout $name in current layout pack.");
207
    }
208
209
    /**
210
     * Find specific slide layout name.
211
     *
212
     * @param int $idLayout
213
     * @param int $masterId
0 ignored issues
show
Bug introduced by
There is no parameter named $masterId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
214
     * @return int
215
     * @throws \Exception
216
     */
217 2
    public function findLayoutName($idLayout = '')
218
    {
219 2
        foreach ($this->layouts as $layoutId => $layout) {
220 2
            if ($layoutId == $idLayout) {
221 1
                return $layout['name'];
222
            }
223 2
        }
224
225 1
        throw new \Exception("Could not find slide layout $idLayout in current layout pack.");
226
    }
227
}
228