Skip to content

Commit 553371f

Browse files
committed
Type hinting and docblock update
1 parent 32f1f62 commit 553371f

File tree

21 files changed

+117
-61
lines changed

21 files changed

+117
-61
lines changed

src/PhpWord/Element/AbstractContainer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ protected function addElement($elementName)
6262
$args[3] = null;
6363
}
6464

65-
// Create element
65+
// Create element dynamically
66+
67+
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
6668
if ($argsCount == 2) { // TextRun, TextBox, Table, Footnote, Endnote
6769
$element = new $elementClass($args[1]);
6870
} elseif ($argsCount == 3) { // Object, TextBreak, Title
@@ -88,6 +90,7 @@ protected function addElement($elementName)
8890
$element->setRelationId($rId);
8991
}
9092
if ($elementName == 'Object') {
93+
/** @var \PhpOffice\PhpWord\Element\Object $element Type hint */
9194
$rIdIcon = Media::addElement($mediaContainer, 'image', $element->getIcon(), new Image($element->getIcon()));
9295
$element->setImageRelationId($rIdIcon);
9396
}

src/PhpWord/Element/Row.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Row extends AbstractElement
4343
/**
4444
* Row cells
4545
*
46-
* @var array
46+
* @var \PhpOffice\PhpWord\Element\Cell[]
4747
*/
4848
private $cells = array();
4949

@@ -79,7 +79,7 @@ public function addCell($width = null, $style = null)
7979
/**
8080
* Get all cells
8181
*
82-
* @return array
82+
* @return \PhpOffice\PhpWord\Element\Cell[]
8383
*/
8484
public function getCells()
8585
{

src/PhpWord/Element/Section.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ private function addHeaderFooter($type = Header::AUTO, $header = true)
206206

207207
if (in_array($type, array(Header::AUTO, Header::FIRST, Header::EVEN))) {
208208
$index = count($collection);
209+
/** @var \PhpOffice\PhpWord\Element\AbstractContainer $container Type hint */
209210
$container = new $containerClass($this->sectionId, ++$index, $type);
210211
$container->setPhpWord($this->phpWord);
211212

src/PhpWord/Element/TOC.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function getTitles()
9595

9696
$titles = $this->phpWord->getTitles()->getItems();
9797
foreach ($titles as $i => $title) {
98+
/** @var \PhpOffice\PhpWord\Element\Title $title Type hint */
9899
$depth = $title->getDepth();
99100
if ($this->minDepth > $depth) {
100101
unset($titles[$i]);

src/PhpWord/Element/Table.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Table extends AbstractElement
3434
/**
3535
* Table rows
3636
*
37-
* @var array
37+
* @var \PhpOffice\PhpWord\Element\Row[]
3838
*/
3939
private $rows = array();
4040

@@ -83,15 +83,16 @@ public function addRow($height = null, $style = null)
8383
public function addCell($width = null, $style = null)
8484
{
8585
$index = count($this->rows) - 1;
86-
$cell = $this->rows[$index]->addCell($width, $style);
86+
$row = $this->rows[$index];
87+
$cell = $row->addCell($width, $style);
8788

8889
return $cell;
8990
}
9091

9192
/**
9293
* Get all rows
9394
*
94-
* @return array
95+
* @return \PhpOffice\PhpWord\Element\Row[]
9596
*/
9697
public function getRows()
9798
{
@@ -139,7 +140,9 @@ public function countColumns()
139140
if (is_array($this->rows)) {
140141
$rowCount = count($this->rows);
141142
for ($i = 0; $i < $rowCount; $i++) {
142-
$cellCount = count($this->rows[$i]->getCells());
143+
/** @var \PhpOffice\PhpWord\Element\Row $row Type hint */
144+
$row = $this->rows[$i];
145+
$cellCount = count($row->getCells());
143146
if ($columnCount < $cellCount) {
144147
$columnCount = $cellCount;
145148
}

src/PhpWord/Reader/ODText.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private function readPart(PhpWord &$phpWord, $relationships, $partName, $docFile
6262
{
6363
$partClass = "PhpOffice\\PhpWord\\Reader\\ODText\\{$partName}";
6464
if (class_exists($partClass)) {
65+
/** @var \PhpOffice\PhpWord\Reader\ODText\AbstractPart $part Type hint */
6566
$part = new $partClass($docFile, $xmlFile);
6667
$part->setRels($relationships);
6768
$part->read($phpWord);

src/PhpWord/Reader/Word2007.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
namespace PhpOffice\PhpWord\Reader;
1919

2020
use PhpOffice\PhpWord\PhpWord;
21-
use PhpOffice\PhpWord\Shared\ZipArchive;
2221
use PhpOffice\PhpWord\Shared\XMLReader;
22+
use PhpOffice\PhpWord\Shared\ZipArchive;
2323

2424
/**
2525
* Reader for Word2007
@@ -87,6 +87,7 @@ private function readPart(PhpWord &$phpWord, $relationships, $partName, $docFile
8787
{
8888
$partClass = "PhpOffice\\PhpWord\\Reader\\Word2007\\{$partName}";
8989
if (class_exists($partClass)) {
90+
/** @var \PhpOffice\PhpWord\Reader\Word2007\AbstractPart $part Type hint */
9091
$part = new $partClass($docFile, $xmlFile);
9192
$part->setRels($relationships);
9293
$part->read($phpWord);

src/PhpWord/Reader/Word2007/Document.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ private function readTable(XMLReader $xmlReader, \DOMElement $domNode, &$parent,
224224
$tblStyle = $this->readTableStyle($xmlReader, $domNode);
225225
}
226226

227+
/** @var \PhpOffice\PhpWord\Element\Table $table Type hint */
227228
$table = $parent->addTable($tblStyle);
228229
$tblNodes = $xmlReader->getElements('*', $domNode);
229230
foreach ($tblNodes as $tblNode) {

src/PhpWord/Shared/XMLReader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace PhpOffice\PhpWord\Shared;
1919

2020
use PhpOffice\PhpWord\Exception\Exception;
21-
use PhpOffice\PhpWord\Shared\ZipArchive;
2221

2322
/**
2423
* XML Reader wrapper
@@ -47,6 +46,7 @@ class XMLReader
4746
* @param string $zipFile
4847
* @param string $xmlFile
4948
* @return \DOMDocument|false
49+
* @throws \PhpOffice\PhpWord\Exception\Exception
5050
*/
5151
public function getDomFromZip($zipFile, $xmlFile)
5252
{
@@ -118,7 +118,9 @@ public function getAttribute($attribute, \DOMElement $contextNode = null, $path
118118
if ($path !== null) {
119119
$elements = $this->getElements($path, $contextNode);
120120
if ($elements->length > 0) {
121-
$return = $elements->item(0)->getAttribute($attribute);
121+
/** @var \DOMElement $node Type hint */
122+
$node = $elements->item(0);
123+
$return = $node->getAttribute($attribute);
122124
}
123125
} else {
124126
if ($contextNode !== null) {

src/PhpWord/Shared/XMLWriter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @method bool startDocument(string $version = 1.0, string $encoding = null, string $standalone = null)
2727
* @method bool startElement(string $name)
2828
* @method bool text(string $content)
29-
* @method bool writeAttribute(string $name, string $value)
29+
* @method bool writeAttribute(string $name, mixed $value)
3030
* @method bool writeElement(string $name, string $content = null)
3131
* @method bool writeRaw(string $content)
3232
*/
@@ -138,10 +138,10 @@ public function getData()
138138
/**
139139
* Write element if ...
140140
*
141-
* @param bool|null $condition
141+
* @param bool $condition
142142
* @param string $element
143143
* @param string $attribute
144-
* @param string $value
144+
* @param mixed $value
145145
*/
146146
public function writeElementIf($condition, $element, $attribute = null, $value = null)
147147
{
@@ -159,9 +159,9 @@ public function writeElementIf($condition, $element, $attribute = null, $value =
159159
/**
160160
* Write attribute if ...
161161
*
162-
* @param bool|null $condition
162+
* @param bool $condition
163163
* @param string $attribute
164-
* @param string $value
164+
* @param mixed $value
165165
*/
166166
public function writeAttributeIf($condition, $attribute, $value)
167167
{

0 commit comments

Comments
 (0)