Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractPart
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 setParentWriter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getParentWriter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 write
n/a
0 / 0
n/a
0 / 0
0
 encodeText
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\Writer\WPS\Part;
20
21use PhpOffice\PhpWord\Writer\AbstractWriter;
22use PhpOffice\PhpWord\Writer\WriterPartInterface;
23
24/**
25 * Abstract class for WPS parts.
26 *
27 * @since 1.5.0
28 */
29abstract class AbstractPart implements WriterPartInterface
30{
31    /**
32     * Parent writer.
33     *
34     * @var AbstractWriter
35     */
36    protected $parentWriter;
37
38    /**
39     * Set parent writer.
40     */
41    public function setParentWriter(AbstractWriter $writer): void
42    {
43        $this->parentWriter = $writer;
44    }
45
46    /**
47     * Get parent writer.
48     */
49    public function getParentWriter(): AbstractWriter
50    {
51        return $this->parentWriter;
52    }
53
54    /**
55     * Write part content.
56     */
57    abstract public function write(): string;
58
59    /**
60     * Convert a text to the UTF-16LE encoding used by the WPS format.
61     */
62    protected function encodeText(string $text): string
63    {
64        return (string) mb_convert_encoding($text, 'UTF-16LE', 'UTF-8');
65    }
66}