Skip to content

Commit 92c7a24

Browse files
committed
QA: Additional unit tests and docblock fixes
1 parent dc6c487 commit 92c7a24

27 files changed

+289
-138
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
4343
- `Writer\Word2007\Part`: `Numbering::writeNumbering()`, `Settings::writeSettings()`, `WebSettings::writeWebSettings()`, `ContentTypes::writeContentTypes()`, `Styles::writeStyles()`, `Document::writeDocument()` all changed into `write()`
4444
- `Writer\Word2007\Part\DocProps`: Split into `Writer\Word2007\Part\DocPropsCore` and `Writer\Word2007\Part\DocPropsApp`
4545
- `Element\Title::getBookmarkId()` replaced by `Element\Title::getRelationId()`
46+
- `Writer\HTML::writeDocument`: Replaced by `Writer\HTML::getContent`
4647

4748
### Miscellaneous
4849

src/PhpWord/Autoloader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
class Autoloader
2424
{
25+
/** @const string */
2526
const NAMESPACE_PREFIX = 'PhpOffice\\PhpWord\\';
2627

2728
/**

src/PhpWord/DocumentProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
class DocumentProperties
2424
{
25-
/** Constants */
25+
/** @const string Property type constants */
2626
const PROPERTY_TYPE_BOOLEAN = 'b';
2727
const PROPERTY_TYPE_INTEGER = 'i';
2828
const PROPERTY_TYPE_FLOAT = 'f';

src/PhpWord/Shared/XMLWriter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ public function __construct($tempLocation = self::STORAGE_MEMORY, $tempFolder =
6868
// Create temporary filename
6969
$this->tempFile = @tempnam($tempFolder, 'xml');
7070

71-
// Open storage
71+
// Fallback to memory when temporary file cannot be used
7272
if ($this->xmlWriter->openUri($this->tempFile) === false) {
73-
// Fallback to memory...
7473
$this->xmlWriter->openMemory();
7574
}
7675
}
@@ -105,9 +104,16 @@ public function __destruct()
105104
*
106105
* @param mixed $function
107106
* @param mixed $args
107+
* @throws \BadMethodCallException
108108
*/
109109
public function __call($function, $args)
110110
{
111+
// Catch exception
112+
if (method_exists($this->xmlWriter, $function) === false) {
113+
throw new \BadMethodCallException("Method '{$function}' does not exists.");
114+
}
115+
116+
// Run method
111117
try {
112118
@call_user_func_array(array($this->xmlWriter, $function), $args);
113119
} catch (\Exception $ex) {

src/PhpWord/Style/AbstractStyle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ protected function setEnumVal($value = null, $enum = array(), $default = null)
265265
{
266266
if ($value != null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) {
267267
throw new \InvalidArgumentException('Invalid style value.');
268-
} elseif (is_null($value) || trim($value) == '') {
268+
} elseif ($value === null || trim($value) == '') {
269269
$value = $default;
270270
}
271271

src/PhpWord/Style/Cell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function setTextDirection($value = null)
144144
*/
145145
public function getBgColor()
146146
{
147-
if (!is_null($this->shading)) {
147+
if ($this->shading !== null) {
148148
return $this->shading->getFill();
149149
} else {
150150
return null;

src/PhpWord/Style/Font.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ public function setFgColor($value = null)
540540
*/
541541
public function getBgColor()
542542
{
543-
if (!is_null($this->shading)) {
543+
if ($this->shading !== null) {
544544
return $this->shading->getFill();
545545
} else {
546546
return null;

src/PhpWord/Style/LineNumbering.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
/**
2121
* Line numbering style
2222
*
23-
* @link http://www.schemacentral.com/sc/ooxml/e-w_lnNumType-1.html
23+
* @link http://www.schemacentral.com/sc/ooxml/t-w_CT_LineNumber.html
2424
* @since 0.10.0
2525
*/
2626
class LineNumbering extends AbstractStyle
2727
{
28+
/** @const string Line numbering restart setting http://www.schemacentral.com/sc/ooxml/a-w_restart-1.html */
2829
const LINE_NUMBERING_CONTINUOUS = 'continuous';
2930
const LINE_NUMBERING_NEW_PAGE = 'newPage';
3031
const LINE_NUMBERING_NEW_SECTION = 'newSection';

src/PhpWord/Style/ListItem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class ListItem extends AbstractStyle
6565
*/
6666
public function __construct($numStyle = null)
6767
{
68-
if (!is_null($numStyle)) {
68+
if ($numStyle !== null) {
6969
$this->setNumStyle($numStyle);
7070
} else {
7171
$this->setListType();
@@ -149,7 +149,7 @@ private function getListTypeStyle()
149149
{
150150
// Check if legacy style already registered in global Style collection
151151
$numStyle = "PHPWordList{$this->listType}";
152-
if (!is_null(Style::getStyle($numStyle))) {
152+
if (Style::getStyle($numStyle) !== null) {
153153
$this->setNumStyle($numStyle);
154154
return;
155155
}

src/PhpWord/Style/Paragraph.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function setAlign($value = null)
171171
*/
172172
public function getSpaceBefore()
173173
{
174-
if (!is_null($this->spacing)) {
174+
if ($this->spacing !== null) {
175175
return $this->spacing->getBefore();
176176
} else {
177177
return null;
@@ -196,7 +196,7 @@ public function setSpaceBefore($value = null)
196196
*/
197197
public function getSpaceAfter()
198198
{
199-
if (!is_null($this->spacing)) {
199+
if ($this->spacing !== null) {
200200
return $this->spacing->getAfter();
201201
} else {
202202
return null;
@@ -221,7 +221,7 @@ public function setSpaceAfter($value = null)
221221
*/
222222
public function getSpacing()
223223
{
224-
if (!is_null($this->spacing)) {
224+
if ($this->spacing !== null) {
225225
return $this->spacing->getLine();
226226
} else {
227227
return null;
@@ -278,7 +278,7 @@ public function setLineHeight($lineHeight)
278278
*/
279279
public function getIndent()
280280
{
281-
if (!is_null($this->indentation)) {
281+
if ($this->indentation !== null) {
282282
return $this->indentation->getLeft();
283283
} else {
284284
return null;
@@ -303,7 +303,7 @@ public function setIndent($value = null)
303303
*/
304304
public function getHanging()
305305
{
306-
if (!is_null($this->indentation)) {
306+
if ($this->indentation !== null) {
307307
return $this->indentation->getHanging();
308308
} else {
309309
return null;

0 commit comments

Comments
 (0)