Skip to content

Commit 52a7cbc

Browse files
oleibmanProgi1984
authored andcommitted
Indentation Changes
Makes no sense to multiply by 720 when supplied in array to Paragraph, but left unchanged when supplied directly. Skip multiplication.
1 parent 4fe91e0 commit 52a7cbc

File tree

4 files changed

+14
-32
lines changed

4 files changed

+14
-32
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,36 +1760,11 @@ parameters:
17601760
count: 1
17611761
path: tests/PhpWordTests/Style/FontTest.php
17621762

1763-
-
1764-
message: "#^Binary operation \"\\*\" between 1\\|120\\|240\\|'atLeast'\\|'auto'\\|'Normal'\\|'numStyle'\\|bool and 720 results in an error\\.$#"
1765-
count: 1
1766-
path: tests/PhpWordTests/Style/ParagraphTest.php
1767-
17681763
-
17691764
message: "#^Cannot call method setLineHeight\\(\\) on PhpOffice\\\\PhpWord\\\\Style\\\\Paragraph\\|string\\.$#"
17701765
count: 1
17711766
path: tests/PhpWordTests/Style/ParagraphTest.php
17721767

1773-
-
1774-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\Style\\\\ParagraphTest\\:\\:findGetter\\(\\) has no return type specified\\.$#"
1775-
count: 1
1776-
path: tests/PhpWordTests/Style/ParagraphTest.php
1777-
1778-
-
1779-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\Style\\\\ParagraphTest\\:\\:findGetter\\(\\) has parameter \\$key with no type specified\\.$#"
1780-
count: 1
1781-
path: tests/PhpWordTests/Style/ParagraphTest.php
1782-
1783-
-
1784-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\Style\\\\ParagraphTest\\:\\:findGetter\\(\\) has parameter \\$object with no type specified\\.$#"
1785-
count: 1
1786-
path: tests/PhpWordTests/Style/ParagraphTest.php
1787-
1788-
-
1789-
message: "#^Method PhpOffice\\\\PhpWordTests\\\\Style\\\\ParagraphTest\\:\\:findGetter\\(\\) has parameter \\$value with no type specified\\.$#"
1790-
count: 1
1791-
path: tests/PhpWordTests/Style/ParagraphTest.php
1792-
17931768
-
17941769
message: "#^Parameter \\#2 \\$value of method PhpOffice\\\\PhpWord\\\\Style\\\\AbstractStyle\\:\\:setStyleValue\\(\\) expects array\\|int\\|string, bool given\\.$#"
17951770
count: 1

src/PhpWord/Style/Paragraph.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ class Paragraph extends Border
199199
public function setStyleValue($key, $value)
200200
{
201201
$key = Text::removeUnderscorePrefix($key);
202-
if ('indent' == $key || 'hanging' == $key) {
203-
$value = $value * 720; // 720 twips is 0.5 inch
204-
}
202+
//if ('indent' == $key || 'hanging' == $key) {
203+
// $value = $value * 720; // 720 twips is 0.5 inch
204+
//}
205205

206206
return parent::setStyleValue($key, $value);
207207
}

src/PhpWord/Writer/HTML/Style/Paragraph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function write()
9595
}
9696
$ind = $style->getIndentation();
9797
if ($ind != null) {
98-
$tcpdf = $this->getParentWriter()->isTcpdf();
98+
$tcpdf = ($this->getParentWriter() === null) ? false : $this->getParentWriter()->isTcpdf(); // @phpstan-ignore-line
9999
$left = $ind->getLeft();
100100
$inches = $left * 1.0 / \PhpOffice\PhpWord\Shared\Converter::INCH_TO_TWIP;
101101
$css[$tcpdf ? 'text-indent' : 'margin-left'] = ((string) $inches) . 'in';

tests/PhpWordTests/Style/ParagraphTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,20 @@ public function testSetStyleValueNormal(): void
9191
foreach ($attributes as $key => $value) {
9292
$get = $this->findGetter($key, $value, $object);
9393
$object->setStyleValue("$key", $value);
94-
if ('indent' == $key || 'hanging' == $key) {
95-
$value = $value * 720;
96-
}
94+
//if ('indent' == $key || 'hanging' == $key) {
95+
// $value = $value * 720;
96+
//}
9797
self::assertEquals($value, $object->$get());
9898
}
9999
}
100100

101+
/**
102+
* @param string $key
103+
* @param mixed $value
104+
* @param object $object
105+
*
106+
* @return string
107+
*/
101108
private function findGetter($key, $value, $object)
102109
{
103110
if (is_bool($value)) {

0 commit comments

Comments
 (0)