• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PHPWord / 13025401639

29 Jan 2025 05:48AM UTC coverage: 96.825% (-0.4%) from 97.217%
13025401639

Pull #2562

github

web-flow
Merge ebe3e5dac into 2d2759585
Pull Request #2562: TemplateProcessor SetComplexBlock/Value and Sections

6 of 7 new or added lines in 1 file covered. (85.71%)

245 existing lines in 40 files now uncovered.

12227 of 12628 relevant lines covered (96.82%)

34.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.94
/src/PhpWord/Writer/HTML/Style/Table.php
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
declare(strict_types=1);
19

20
namespace PhpOffice\PhpWord\Writer\HTML\Style;
21

22
use PhpOffice\PhpWord\Style\Cell as StyleCell;
23
use PhpOffice\PhpWord\Style\Table as StyleTable;
24

25
class Table extends AbstractStyle
26
{
27
    /**
28
     * @return string
29
     */
30
    public function write()
31
    {
32
        $style = $this->getStyle();
9✔
33
        if (!$style instanceof StyleTable && !$style instanceof StyleCell) {
9✔
34
            return '';
1✔
35
        }
36

37
        $css = [];
8✔
38
        if (is_object($style) && method_exists($style, 'getLayout')) {
8✔
39
            if ($style->getLayout() == StyleTable::LAYOUT_FIXED) {
2✔
40
                $css['table-layout'] = 'fixed';
1✔
41
            } elseif ($style->getLayout() == StyleTable::LAYOUT_AUTO) {
2✔
42
                $css['table-layout'] = 'auto';
2✔
43
            }
44
        }
45
        if (is_object($style) && method_exists($style, 'isBidiVisual')) {
8✔
46
            if ($style->isBidiVisual()) {
2✔
UNCOV
47
                $css['direction'] = 'rtl';
×
48
            }
49
        }
50
        if (is_object($style) && method_exists($style, 'getVAlign')) {
8✔
51
            $css['vertical-align'] = $style->getVAlign();
8✔
52
        }
53

54
        foreach (['Top', 'Left', 'Bottom', 'Right'] as $direction) {
8✔
55
            $method = 'getBorder' . $direction . 'Style';
8✔
56
            if (method_exists($style, $method)) {
8✔
57
                $outval = $style->{$method}();
8✔
58
                if ($outval === 'single') {
8✔
UNCOV
59
                    $outval = 'solid';
×
60
                }
61
                if (is_string($outval) && 1 == preg_match('/^[a-z]+$/', $outval)) {
8✔
62
                    $css['border-' . lcfirst($direction) . '-style'] = $outval;
1✔
63
                }
64
            }
65

66
            $method = 'getBorder' . $direction . 'Color';
8✔
67
            if (method_exists($style, $method)) {
8✔
68
                $outval = $style->{$method}();
8✔
69
                if (is_string($outval) && 1 == preg_match('/^[a-z]+$/', $outval)) {
8✔
70
                    $css['border-' . lcfirst($direction) . '-color'] = $outval;
1✔
71
                }
72
            }
73

74
            $method = 'getBorder' . $direction . 'Size';
8✔
75
            if (method_exists($style, $method)) {
8✔
76
                $outval = $style->{$method}();
8✔
77
                if (is_numeric($outval)) {
8✔
78
                    // size is in twips - divide by 20 to get points
79
                    $css['border-' . lcfirst($direction) . '-width'] = ((string) ($outval / 20)) . 'pt';
1✔
80
                }
81
            }
82
        }
83

84
        return $this->assembleCss($css);
8✔
85
    }
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc