Completed
Pull Request — develop (#178)
by
unknown
09:34
created

Theme::writeTheme()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.432

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 7
cts 10
cp 0.7
rs 9.2
cc 4
eloc 8
nc 4
nop 1
crap 4.432
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;
19
20
use PhpOffice\PhpPresentation\Writer\PowerPoint2007;
21
22
/**
23
 * \PhpOffice\PhpPresentation\Writer\PowerPoint2007\Theme
24
 */
25
class Theme extends AbstractPart
26
{
27
    /**
28
     * Write theme to XML format
29
     *
30
     * @param  int $masterId
31
     * @throws \Exception
32
     * @return string XML Output
33
     */
34 60
    public function writeTheme($masterId = 1)
35
    {
36
        // Write theme from layout pack
37 60
        $parentWriter = $this->getParentWriter();
38 60
        if ($parentWriter instanceof PowerPoint2007) {
39 60
            $layoutPack     = $parentWriter->getLayoutPack();
40 60
            foreach ($layoutPack->getThemes() as $theme) {
41 60
                if ($theme['masterid'] == $masterId) {
42 60
                    return $theme['body'];
43
                }
44
            }
45
            throw new \Exception('No theme has been found!');
46
        }
47
    }
48
}
49