Skip to content

Commit 4d9e406

Browse files
committed
QA: Scrutinizer dedup
1 parent 1c3735f commit 4d9e406

36 files changed

+136
-173
lines changed

src/PhpWord/Reader/AbstractReader.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,47 +54,47 @@ public function isReadDataOnly()
5454
/**
5555
* Set read data only
5656
*
57-
* @param bool $pValue
57+
* @param bool $value
5858
* @return self
5959
*/
60-
public function setReadDataOnly($pValue = true)
60+
public function setReadDataOnly($value = true)
6161
{
62-
$this->readDataOnly = $pValue;
62+
$this->readDataOnly = $value;
6363
return $this;
6464
}
6565

6666
/**
6767
* Open file for reading
6868
*
69-
* @param string $pFilename
69+
* @param string $filename
7070
* @return resource
7171
* @throws \PhpOffice\PhpWord\Exception\Exception
7272
*/
73-
protected function openFile($pFilename)
73+
protected function openFile($filename)
7474
{
7575
// Check if file exists
76-
if (!file_exists($pFilename) || !is_readable($pFilename)) {
77-
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
76+
if (!file_exists($filename) || !is_readable($filename)) {
77+
throw new Exception("Could not open " . $filename . " for reading! File does not exist.");
7878
}
7979

8080
// Open file
81-
$this->fileHandle = fopen($pFilename, 'r');
81+
$this->fileHandle = fopen($filename, 'r');
8282
if ($this->fileHandle === false) {
83-
throw new Exception("Could not open file " . $pFilename . " for reading.");
83+
throw new Exception("Could not open file " . $filename . " for reading.");
8484
}
8585
}
8686

8787
/**
8888
* Can the current ReaderInterface read the file?
8989
*
90-
* @param string $pFilename
90+
* @param string $filename
9191
* @return bool
9292
*/
93-
public function canRead($pFilename)
93+
public function canRead($filename)
9494
{
9595
// Check if file exists
9696
try {
97-
$this->openFile($pFilename);
97+
$this->openFile($filename);
9898
} catch (Exception $e) {
9999
return false;
100100
}

src/PhpWord/Reader/ODText/AbstractPart.php

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

2020
use PhpOffice\PhpWord\Shared\XMLReader;
21+
use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart;
2122

2223
/**
2324
* Abstract part reader
2425
*/
25-
abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractPart
26+
abstract class AbstractPart extends Word2007AbstractPart
2627
{
2728
/**
2829
* Read w:r (override)

src/PhpWord/Reader/ReaderInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ interface ReaderInterface
2525
/**
2626
* Can the current ReaderInterface read the file?
2727
*
28-
* @param string $pFilename
28+
* @param string $filename
2929
* @return boolean
3030
*/
31-
public function canRead($pFilename);
31+
public function canRead($filename);
3232

3333
/**
3434
* Loads PhpWord from file
3535
*
36-
* @param string $pFilename
36+
* @param string $filename
3737
*/
38-
public function load($pFilename);
38+
public function load($filename);
3939
}

src/PhpWord/Style/Font.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ public function setShading($value = null)
633633
* Set $property value and set $pairProperty = false when $value = true
634634
*
635635
* @param bool $property
636-
* @param bool $pair
636+
* @param bool $pairProperty
637637
* @param bool $value
638638
* @return self
639639
*/

src/PhpWord/Style/Table.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,19 @@ class Table extends Border
2929
const WIDTH_PERCENT = 'pct'; // Width in fiftieths (1/50) of a percent (1% = 50 unit)
3030
const WIDTH_TWIP = 'dxa'; // Width in twentieths (1/20) of a point (twip)
3131

32+
/**
33+
* Is this a first row style?
34+
*
35+
* @var bool
36+
*/
37+
private $isFirstRow = false;
38+
3239
/**
3340
* Style for first row
3441
*
3542
* @var \PhpOffice\PhpWord\Style\Table
3643
*/
37-
private $firstRow;
44+
private $firstRowStyle;
3845

3946
/**
4047
* Cell margin top
@@ -126,17 +133,18 @@ public function __construct($tableStyle = null, $firstRowStyle = null)
126133

127134
// Clone first row from table style, but with certain properties disabled
128135
if ($firstRowStyle !== null && is_array($firstRowStyle)) {
129-
$this->firstRow = clone $this;
130-
unset($this->firstRow->firstRow);
131-
unset($this->firstRow->borderInsideHSize);
132-
unset($this->firstRow->borderInsideHColor);
133-
unset($this->firstRow->borderInsideVSize);
134-
unset($this->firstRow->borderInsideVColor);
135-
unset($this->firstRow->cellMarginTop);
136-
unset($this->firstRow->cellMarginLeft);
137-
unset($this->firstRow->cellMarginRight);
138-
unset($this->firstRow->cellMarginBottom);
139-
$this->firstRow->setStyleByArray($firstRowStyle);
136+
$this->firstRowStyle = clone $this;
137+
$this->firstRowStyle->isFirstRow = true;
138+
unset($this->firstRowStyle->firstRowStyle);
139+
unset($this->firstRowStyle->borderInsideHSize);
140+
unset($this->firstRowStyle->borderInsideHColor);
141+
unset($this->firstRowStyle->borderInsideVSize);
142+
unset($this->firstRowStyle->borderInsideVColor);
143+
unset($this->firstRowStyle->cellMarginTop);
144+
unset($this->firstRowStyle->cellMarginLeft);
145+
unset($this->firstRowStyle->cellMarginRight);
146+
unset($this->firstRowStyle->cellMarginBottom);
147+
$this->firstRowStyle->setStyleByArray($firstRowStyle);
140148
}
141149

142150
if ($tableStyle !== null && is_array($tableStyle)) {
@@ -145,13 +153,13 @@ public function __construct($tableStyle = null, $firstRowStyle = null)
145153
}
146154

147155
/**
148-
* Get First Row Style
156+
* Set first row
149157
*
150158
* @return \PhpOffice\PhpWord\Style\Table
151159
*/
152160
public function getFirstRow()
153161
{
154-
return $this->firstRow;
162+
return $this->firstRowStyle;
155163
}
156164

157165
/**
@@ -556,7 +564,7 @@ public function setUnit($value = null)
556564
}
557565

558566
/**
559-
* Get table style only property by checking if firstRow is set
567+
* Get table style only property by checking if it's a firstRow
560568
*
561569
* This is necessary since firstRow style is cloned from table style but
562570
* without certain properties activated, e.g. margins
@@ -566,15 +574,15 @@ public function setUnit($value = null)
566574
*/
567575
private function getTableOnlyProperty($property)
568576
{
569-
if (isset($this->firstRow)) {
577+
if ($this->isFirstRow === false) {
570578
return $this->$property;
571579
}
572580

573581
return null;
574582
}
575583

576584
/**
577-
* Set table style only property by checking if firstRow is set
585+
* Set table style only property by checking if it's a firstRow
578586
*
579587
* This is necessary since firstRow style is cloned from table style but
580588
* without certain properties activated, e.g. margins
@@ -586,8 +594,8 @@ private function getTableOnlyProperty($property)
586594
*/
587595
private function setTableOnlyProperty($property, $value, $isNumeric = true)
588596
{
589-
if (isset($this->firstRow)) {
590-
if ($isNumeric) {
597+
if ($this->isFirstRow === false) {
598+
if ($isNumeric === true) {
591599
$this->$property = $this->setNumericVal($value, $this->$property);
592600
} else {
593601
$this->$property = $value;

src/PhpWord/Writer/AbstractWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ protected function addFileToPackage($objZip, $source, $target)
335335
$source = substr($source, 6);
336336
list($zipFilename, $imageFilename) = explode('#', $source);
337337

338-
$zipClass = \PhpOffice\PhpWord\Settings::getZipClass();
338+
$zipClass = Settings::getZipClass();
339339
$zip = new $zipClass();
340340
if ($zip->open($zipFilename) !== false) {
341341
if ($zip->locateName($imageFilename)) {

src/PhpWord/Writer/HTML.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,10 @@ public function __construct(PhpWord $phpWord = null)
6262
* Save PhpWord to file
6363
*
6464
* @param string $filename
65-
* @throws Exception
65+
* @throws \PhpOffice\PhpWord\Exception\Exception
6666
*/
6767
public function save($filename = null)
6868
{
69-
if (is_null($this->phpWord)) {
70-
throw new Exception('PhpWord object unassigned.');
71-
}
72-
7369
$this->setTempDir(sys_get_temp_dir() . '/PHPWordWriter/');
7470
$hFile = fopen($filename, 'w');
7571
if ($hFile !== false) {
@@ -111,7 +107,8 @@ public function writeDocument()
111107
*/
112108
private function writeHead()
113109
{
114-
$properties = $this->getPhpWord()->getDocumentProperties();
110+
$phpWord = $this->getPhpWord();
111+
$properties = $phpWord->getDocumentProperties();
115112
$propertiesMapping = array(
116113
'creator' => 'author',
117114
'title' => '',
@@ -171,13 +168,14 @@ private function writeBody()
171168
*/
172169
private function writeStyles()
173170
{
171+
$phpWord = $this->getPhpWord();
174172
$css = '<style>' . PHP_EOL;
175173

176174
// Default styles
177175
$defaultStyles = array(
178176
'*' => array(
179-
'font-family' => $this->getPhpWord()->getDefaultFontName(),
180-
'font-size' => $this->getPhpWord()->getDefaultFontSize() . 'pt',
177+
'font-family' => $phpWord->getDefaultFontName(),
178+
'font-size' => $phpWord->getDefaultFontSize() . 'pt',
181179
),
182180
'a.NoteRef' => array(
183181
'text-decoration' => 'none',

src/PhpWord/Writer/HTML/Element/Container.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace PhpOffice\PhpWord\Writer\HTML\Element;
1919

20+
use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement;
21+
2022
/**
2123
* Container element HTML writer
2224
*
@@ -39,7 +41,7 @@ class Container extends AbstractElement
3941
public function write()
4042
{
4143
$container = $this->element;
42-
if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) {
44+
if (!$container instanceof ContainerElement) {
4345
return '';
4446
}
4547
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);

src/PhpWord/Writer/HTML/Element/Image.php

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

2020
use PhpOffice\PhpWord\Element\Image as ImageElement;
21+
use PhpOffice\PhpWord\Settings;
2122
use PhpOffice\PhpWord\Writer\HTML\Style\Image as ImageStyleWriter;
2223

2324
/**
@@ -34,7 +35,7 @@ class Image extends Text
3435
*/
3536
public function write()
3637
{
37-
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) {
38+
if (!$this->element instanceof ImageElement) {
3839
return '';
3940
}
4041
/** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */
@@ -76,7 +77,7 @@ private function getBase64ImageData(ImageElement $element)
7677
$source = substr($source, 6);
7778
list($zipFilename, $imageFilename) = explode('#', $source);
7879

79-
$zipClass = \PhpOffice\PhpWord\Settings::getZipClass();
80+
$zipClass = Settings::getZipClass();
8081
$zip = new $zipClass();
8182
if ($zip->open($zipFilename) !== false) {
8283
if ($zip->locateName($imageFilename)) {

src/PhpWord/Writer/HTML/Style/Font.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Font extends AbstractStyle
3535
public function write()
3636
{
3737
$style = $this->getStyle();
38-
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) {
38+
if (!$style instanceof FontStyle) {
3939
return '';
4040
}
4141
$css = array();

0 commit comments

Comments
 (0)