Skip to content

Commit 4f1ce84

Browse files
committed
Rebase & Fixed CI
1 parent 2404cc8 commit 4f1ce84

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed

docs/changes/2.x/2.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- IOFactory : Added extractVariables method to extract variables from a document [@sibalonat](https://github.com/sibalonat) in [#2515](https://github.com/PHPOffice/PHPWord/pull/2515)
88
- PDF Writer : Documented how to specify a PDF renderer, when working with the PDF writer, as well as the three available choices by [@settermjd](https://github.com/settermjd) in [#2642](https://github.com/PHPOffice/PHPWord/pull/2642)
99
- Word2007 Reader: Support for Paragraph Border Style by [@damienfa](https://github.com/damienfa) in [#2651](https://github.com/PHPOffice/PHPWord/pull/2651)
10+
- Word2007 Writer: Support for field REF by [@crystoline](https://github.com/crystoline) in [#2652](https://github.com/PHPOffice/PHPWord/pull/2652)
1011

1112
### Bug fixes
1213

docs/usage/elements/field.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ For instance for the INDEX field, you can do the following (See `Index Field for
2626
``` php
2727
<?php
2828

29-
//the $fieldText can be either a simple string
29+
// the $fieldText can be either a simple string
3030
$fieldText = 'The index value';
3131

32-
//or a 'TextRun', to be able to format the text you want in the index
32+
// or a 'TextRun', to be able to format the text you want in the index
3333
$fieldText = new TextRun();
3434
$fieldText->addText('My ');
3535
$fieldText->addText('bold index', ['bold' => true]);
3636
$fieldText->addText(' entry');
3737
$section->addField('XE', array(), array(), $fieldText);
3838

39-
//this actually adds the index
39+
// this actually adds the index
4040
$section->addField('INDEX', array(), array('\\e " " \\h "A" \\c "3"'), 'right click to update index');
4141

42-
//Adding reference to a bookmark
42+
// Adding reference to a bookmark
4343
$fieldText->addField('REF', [
44-
'name' => 'bookmark'
45-
], [
46-
'InsertParagraphNumberRelativeContext',
47-
'CreateHyperLink',
48-
]);
44+
'name' => 'bookmark'
45+
], [
46+
'InsertParagraphNumberRelativeContext',
47+
'CreateHyperLink',
48+
]);
4949
```

src/PhpWord/Element/Field.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ class Field extends AbstractElement
9191
],
9292
'options' => ['Path', 'PreserveFormat'],
9393
],
94-
'REF' => array(
95-
'properties' => array('name' => ''),
96-
'options' => array('f', 'h', 'n', 'p', 'r', 't', 'w'),
97-
),
94+
'REF' => [
95+
'properties' => ['name' => ''],
96+
'options' => ['f', 'h', 'n', 'p', 'r', 't', 'w'],
97+
],
9898
];
9999

100100
/**

src/PhpWord/Writer/Word2007/Element/Field.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,9 @@ private function buildPropertiesAndOptions(\PhpOffice\PhpWord\Element\Field $ele
228228
}
229229

230230
/**
231-
* Writes a REF field
232-
*
233-
* @param \PhpOffice\PhpWord\Element\Field $element
231+
* Writes a REF field.
234232
*/
235-
protected function writeRef(\PhpOffice\PhpWord\Element\Field $element)
233+
protected function writeRef(\PhpOffice\PhpWord\Element\Field $element): void
236234
{
237235
$xmlWriter = $this->getXmlWriter();
238236
$this->startElementP();
@@ -303,7 +301,7 @@ protected function writeRef(\PhpOffice\PhpWord\Element\Field $element)
303301
$this->endElementP(); // w:p
304302
}
305303

306-
private function convertRefOption($optionKey, $optionValue)
304+
private function convertRefOption(string $optionKey, string $optionValue): string
307305
{
308306
if ($optionKey === 'NumberSeperatorSequence') {
309307
return '\\d ' . $optionValue;

tests/PhpWord/Writer/Word2007/Element/FieldTest.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@
33
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
44

55
use PhpOffice\PhpWord\PhpWord;
6-
use PhpOffice\PhpWord\TestHelperDOCX;
6+
use PhpOffice\PhpWordTests\TestHelperDOCX;
77
use PHPUnit\Framework\TestCase;
88

99
/**
10-
* Test class for PhpOffice\PhpWord\Writer\Word2007\Field
10+
* Test class for PhpOffice\PhpWord\Writer\Word2007\Field.
1111
*/
1212
class FieldTest extends TestCase
1313
{
1414
/**
15-
* Executed before each method of the class
15+
* Executed before each method of the class.
1616
*/
17-
public function tearDown()
17+
protected function tearDown(): void
1818
{
1919
TestHelperDOCX::clear();
2020
}
2121

2222
/**
23-
* Test Field write
23+
* Test Field write.
2424
*/
25-
public function testWriteWithRefType()
25+
public function testWriteWithRefType(): void
2626
{
2727
$phpWord = new PhpWord();
2828
$section = $phpWord->addSection();
2929
$section->addField(
3030
'REF',
31-
array(
31+
[
3232
'name' => 'my-bookmark',
33-
),
34-
array(
33+
],
34+
[
3535
'InsertParagraphNumberRelativeContext',
3636
'CreateHyperLink',
37-
)
37+
]
3838
);
3939

4040
$section->addListItem('line one item');
@@ -45,18 +45,14 @@ public function testWriteWithRefType()
4545
$doc = TestHelperDOCX::getDocument($phpWord, 'Word2007');
4646

4747
$refFieldPath = '/w:document/w:body/w:p[1]/w:r[2]/w:instrText';
48-
49-
$this->assertTrue($doc->elementExists($refFieldPath));
48+
self::assertTrue($doc->elementExists($refFieldPath));
5049

5150
$bookMarkElement = $doc->getElement($refFieldPath);
52-
53-
$this->assertNotNull($bookMarkElement);
54-
55-
$this->assertEquals(' REF my-bookmark \r \h ', $bookMarkElement->textContent);
51+
self::assertNotNull($bookMarkElement);
52+
self::assertEquals(' REF my-bookmark \r \h ', $bookMarkElement->textContent);
5653

5754
$bookmarkPath = '/w:document/w:body/w:bookmarkStart';
58-
59-
$this->assertTrue($doc->elementExists($bookmarkPath));
60-
$this->assertEquals('my-bookmark', $doc->getElementAttribute("$bookmarkPath", 'w:name'));
55+
self::assertTrue($doc->elementExists($bookmarkPath));
56+
self::assertEquals('my-bookmark', $doc->getElementAttribute("$bookmarkPath", 'w:name'));
6157
}
6258
}

0 commit comments

Comments
 (0)