Completed
Pull Request — develop (#230)
by Franck
09:23
created

AbstractLayoutPack::findLayoutName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 1
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 3
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
 */
23
abstract class AbstractLayoutPack
24
{
25
    /**
26
     * Master slides
27
     *
28
     * Structure:
29
     * - masterid
30
     * - body
31
     *
32
     * @var array
33
     */
34
    protected $masterSlides = array();
35
36
    /**
37
     * Master slide relations
38
     *
39
     * Structure:
40
     * - master id
41
     * - id (relation id)
42
     * - type
43
     * - contentType
44
     * - target (full path in OpenXML package)
45
     * - contents (body)
46
     *
47
     * @var array
48
     */
49
    protected $masterSlideRels = array();
50
51
    /**
52
     * Themes
53
     *
54
     * Structure:
55
     * - masterid
56
     * - body
57
     *
58
     * @var array
59
     */
60
    protected $themes = '';
61
62
    /**
63
     * Theme relations
64
     *
65
     * Structure:
66
     * - masterid
67
     * - id (relation id)
68
     * - type
69
     * - contentType
70
     * - target (full path in OpenXML package)
71
     * - contents (body)
72
     *
73
     * @var array
74
     */
75
    protected $themeRelations = array();
76
77
    /**
78
     * Array of slide layouts.
79
     *
80
     * These are all an array consisting of:
81
     * - id (int)
82
     * - masterid (int)
83
     * - name (string)
84
     * - body (string)
85
     *
86
     * @var array
87
     */
88
    protected $layouts = array();
89
90
    /**
91
     * Layout relations
92
     *
93
     * Structure:
94
     * - layoutId (referencing layout id in layouts array)
95
     * - id (relation id)
96
     * - type
97
     * - contentType
98
     * - target (full path in OpenXML package)
99
     * - contents (body)
100
     *
101
     * @var array
102
     */
103
    protected $layoutRelations = array();
104
105
    /**
106
     * Get master slides
107
     *
108
     * @return array
109
     */
110
    public function getMasterSlides()
111
    {
112
        return $this->masterSlides;
113
    }
114
115
    /**
116
     * Get master slide relations
117
     *
118
     * @return array
119
     */
120
    public function getMasterSlideRelations()
121
    {
122
        return $this->masterSlideRels;
123
    }
124
125
    /**
126
     * Get themes
127
     *
128
     * @return array
129
     */
130
    public function getThemes()
131
    {
132
        return $this->themes;
133
    }
134
135
    /**
136
     * Get theme relations
137
     *
138
     * @return array
139
     */
140
    public function getThemeRelations()
141
    {
142
        return $this->themeRelations;
143
    }
144
145
    /**
146
     * Get array of slide layouts
147
     *
148
     * @return array
149
     */
150 3
    public function getLayouts()
151
    {
152 3
        return $this->layouts;
153
    }
154
155
    /**
156
     * Get array of slide layout relations
157
     *
158
     * @return array
159
     */
160
    public function getLayoutRelations()
161
    {
162
        return $this->layoutRelations;
163
    }
164
165
    /**
166
     * Find specific slide layout.
167
     *
168
     * This is an array consisting of:
169
     * - masterid
170
     * - name (string)
171
     * - body (string)
172
     *
173
     * @param string $name
174
     * @param int $masterId
175
     * @return array
176
     * @throws \Exception
177
     */
178 2
    public function findLayout($name = '', $masterId = 1)
179
    {
180 2
        foreach ($this->layouts as $layout) {
181 2
            if ($layout['name'] == $name && $layout['masterid'] == $masterId) {
182 1
                return $layout;
183
            }
184 2
        }
185
186 1
        throw new \Exception("Could not find slide layout $name in current layout pack.");
187
    }
188
189
    /**
190
     * Find specific slide layout id.
191
     *
192
     * @param string $name
193
     * @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...
194
     * @return int
195
     * @throws \Exception
196
     */
197 2
    public function findLayoutId($name = '')
198
    {
199 2
        foreach ($this->layouts as $layoutId => $layout) {
200 2
            if ($layout['name'] == $name) {
201 1
                return $layoutId;
202
            }
203 2
        }
204
205 1
        throw new \Exception("Could not find slide layout $name in current layout pack.");
206
    }
207
208
    /**
209
     * Find specific slide layout name.
210
     *
211
     * @param int $idLayout
212
     * @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...
213
     * @return int
214
     * @throws \Exception
215
     */
216 2
    public function findLayoutName($idLayout = '')
217
    {
218 2
        foreach ($this->layouts as $layoutId => $layout) {
219 2
            if ($layoutId == $idLayout) {
220 1
                return $layout['name'];
221
            }
222 2
        }
223
224 1
        throw new \Exception("Could not find slide layout $idLayout in current layout pack.");
225
    }
226
}
227