Skip to content

Commit 3b7dac4

Browse files
committed
Refactored PHPWord_Exception to namespaces
1 parent 0c5e405 commit 3b7dac4

17 files changed

+212
-207
lines changed

Classes/PHPWord.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
}
3535
// @codeCoverageIgnoreEnd
3636

37+
use PhpOffice\PhpWord\Exceptions\Exception;
38+
3739
/**
3840
* PHPWord
3941
*/
@@ -252,17 +254,15 @@ public function getSections()
252254
*
253255
* @param string $strFilename
254256
* @return PHPWord_Template
257+
* @throws Exception
255258
*/
256259
public function loadTemplate($strFilename)
257260
{
258261
if (file_exists($strFilename)) {
259262
$template = new PHPWord_Template($strFilename);
260263
return $template;
261-
} else {
262-
throw new PHPWord_Exception(
263-
"Template file {$strFilename} not found."
264-
);
265264
}
265+
throw new Exception("Template file {$strFilename} not found.");
266266
}
267267

268268
/**

Classes/PHPWord/Exception.php

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace PhpOffice\PhpWord\Exceptions;
3+
4+
/**
5+
* Class Exception
6+
*/
7+
class Exception extends \Exception
8+
{
9+
}

Classes/PHPWord/Exceptions/InvalidImageException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
namespace PhpOffice\PhpWord\Exceptions;
33

4-
use Exception;
5-
64
/**
75
* InvalidImageException
86
*

Classes/PHPWord/Exceptions/InvalidStyleException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
*/
1313
class InvalidStyleException extends InvalidArgumentException
1414
{
15-
}
15+
}

Classes/PHPWord/Exceptions/UnsupportedImageTypeException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22
namespace PhpOffice\PhpWord\Exceptions;
33

4-
use Exception;
5-
64
/**
75
* UnsupportedImageTypeException
86
*

Classes/PHPWord/IOFactory.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525
* @version 0.8.0
2626
*/
2727

28+
use PhpOffice\PhpWord\Exceptions\Exception;
29+
2830
/**
2931
* Class PHPWord_IOFactory
3032
*/
3133
class PHPWord_IOFactory
3234
{
33-
3435
/**
3536
* Search locations
3637
*
@@ -73,13 +74,9 @@ public static function getSearchLocations()
7374
* @param array $value
7475
* @throws Exception
7576
*/
76-
public static function setSearchLocations($value)
77+
public static function setSearchLocations(array $value)
7778
{
78-
if (is_array($value)) {
79-
self::$_searchLocations = $value;
80-
} else {
81-
throw new Exception('Invalid parameter passed.');
82-
}
79+
self::$_searchLocations = $value;
8380
}
8481

8582
/**
@@ -100,6 +97,7 @@ public static function addSearchLocation($type = '', $location = '', $classname
10097
* @param PHPWord $PHPWord
10198
* @param string $writerType Example: Word2007
10299
* @return PHPWord_Writer_IWriter
100+
* @throws Exception
103101
*/
104102
public static function createWriter(PHPWord $PHPWord, $writerType = '')
105103
{
@@ -123,8 +121,9 @@ public static function createWriter(PHPWord $PHPWord, $writerType = '')
123121
/**
124122
* Create PHPWord_Reader_IReader
125123
*
126-
* @param string $readerType Example: Word2007
127-
* @return PHPWord_Reader_IReader
124+
* @param string $readerType Example: Word2007
125+
* @return PHPWord_Reader_IReader
126+
* @throws Exception
128127
*/
129128
public static function createReader($readerType = '')
130129
{
@@ -141,18 +140,19 @@ public static function createReader($readerType = '')
141140
}
142141
}
143142

144-
throw new PHPWord_Exception("No $searchType found for type $readerType");
143+
throw new Exception("No $searchType found for type $readerType");
145144
}
146145

147146
/**
148147
* Loads PHPWord from file
149148
*
150-
* @param string $pFilename The name of the file
151-
* @return PHPWord
149+
* @param string $pFilename The name of the file
150+
* @param string $readerType
151+
* @return PHPWord
152152
*/
153153
public static function load($pFilename, $readerType = 'Word2007')
154154
{
155155
$reader = self::createReader($readerType);
156156
return $reader->load($pFilename);
157157
}
158-
}
158+
}

Classes/PHPWord/Reader/Abstract.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
* @version 0.8.0
2626
*/
2727

28+
use PhpOffice\PhpWord\Exceptions\Exception;
29+
2830
/**
2931
* PHPWord_Reader_Abstract
3032
*
@@ -35,17 +37,19 @@ abstract class PHPWord_Reader_Abstract implements PHPWord_Reader_IReader
3537
/**
3638
* Read data only?
3739
*
38-
* @var boolean
40+
* @var bool
3941
*/
4042
protected $readDataOnly = true;
4143

44+
/**
45+
* @var bool|resource
46+
*/
4247
protected $fileHandle = true;
4348

44-
4549
/**
4650
* Read data only?
4751
*
48-
* @return boolean
52+
* @return bool
4953
*/
5054
public function getReadDataOnly()
5155
{
@@ -56,8 +60,8 @@ public function getReadDataOnly()
5660
/**
5761
* Set read data only
5862
*
59-
* @param boolean $pValue
60-
* @return PHPWord_Reader_IReader
63+
* @param bool $pValue
64+
* @return PHPWord_Reader_IReader
6165
*/
6266
public function setReadDataOnly($pValue = true)
6367
{
@@ -69,29 +73,28 @@ public function setReadDataOnly($pValue = true)
6973
* Open file for reading
7074
*
7175
* @param string $pFilename
72-
* @throws PHPWord_Exception
7376
* @return resource
77+
* @throws Exception
7478
*/
7579
protected function openFile($pFilename)
7680
{
7781
// Check if file exists
7882
if (!file_exists($pFilename) || !is_readable($pFilename)) {
79-
throw new PHPWord_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
83+
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
8084
}
8185

8286
// Open file
8387
$this->fileHandle = fopen($pFilename, 'r');
8488
if ($this->fileHandle === false) {
85-
throw new PHPWord_Exception("Could not open file " . $pFilename . " for reading.");
89+
throw new Exception("Could not open file " . $pFilename . " for reading.");
8690
}
8791
}
8892

8993
/**
9094
* Can the current PHPWord_Reader_IReader read the file?
9195
*
92-
* @param string $pFilename
93-
* @return boolean
94-
* @throws PHPWord_Exception
96+
* @param string $pFilename
97+
* @return bool
9598
*/
9699
public function canRead($pFilename)
97100
{
@@ -102,6 +105,6 @@ public function canRead($pFilename)
102105
return false;
103106
}
104107
fclose($this->fileHandle);
105-
return $readable;
108+
return true;
106109
}
107-
}
110+
}

0 commit comments

Comments
 (0)