CS Fixer
This commit is contained in:
parent
46e61d4c18
commit
f482f2600b
@ -761,12 +761,6 @@ class TemplateProcessor
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a table row in a template document.
|
* Delete a table row in a template document.
|
||||||
*
|
|
||||||
* @param string $search
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
|
||||||
*/
|
*/
|
||||||
public function deleteRow(string $search): void
|
public function deleteRow(string $search): void
|
||||||
{
|
{
|
||||||
@ -776,7 +770,7 @@ class TemplateProcessor
|
|||||||
|
|
||||||
$tagPos = strpos($this->tempDocumentMainPart, $search);
|
$tagPos = strpos($this->tempDocumentMainPart, $search);
|
||||||
if (!$tagPos) {
|
if (!$tagPos) {
|
||||||
throw new Exception(sprintf("Can not delete row %s, template variable not found or variable contains markup.", $search));
|
throw new Exception(sprintf('Can not delete row %s, template variable not found or variable contains markup.', $search));
|
||||||
}
|
}
|
||||||
|
|
||||||
$tableStart = $this->findTableStart($tagPos);
|
$tableStart = $this->findTableStart($tagPos);
|
||||||
@ -1151,21 +1145,21 @@ class TemplateProcessor
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the start position of the nearest table before $offset.
|
* Find the start position of the nearest table before $offset.
|
||||||
*
|
|
||||||
* @param integer $offset
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*
|
|
||||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
|
||||||
*/
|
*/
|
||||||
protected function findTableStart(int $offset): int
|
protected function findTableStart(int $offset): int
|
||||||
{
|
{
|
||||||
$rowStart = strrpos($this->tempDocumentMainPart, '<w:tbl ',
|
$rowStart = strrpos(
|
||||||
((strlen($this->tempDocumentMainPart) - $offset) * -1));
|
$this->tempDocumentMainPart,
|
||||||
|
'<w:tbl ',
|
||||||
|
((strlen($this->tempDocumentMainPart) - $offset) * -1)
|
||||||
|
);
|
||||||
|
|
||||||
if (!$rowStart) {
|
if (!$rowStart) {
|
||||||
$rowStart = strrpos($this->tempDocumentMainPart, '<w:tbl>',
|
$rowStart = strrpos(
|
||||||
((strlen($this->tempDocumentMainPart) - $offset) * -1));
|
$this->tempDocumentMainPart,
|
||||||
|
'<w:tbl>',
|
||||||
|
((strlen($this->tempDocumentMainPart) - $offset) * -1)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (!$rowStart) {
|
if (!$rowStart) {
|
||||||
throw new Exception('Can not find the start position of the table.');
|
throw new Exception('Can not find the start position of the table.');
|
||||||
@ -1175,12 +1169,8 @@ class TemplateProcessor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the end position of the nearest table row after $offset.
|
* Find the end position of the nearest table row after $offset.
|
||||||
*
|
*/
|
||||||
* @param integer $offset
|
|
||||||
*
|
|
||||||
* @return integer
|
|
||||||
*/
|
|
||||||
protected function findTableEnd(int $offset): int
|
protected function findTableEnd(int $offset): int
|
||||||
{
|
{
|
||||||
return strpos($this->tempDocumentMainPart, '</w:tbl>', $offset) + 7;
|
return strpos($this->tempDocumentMainPart, '</w:tbl>', $offset) + 7;
|
||||||
|
|||||||
@ -183,30 +183,29 @@ final class TemplateProcessorTest extends \PHPUnit\Framework\TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::getVariables
|
|
||||||
* @covers ::deleteRow
|
* @covers ::deleteRow
|
||||||
|
* @covers ::getVariables
|
||||||
* @covers ::saveAs
|
* @covers ::saveAs
|
||||||
* @test
|
|
||||||
*/
|
*/
|
||||||
public function testDeleteRow(): void
|
public function testDeleteRow(): void
|
||||||
{
|
{
|
||||||
$templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/delete-row.docx');
|
$templateProcessor = new TemplateProcessor(__DIR__ . '/_files/templates/delete-row.docx');
|
||||||
|
|
||||||
$this->assertEquals(
|
self::assertEquals(
|
||||||
array('deleteMe', 'deleteMeToo'),
|
['deleteMe', 'deleteMeToo'],
|
||||||
$templateProcessor->getVariables()
|
$templateProcessor->getVariables()
|
||||||
);
|
);
|
||||||
|
|
||||||
$docName = 'delete-row-test-result.docx';
|
$docName = 'delete-row-test-result.docx';
|
||||||
$templateProcessor->deleteRow('deleteMe');
|
$templateProcessor->deleteRow('deleteMe');
|
||||||
$this->assertEquals(
|
self::assertEquals(
|
||||||
array(),
|
[],
|
||||||
$templateProcessor->getVariables()
|
$templateProcessor->getVariables()
|
||||||
);
|
);
|
||||||
$templateProcessor->saveAs($docName);
|
$templateProcessor->saveAs($docName);
|
||||||
$docFound = file_exists($docName);
|
$docFound = file_exists($docName);
|
||||||
unlink($docName);
|
unlink($docName);
|
||||||
$this->assertTrue($docFound);
|
self::assertTrue($docFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user