Skip to content

Commit 8745c5e

Browse files
committed
Change behaviour of set... function of boolean properties; Some bug fixing based on Scrutinizer; New Row Word2007 style writer
1 parent 4b1a160 commit 8745c5e

File tree

25 files changed

+251
-148
lines changed

25 files changed

+251
-148
lines changed

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tools:
1818
enabled: true
1919
timeout: 900
2020
php_sim:
21-
min_mass: 30
21+
min_mass: 16
2222
php_pdepend: true
2323
php_analyzer: true
2424
sensiolabs_security_checker: true

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3; new r
4242
- QA: Add `.scrutinizer.yml` and include `composer.lock` for preparation to Scrutinizer - @ivanlanin GH-186
4343
- Writer: Refactor writer parts using composite pattern - @ivanlanin
4444
- Docs: Show code quality and test code coverage badge on README
45+
- Style: Change behaviour of `set...` function of boolean properties; when none is defined, assumed true - @ivanlanin
4546

4647
## 0.10.0 - 4 May 2014
4748

phpmd.xml.dist

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
<rule ref="rulesets/design.xml/ExitExpression" />
99
<rule ref="rulesets/design.xml/EvalExpression" />
1010
<rule ref="rulesets/design.xml/GotoStatement" />
11-
<rule ref="rulesets/design.xml/NumberOfChildren" />
1211
<rule ref="rulesets/design.xml/DepthOfInheritance" />
13-
<rule ref="rulesets/design.xml/CouplingBetweenObjects">
12+
<rule ref="rulesets/design.xml/CouplingBetweenObjects" />
13+
<rule ref="rulesets/design.xml/NumberOfChildren">
14+
<!-- AbstractElement and AbstractStyle still needs a lot of children classes -->
1415
<properties>
15-
<property name="minimum" value="15" />
16+
<property name="minimum" value="20" />
1617
</properties>
1718
</rule>
1819
<rule ref="rulesets/unusedcode.xml" />

samples/Sample_09_Tables.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
// 3. colspan (gridSpan) and rowspan (vMerge)
5353

54-
$section->addTextBreak(1);
54+
$section->addPageBreak();
5555
$section->addText("Table with colspan and rowspan", $header);
5656

5757
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');

samples/Sample_25_TextBox.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$section = $phpWord->addSection();
99

1010
// In section
11-
$textbox = $section->addTextBox(array('align' => 'left', 'width' => 400, 'height' => 150, 'borderSize' => 1, 'borderColor' => '#FF0000'));
11+
$textbox = $section->addTextBox(array('align' => 'center', 'width' => 400, 'height' => 150, 'borderSize' => 1, 'borderColor' => '#FF0000'));
1212
$textbox->addText('Text box content in section.');
1313
$textbox->addText('Another line.');
1414
$cell = $textbox->addTable()->addRow()->addCell();
@@ -22,7 +22,7 @@
2222

2323
// Inside header with textrun
2424
$header = $section->addHeader();
25-
$textbox = $header->addTextBox(array('align' => 'center', 'width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
25+
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
2626
$textrun = $textbox->addTextRun();
2727
$textrun->addText('TextBox in header. TextBox can contain a TextRun ');
2828
$textrun->addText('with bold text', array('bold' => true));

src/PhpWord/Shared/Html.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ protected static function parseNode(
219219
$text = $cNode->nodeValue;
220220
}
221221
}
222-
$object->addListItem($text, $data['listdepth'], $styles['fontStyle'], $styles['listStyle'], $styles['paragraphStyle']);
222+
$object->addListItem(
223+
$text,
224+
$data['listdepth'],
225+
$styles['fontStyle'],
226+
$styles['listStyle'],
227+
$styles['paragraphStyle']
228+
);
223229
}
224230
}
225231

src/PhpWord/Style/AbstractStyle.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ protected function setNonEmptyVal($value, $default)
152152
}
153153

154154
/**
155-
* Set boolean value
155+
* Set bool value
156156
*
157-
* @param mixed $value
158-
* @param boolean|null $default
159-
* @return boolean|null
157+
* @param bool $value
158+
* @param bool $default
159+
* @return bool
160160
*/
161-
protected function setBoolVal($value, $default = null)
161+
protected function setBoolVal($value, $default)
162162
{
163163
if (!is_bool($value)) {
164164
$value = $default;
@@ -184,7 +184,7 @@ protected function setNumericVal($value, $default = null)
184184
}
185185

186186
/**
187-
* Set float value: Convert string that contains only numeric into integer
187+
* Set integer value: Convert string that contains only numeric into integer
188188
*
189189
* @param mixed $value
190190
* @param int|null $default

src/PhpWord/Style/Font.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public function isBold()
333333
* @param bool $value
334334
* @return self
335335
*/
336-
public function setBold($value = false)
336+
public function setBold($value = true)
337337
{
338338
$this->bold = $this->setBoolVal($value, $this->bold);
339339

@@ -356,7 +356,7 @@ public function isItalic()
356356
* @param bool $value
357357
* @return self
358358
*/
359-
public function setItalic($value = false)
359+
public function setItalic($value = true)
360360
{
361361
$this->italic = $this->setBoolVal($value, $this->italic);
362362

@@ -402,7 +402,7 @@ public function isSuperScript()
402402
* @param bool $value
403403
* @return self
404404
*/
405-
public function setSuperScript($value = false)
405+
public function setSuperScript($value = true)
406406
{
407407
$this->superScript = $this->setBoolVal($value, $this->superScript);
408408
$this->toggleFalse($this->subScript, $this->superScript);
@@ -426,13 +426,10 @@ public function isSubScript()
426426
* @param bool $value
427427
* @return self
428428
*/
429-
public function setSubScript($value = false)
429+
public function setSubScript($value = true)
430430
{
431431
$this->subScript = $this->setBoolVal($value, $this->subScript);
432432
$this->toggleFalse($this->subScript, $this->superScript);
433-
if ($this->subScript) {
434-
$this->superScript = false;
435-
}
436433

437434
return $this;
438435
}
@@ -453,7 +450,7 @@ public function isStrikethrough()
453450
* @param bool $value
454451
* @return self
455452
*/
456-
public function setStrikethrough($value = false)
453+
public function setStrikethrough($value = true)
457454
{
458455
$this->strikethrough = $this->setBoolVal($value, $this->strikethrough);
459456
$this->toggleFalse($this->doubleStrikethrough, $this->strikethrough);
@@ -477,7 +474,7 @@ public function isDoubleStrikethrough()
477474
* @param bool $value
478475
* @return self
479476
*/
480-
public function setDoubleStrikethrough($value = false)
477+
public function setDoubleStrikethrough($value = true)
481478
{
482479
$this->doubleStrikethrough = $this->setBoolVal($value, $this->doubleStrikethrough);
483480
$this->toggleFalse($this->strikethrough, $this->doubleStrikethrough);
@@ -501,7 +498,7 @@ public function isSmallCaps()
501498
* @param bool $value
502499
* @return self
503500
*/
504-
public function setSmallCaps($value = false)
501+
public function setSmallCaps($value = true)
505502
{
506503
$this->smallCaps = $this->setBoolVal($value, $this->smallCaps);
507504
$this->toggleFalse($this->allCaps, $this->smallCaps);
@@ -525,7 +522,7 @@ public function isAllCaps()
525522
* @param bool $value
526523
* @return self
527524
*/
528-
public function setAllCaps($value = false)
525+
public function setAllCaps($value = true)
529526
{
530527
$this->allCaps = $this->setBoolVal($value, $this->allCaps);
531528
$this->toggleFalse($this->smallCaps, $this->allCaps);

src/PhpWord/Style/Image.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ class Image extends AbstractStyle
9494
/**
9595
* Alignment
9696
*
97-
* @var string
97+
* @var \PhpOffice\PhpWord\Style\Alignment
9898
*/
99-
private $align;
99+
private $alignment;
100100

101101
/**
102102
* Margin Top
@@ -154,8 +154,18 @@ class Image extends AbstractStyle
154154
*/
155155
private $posVerticalRel = self::POSITION_RELATIVE_TO_LINE;
156156

157+
/**
158+
* Create new instance
159+
*/
160+
public function __construct()
161+
{
162+
$this->alignment = new Alignment();
163+
}
164+
157165
/**
158166
* Get width
167+
*
168+
* @return int
159169
*/
160170
public function getWidth()
161171
{
@@ -166,14 +176,19 @@ public function getWidth()
166176
* Set width
167177
*
168178
* @param int $value
179+
* @return self
169180
*/
170181
public function setWidth($value = null)
171182
{
172183
$this->width = $value;
184+
185+
return $this;
173186
}
174187

175188
/**
176189
* Get height
190+
*
191+
* @return int
177192
*/
178193
public function getHeight()
179194
{
@@ -184,32 +199,40 @@ public function getHeight()
184199
* Set height
185200
*
186201
* @param int $value
202+
* @return self
187203
*/
188204
public function setHeight($value = null)
189205
{
190206
$this->height = $value;
207+
208+
return $this;
191209
}
192210

193211
/**
194212
* Get alignment
213+
*
214+
* @return string
195215
*/
196216
public function getAlign()
197217
{
198-
return $this->align;
218+
return $this->alignment->getValue();
199219
}
200220

201221
/**
202222
* Set alignment
203223
*
204224
* @param string $value
225+
* @return self
205226
*/
206227
public function setAlign($value = null)
207228
{
208-
$this->align = $value;
229+
$this->alignment->setValue($value);
230+
231+
return $this;
209232
}
210233

211234
/**
212-
* Get Margin Top
235+
* Get margin top
213236
*
214237
* @return int
215238
*/
@@ -219,19 +242,20 @@ public function getMarginTop()
219242
}
220243

221244
/**
222-
* Set Margin Top
245+
* Set margin top
223246
*
224247
* @param int $value
225248
* @return self
226249
*/
227250
public function setMarginTop($value = null)
228251
{
229252
$this->marginTop = $value;
253+
230254
return $this;
231255
}
232256

233257
/**
234-
* Get Margin Left
258+
* Get margin left
235259
*
236260
* @return int
237261
*/
@@ -241,14 +265,15 @@ public function getMarginLeft()
241265
}
242266

243267
/**
244-
* Set Margin Left
268+
* Set margin left
245269
*
246270
* @param int $value
247271
* @return self
248272
*/
249273
public function setMarginLeft($value = null)
250274
{
251275
$this->marginLeft = $value;
276+
252277
return $this;
253278
}
254279

src/PhpWord/Style/Paragraph.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public function isKeepNext()
420420
* @param bool $value
421421
* @return self
422422
*/
423-
public function setKeepNext($value = false)
423+
public function setKeepNext($value = true)
424424
{
425425
$this->keepNext = $this->setBoolVal($value, $this->keepNext);
426426

@@ -443,7 +443,7 @@ public function isKeepLines()
443443
* @param bool $value
444444
* @return self
445445
*/
446-
public function setKeepLines($value = false)
446+
public function setKeepLines($value = true)
447447
{
448448
$this->keepLines = $this->setBoolVal($value, $this->keepLines);
449449

@@ -466,7 +466,7 @@ public function hasPageBreakBefore()
466466
* @param bool $value
467467
* @return self
468468
*/
469-
public function setPageBreakBefore($value = false)
469+
public function setPageBreakBefore($value = true)
470470
{
471471
$this->pageBreakBefore = $this->setBoolVal($value, $this->pageBreakBefore);
472472

0 commit comments

Comments
 (0)