Skip to content

Commit

Permalink
remove new lines
Browse files Browse the repository at this point in the history
  • Loading branch information
sibalonat committed Nov 30, 2023
1 parent e6ba84a commit c90df91
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/PhpWord/IOFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public static function extractVariables(string $filename, $readerName = 'Word200
$extractedVariables = [];
foreach ($document->getSections() as $section) {
$concatenatedText = '';

foreach ($section->getElements() as $element) {
if ($element instanceof TextRun) {
foreach ($element->getElements() as $textElement) {
Expand All @@ -121,17 +120,14 @@ public static function extractVariables(string $filename, $readerName = 'Word200
$concatenatedText .= $text;
}
}

preg_match_all('/\$\{([^}]+)\}/', $concatenatedText, $matches);

if (!empty($matches[1])) {
foreach ($matches[1] as $match) {
$trimmedMatch = trim($match);
$extractedVariables[] = $trimmedMatch;
}
}
}

return $extractedVariables;
}

Expand Down
3 changes: 0 additions & 3 deletions tests/PhpWordTests/IOFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,8 @@ public function testLoad(): void
public function testExtractVariables(): void
{
$file = __DIR__ . '/_files/templates/extract-variable.docx';

$extractedVariables = IOFactory::extractVariables($file, 'Word2007');

$expectedVariables = ['date', 'A1', 'B1'];

self::assertEquals($expectedVariables, $extractedVariables, 'Extracted variables do not match expected variables.');
}
}

0 comments on commit c90df91

Please sign in to comment.