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

PHPOffice / PHPWord / 6956347003

22 Nov 2023 11:00AM UTC coverage: 95.489% (+13.8%) from 81.642%
6956347003

push

github

web-flow
Merge pull request #2475 from oleibman/html_changes_5

Add Support for Various Missing Features in HTML Writer

350 of 355 new or added lines in 43 files covered. (98.59%)

3 existing lines in 1 file now uncovered.

11303 of 11837 relevant lines covered (95.49%)

30.23 hits per line

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

93.55
/src/PhpWord/Writer/HTML/Style/Table.php
1
<?php
2
/**
3
 * This file is part of PHPWord - A pure PHP library for reading and writing
4
 * word processing documents.
5
 *
6
 * PHPWord 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/PHPWord/contributors.
12
 *
13
 * @see         https://github.com/PHPOffice/PHPWord
14
 *
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
declare(strict_types=1);
18

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

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

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

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

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

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

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

80
        return $this->assembleCss($css);
5✔
81
    }
82
}
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