Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Comments
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 read
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3namespace PhpOffice\PhpWord\Reader\Word2007;
4
5use DateTime;
6use PhpOffice\PhpWord\Element\Comment;
7use PhpOffice\PhpWord\PhpWord;
8use PhpOffice\PhpWord\Shared\XMLReader;
9
10class Comments extends AbstractPart
11{
12    /**
13     * Collection name comments.
14     *
15     * @var string
16     */
17    protected $collection = 'comments';
18
19    /**
20     * Read settings.xml.
21     */
22    public function read(PhpWord $phpWord): void
23    {
24        $xmlReader = new XMLReader();
25        $xmlReader->getDomFromZip($this->docFile, $this->xmlFile);
26
27        $comments = $phpWord->getComments();
28
29        $nodes = $xmlReader->getElements('*');
30
31        foreach ($nodes as $node) {
32            $name = str_replace('w:', '', $node->nodeName);
33
34            $author = $xmlReader->getAttribute('w:author', $node);
35            $date = $xmlReader->getAttribute('w:date', $node);
36            $initials = $xmlReader->getAttribute('w:initials', $node);
37
38            $element = new Comment($author, new DateTime($date), $initials);
39
40            $range = $this->getCommentReference($xmlReader->getAttribute('w:id', $node));
41            if ($range['start']) {
42                $range['start']->setCommentRangeStart($element);
43            }
44            if ($range['end']) {
45                $range['end']->setCommentRangeEnd($element);
46            }
47
48            $pNodes = $xmlReader->getElements('w:p/w:r', $node);
49            foreach ($pNodes as $pNode) {
50                $this->readRun($xmlReader, $pNode, $element, $this->collection);
51            }
52
53            $phpWord->getComments()->addItem($element);
54        }
55    }
56}