Skip to content

Commit a19b554

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

File tree

5 files changed

+40
-42
lines changed

5 files changed

+40
-42
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: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
namespace PhpOffice\PhpWord\Writer\Word2007\Element;
1919

20+
use PhpOffice\PhpWord\Element\Field as ElementField;
21+
use PhpOffice\PhpWord\Element\TextRun;
22+
2023
/**
2124
* Field element writer.
2225
*
@@ -30,7 +33,7 @@ class Field extends Text
3033
public function write(): void
3134
{
3235
$element = $this->getElement();
33-
if (!$element instanceof \PhpOffice\PhpWord\Element\Field) {
36+
if (!$element instanceof ElementField) {
3437
return;
3538
}
3639

@@ -42,7 +45,7 @@ public function write(): void
4245
}
4346
}
4447

45-
private function writeDefault(\PhpOffice\PhpWord\Element\Field $element): void
48+
private function writeDefault(ElementField $element): void
4649
{
4750
$xmlWriter = $this->getXmlWriter();
4851
$this->startElementP();
@@ -73,7 +76,7 @@ private function writeDefault(\PhpOffice\PhpWord\Element\Field $element): void
7376
$xmlWriter->endElement(); // w:r
7477

7578
if ($element->getText() != null) {
76-
if ($element->getText() instanceof \PhpOffice\PhpWord\Element\TextRun) {
79+
if ($element->getText() instanceof TextRun) {
7780
$containerWriter = new Container($xmlWriter, $element->getText(), true);
7881
$containerWriter->write();
7982

@@ -120,7 +123,7 @@ private function writeDefault(\PhpOffice\PhpWord\Element\Field $element): void
120123
*
121124
* //TODO A lot of code duplication with general method, should maybe be refactored
122125
*/
123-
protected function writeMacrobutton(\PhpOffice\PhpWord\Element\Field $element): void
126+
protected function writeMacrobutton(ElementField $element): void
124127
{
125128
$xmlWriter = $this->getXmlWriter();
126129
$this->startElementP();
@@ -159,7 +162,7 @@ protected function writeMacrobutton(\PhpOffice\PhpWord\Element\Field $element):
159162
$this->endElementP(); // w:p
160163
}
161164

162-
private function buildPropertiesAndOptions(\PhpOffice\PhpWord\Element\Field $element)
165+
private function buildPropertiesAndOptions(ElementField $element)
163166
{
164167
$propertiesAndOptions = '';
165168
$properties = $element->getProperties();
@@ -228,11 +231,9 @@ private function buildPropertiesAndOptions(\PhpOffice\PhpWord\Element\Field $ele
228231
}
229232

230233
/**
231-
* Writes a REF field
232-
*
233-
* @param \PhpOffice\PhpWord\Element\Field $element
234+
* Writes a REF field.
234235
*/
235-
protected function writeRef(\PhpOffice\PhpWord\Element\Field $element)
236+
protected function writeRef(ElementField $element): void
236237
{
237238
$xmlWriter = $this->getXmlWriter();
238239
$this->startElementP();
@@ -303,7 +304,7 @@ protected function writeRef(\PhpOffice\PhpWord\Element\Field $element)
303304
$this->endElementP(); // w:p
304305
}
305306

306-
private function convertRefOption($optionKey, $optionValue)
307+
private function convertRefOption(string $optionKey, string $optionValue): string
307308
{
308309
if ($optionKey === 'NumberSeperatorSequence') {
309310
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)