Skip to content

Commit 1e968b2

Browse files
authored
Merge pull request #54 from PHPOffice/develop
Merge `master` from `develop`
2 parents 6b5c03a + 1f70f65 commit 1e968b2

20 files changed

+121
-115
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
strategy:
4848
fail-fast: false
4949
matrix:
50-
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
50+
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
5151
steps:
5252
- name: Setup PHP
5353
uses: shivammathur/setup-php@v2
@@ -68,7 +68,7 @@ jobs:
6868
strategy:
6969
fail-fast: false
7070
matrix:
71-
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
71+
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
7272
steps:
7373
- name: Setup PHP
7474
uses: shivammathur/setup-php@v2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PHPOffice Common is a library written in pure PHP that provides a set of compone
1010

1111
PHPOffice Common is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/Common/blob/develop/COPYING.LESSER). PHPOffice Common is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/Common) and [unit testing](http://phpoffice.github.io/Common/coverage/develop/). You can learn more about PHPPowerPoint by reading the [API Documentation](http://phpoffice.github.io/Common/docs/develop/).
1212

13-
Read more about PHPPowerPoint:
13+
Read more about PHPOffice Common:
1414

1515
- [Requirements](#requirements)
1616
- [Contributing](#contributing)

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,16 @@
2121
"require-dev": {
2222
"phpunit/phpunit": ">=7",
2323
"phpmd/phpmd": "2.*",
24-
"phpstan/phpstan": "^0.12.88"
24+
"phpstan/phpstan": "^0.12.88 || ^1.0.0"
2525
},
2626
"autoload": {
2727
"psr-4": {
2828
"PhpOffice\\Common\\": "src/Common/"
2929
}
30+
},
31+
"autoload-dev": {
32+
"psr-4": {
33+
"PhpOffice\\Common\\Tests\\": "tests/Common/Tests"
34+
}
3035
}
3136
}

phpunit.xml.dist

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
convertErrorsToExceptions="true"
66
convertNoticesToExceptions="true"
77
convertWarningsToExceptions="true"
8+
convertDeprecationsToExceptions="true"
89
processIsolation="false"
910
stopOnFailure="false">
11+
<coverage>
12+
<include>
13+
<directory suffix=".php">./src</directory>
14+
</include>
15+
<report>
16+
<clover outputFile="./build/logs/clover.xml"/>
17+
<html outputDirectory="./build/coverage"/>
18+
</report>
19+
</coverage>
1020
<testsuites>
1121
<testsuite name="PhpOffice Common Test Suite">
1222
<directory>./tests/Common</directory>
1323
</testsuite>
1424
</testsuites>
15-
<filter>
16-
<whitelist>
17-
<directory suffix=".php">./src</directory>
18-
</whitelist>
19-
</filter>
20-
<logging>
21-
<log type="coverage-clover" target="./build/clover.xml" />
22-
</logging>
2325
</phpunit>

src/Common/Adapter/Zip/PclZipAdapter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace PhpOffice\Common\Adapter\Zip;
44

5-
use PclZip;
6-
75
class PclZipAdapter implements ZipInterface
86
{
97
/**
10-
* @var PclZip
8+
* @var \PclZip
119
*/
1210
protected $oPclZip;
1311

@@ -18,7 +16,7 @@ class PclZipAdapter implements ZipInterface
1816

1917
public function open($filename)
2018
{
21-
$this->oPclZip = new PclZip($filename);
19+
$this->oPclZip = new \PclZip($filename);
2220
$this->tmpDir = sys_get_temp_dir();
2321

2422
return $this;

src/Common/Adapter/Zip/ZipArchiveAdapter.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace PhpOffice\Common\Adapter\Zip;
44

5-
use ZipArchive;
6-
75
class ZipArchiveAdapter implements ZipInterface
86
{
97
/**
10-
* @var ZipArchive
8+
* @var \ZipArchive
119
*/
1210
protected $oZipArchive;
1311

@@ -19,12 +17,12 @@ class ZipArchiveAdapter implements ZipInterface
1917
public function open($filename)
2018
{
2119
$this->filename = $filename;
22-
$this->oZipArchive = new ZipArchive();
20+
$this->oZipArchive = new \ZipArchive();
2321

24-
if ($this->oZipArchive->open($this->filename, ZipArchive::OVERWRITE) === true) {
22+
if ($this->oZipArchive->open($this->filename, \ZipArchive::OVERWRITE) === true) {
2523
return $this;
2624
}
27-
if ($this->oZipArchive->open($this->filename, ZipArchive::CREATE) === true) {
25+
if ($this->oZipArchive->open($this->filename, \ZipArchive::CREATE) === true) {
2826
return $this;
2927
}
3028
throw new \Exception("Could not open $this->filename for writing.");

src/Common/Drawing.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static function pointsToPixels(float $pValue = 0): float
118118
*/
119119
public static function pixelsToCentimeters(int $pValue = 0): float
120120
{
121-
//return $pValue * 0.028;
121+
// return $pValue * 0.028;
122122
return ($pValue / self::DPI_96) * 2.54;
123123
}
124124

@@ -135,7 +135,7 @@ public static function centimetersToPixels(float $pValue = 0): int
135135
return 0;
136136
}
137137

138-
return (int) round((($pValue / 2.54) * self::DPI_96));
138+
return (int) round(($pValue / 2.54) * self::DPI_96);
139139
}
140140

141141
/**
@@ -259,7 +259,7 @@ public static function pointsToEmu(float $pValue = 0): int
259259
return 0;
260260
}
261261

262-
return (int) round(($pValue / 0.75) / 9525);
262+
return (int) round(($pValue / 0.75) * 9525);
263263
}
264264

265265
/**

src/Common/File.php

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

1818
namespace PhpOffice\Common;
1919

20-
use ZipArchive;
21-
2220
class File
2321
{
2422
/**
@@ -38,7 +36,7 @@ public static function fileExists(string $pFilename): bool
3836
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
3937
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
4038

41-
$zip = new ZipArchive();
39+
$zip = new \ZipArchive();
4240
if ($zip->open($zipFile) === true) {
4341
$returnValue = ($zip->getFromName($archiveFile) !== false);
4442
$zip->close();
@@ -70,7 +68,7 @@ public static function fileGetContents(string $pFilename): ?string
7068
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
7169
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);
7270

73-
$zip = new ZipArchive();
71+
$zip = new \ZipArchive();
7472
if ($zip->open($zipFile) === true) {
7573
$returnValue = $zip->getFromName($archiveFile);
7674
$zip->close();
@@ -80,6 +78,7 @@ public static function fileGetContents(string $pFilename): ?string
8078

8179
return null;
8280
}
81+
8382
// Regular file contents
8483
return file_get_contents($pFilename);
8584
}

src/Common/Microsoft/PasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class PasswordEncoder
4949
self::ALGORITHM_MAC => [5, ''], // 'mac' -> not possible with hash()
5050
self::ALGORITHM_RIPEMD => [6, 'ripemd'],
5151
self::ALGORITHM_RIPEMD_160 => [7, 'ripemd160'],
52-
self::ALGORITHM_HMAC => [9, ''], //'hmac' -> not possible with hash()
52+
self::ALGORITHM_HMAC => [9, ''], // 'hmac' -> not possible with hash()
5353
self::ALGORITHM_SHA_256 => [12, 'sha256'],
5454
self::ALGORITHM_SHA_384 => [13, 'sha384'],
5555
self::ALGORITHM_SHA_512 => [14, 'sha512'],

src/Common/XMLReader.php

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
namespace PhpOffice\Common;
1919

2020
use DOMDocument;
21-
use DOMElement;
22-
use DOMNodeList;
2321
use DOMXpath;
2422
use ZipArchive;
2523

@@ -33,24 +31,24 @@ class XMLReader
3331
/**
3432
* DOMDocument object
3533
*
36-
* @var DOMDocument
34+
* @var \DOMDocument
3735
*/
38-
private $dom = null;
36+
private $dom;
3937

4038
/**
4139
* DOMXpath object
4240
*
43-
* @var DOMXpath
41+
* @var \DOMXpath
4442
*/
45-
private $xpath = null;
43+
private $xpath;
4644

4745
/**
4846
* Get DOMDocument from ZipArchive
4947
*
5048
* @param string $zipFile
5149
* @param string $xmlFile
5250
*
53-
* @return DOMDocument|false
51+
* @return \DOMDocument|false
5452
*
5553
* @throws \Exception
5654
*/
@@ -60,9 +58,15 @@ public function getDomFromZip(string $zipFile, string $xmlFile)
6058
throw new \Exception('Cannot find archive file.');
6159
}
6260

63-
$zip = new ZipArchive();
61+
$zip = new \ZipArchive();
6462
$zip->open($zipFile);
6563
$content = $zip->getFromName($xmlFile);
64+
65+
// Files downloaded from Sharepoint are somehow different and fail on the leading slash.
66+
if ($content === false && substr($xmlFile, 0, 1) === '/') {
67+
$content = $zip->getFromName(substr($xmlFile, 1));
68+
}
69+
6670
$zip->close();
6771

6872
if ($content === false) {
@@ -77,7 +81,7 @@ public function getDomFromZip(string $zipFile, string $xmlFile)
7781
*
7882
* @param string $content
7983
*
80-
* @return DOMDocument
84+
* @return \DOMDocument
8185
*/
8286
public function getDomFromString(string $content)
8387
{
@@ -86,7 +90,7 @@ public function getDomFromString(string $content)
8690
$originalLibXMLEntityValue = libxml_disable_entity_loader(true);
8791
}
8892

89-
$this->dom = new DOMDocument();
93+
$this->dom = new \DOMDocument();
9094
$this->dom->loadXML($content);
9195

9296
if (\PHP_VERSION_ID < 80000) {
@@ -100,17 +104,17 @@ public function getDomFromString(string $content)
100104
* Get elements
101105
*
102106
* @param string $path
103-
* @param DOMElement $contextNode
107+
* @param \DOMElement $contextNode
104108
*
105-
* @return DOMNodeList<DOMElement>
109+
* @return \DOMNodeList<\DOMElement>
106110
*/
107-
public function getElements(string $path, DOMElement $contextNode = null)
111+
public function getElements(string $path, \DOMElement $contextNode = null)
108112
{
109113
if ($this->dom === null) {
110-
return new DOMNodeList();
114+
return new \DOMNodeList();
111115
}
112116
if ($this->xpath === null) {
113-
$this->xpath = new DOMXpath($this->dom);
117+
$this->xpath = new \DOMXpath($this->dom);
114118
}
115119

116120
if (is_null($contextNode)) {
@@ -136,7 +140,7 @@ public function registerNamespace($prefix, $namespaceURI)
136140
throw new \InvalidArgumentException('Dom needs to be loaded before registering a namespace');
137141
}
138142
if ($this->xpath === null) {
139-
$this->xpath = new DOMXpath($this->dom);
143+
$this->xpath = new \DOMXpath($this->dom);
140144
}
141145

142146
return $this->xpath->registerNamespace($prefix, $namespaceURI);
@@ -146,15 +150,15 @@ public function registerNamespace($prefix, $namespaceURI)
146150
* Get element
147151
*
148152
* @param string $path
149-
* @param DOMElement $contextNode
153+
* @param \DOMElement $contextNode
150154
*
151-
* @return DOMElement|null
155+
* @return \DOMElement|null
152156
*/
153-
public function getElement($path, DOMElement $contextNode = null): ?DOMElement
157+
public function getElement($path, \DOMElement $contextNode = null): ?\DOMElement
154158
{
155159
$elements = $this->getElements($path, $contextNode);
156160
if ($elements->length > 0) {
157-
return $elements->item(0) instanceof DOMElement ? $elements->item(0) : null;
161+
return $elements->item(0) instanceof \DOMElement ? $elements->item(0) : null;
158162
}
159163

160164
return null;
@@ -164,18 +168,18 @@ public function getElement($path, DOMElement $contextNode = null): ?DOMElement
164168
* Get element attribute
165169
*
166170
* @param string $attribute
167-
* @param DOMElement $contextNode
171+
* @param \DOMElement $contextNode
168172
* @param string $path
169173
*
170174
* @return string|null
171175
*/
172-
public function getAttribute($attribute, DOMElement $contextNode = null, $path = null)
176+
public function getAttribute($attribute, \DOMElement $contextNode = null, $path = null)
173177
{
174178
$return = null;
175179
if ($path !== null) {
176180
$elements = $this->getElements($path, $contextNode);
177181
if ($elements->length > 0) {
178-
/** @var DOMElement $node Type hint */
182+
/** @var \DOMElement $node Type hint */
179183
$node = $elements->item(0);
180184
$return = $node->getAttribute($attribute);
181185
}
@@ -192,11 +196,11 @@ public function getAttribute($attribute, DOMElement $contextNode = null, $path =
192196
* Get element value
193197
*
194198
* @param string $path
195-
* @param DOMElement $contextNode
199+
* @param \DOMElement $contextNode
196200
*
197201
* @return string|null
198202
*/
199-
public function getValue($path, DOMElement $contextNode = null)
203+
public function getValue($path, \DOMElement $contextNode = null)
200204
{
201205
$elements = $this->getElements($path, $contextNode);
202206
if ($elements->length > 0) {
@@ -210,11 +214,11 @@ public function getValue($path, DOMElement $contextNode = null)
210214
* Count elements
211215
*
212216
* @param string $path
213-
* @param DOMElement $contextNode
217+
* @param \DOMElement $contextNode
214218
*
215219
* @return int
216220
*/
217-
public function countElements($path, DOMElement $contextNode = null)
221+
public function countElements($path, \DOMElement $contextNode = null)
218222
{
219223
$elements = $this->getElements($path, $contextNode);
220224

@@ -225,11 +229,11 @@ public function countElements($path, DOMElement $contextNode = null)
225229
* Element exists
226230
*
227231
* @param string $path
228-
* @param DOMElement $contextNode
232+
* @param \DOMElement $contextNode
229233
*
230234
* @return bool
231235
*/
232-
public function elementExists($path, DOMElement $contextNode = null)
236+
public function elementExists($path, \DOMElement $contextNode = null)
233237
{
234238
return $this->getElements($path, $contextNode)->length > 0;
235239
}

0 commit comments

Comments
 (0)