Skip to content

Commit

Permalink
Merge pull request #54 from PHPOffice/develop
Browse files Browse the repository at this point in the history
Merge `master` from `develop`
  • Loading branch information
Progi1984 authored Dec 11, 2023
2 parents 6b5c03a + 1f70f65 commit 1e968b2
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -68,7 +68,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PHPOffice Common is a library written in pure PHP that provides a set of compone

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/).

Read more about PHPPowerPoint:
Read more about PHPOffice Common:

- [Requirements](#requirements)
- [Contributing](#contributing)
Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
"require-dev": {
"phpunit/phpunit": ">=7",
"phpmd/phpmd": "2.*",
"phpstan/phpstan": "^0.12.88"
"phpstan/phpstan": "^0.12.88 || ^1.0.0"
},
"autoload": {
"psr-4": {
"PhpOffice\\Common\\": "src/Common/"
}
},
"autoload-dev": {
"psr-4": {
"PhpOffice\\Common\\Tests\\": "tests/Common/Tests"
}
}
}
18 changes: 10 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="./build/logs/clover.xml"/>
<html outputDirectory="./build/coverage"/>
</report>
</coverage>
<testsuites>
<testsuite name="PhpOffice Common Test Suite">
<directory>./tests/Common</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="./build/clover.xml" />
</logging>
</phpunit>
6 changes: 2 additions & 4 deletions src/Common/Adapter/Zip/PclZipAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace PhpOffice\Common\Adapter\Zip;

use PclZip;

class PclZipAdapter implements ZipInterface
{
/**
* @var PclZip
* @var \PclZip
*/
protected $oPclZip;

Expand All @@ -18,7 +16,7 @@ class PclZipAdapter implements ZipInterface

public function open($filename)
{
$this->oPclZip = new PclZip($filename);
$this->oPclZip = new \PclZip($filename);
$this->tmpDir = sys_get_temp_dir();

return $this;
Expand Down
10 changes: 4 additions & 6 deletions src/Common/Adapter/Zip/ZipArchiveAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace PhpOffice\Common\Adapter\Zip;

use ZipArchive;

class ZipArchiveAdapter implements ZipInterface
{
/**
* @var ZipArchive
* @var \ZipArchive
*/
protected $oZipArchive;

Expand All @@ -19,12 +17,12 @@ class ZipArchiveAdapter implements ZipInterface
public function open($filename)
{
$this->filename = $filename;
$this->oZipArchive = new ZipArchive();
$this->oZipArchive = new \ZipArchive();

if ($this->oZipArchive->open($this->filename, ZipArchive::OVERWRITE) === true) {
if ($this->oZipArchive->open($this->filename, \ZipArchive::OVERWRITE) === true) {
return $this;
}
if ($this->oZipArchive->open($this->filename, ZipArchive::CREATE) === true) {
if ($this->oZipArchive->open($this->filename, \ZipArchive::CREATE) === true) {
return $this;
}
throw new \Exception("Could not open $this->filename for writing.");
Expand Down
6 changes: 3 additions & 3 deletions src/Common/Drawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static function pointsToPixels(float $pValue = 0): float
*/
public static function pixelsToCentimeters(int $pValue = 0): float
{
//return $pValue * 0.028;
// return $pValue * 0.028;
return ($pValue / self::DPI_96) * 2.54;
}

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

return (int) round((($pValue / 2.54) * self::DPI_96));
return (int) round(($pValue / 2.54) * self::DPI_96);
}

/**
Expand Down Expand Up @@ -259,7 +259,7 @@ public static function pointsToEmu(float $pValue = 0): int
return 0;
}

return (int) round(($pValue / 0.75) / 9525);
return (int) round(($pValue / 0.75) * 9525);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Common/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace PhpOffice\Common;

use ZipArchive;

class File
{
/**
Expand All @@ -38,7 +36,7 @@ public static function fileExists(string $pFilename): bool
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);

$zip = new ZipArchive();
$zip = new \ZipArchive();
if ($zip->open($zipFile) === true) {
$returnValue = ($zip->getFromName($archiveFile) !== false);
$zip->close();
Expand Down Expand Up @@ -70,7 +68,7 @@ public static function fileGetContents(string $pFilename): ?string
$zipFile = substr($pFilename, 6, strpos($pFilename, '#') - 6);
$archiveFile = substr($pFilename, strpos($pFilename, '#') + 1);

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

return null;
}

// Regular file contents
return file_get_contents($pFilename);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Microsoft/PasswordEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PasswordEncoder
self::ALGORITHM_MAC => [5, ''], // 'mac' -> not possible with hash()
self::ALGORITHM_RIPEMD => [6, 'ripemd'],
self::ALGORITHM_RIPEMD_160 => [7, 'ripemd160'],
self::ALGORITHM_HMAC => [9, ''], //'hmac' -> not possible with hash()
self::ALGORITHM_HMAC => [9, ''], // 'hmac' -> not possible with hash()
self::ALGORITHM_SHA_256 => [12, 'sha256'],
self::ALGORITHM_SHA_384 => [13, 'sha384'],
self::ALGORITHM_SHA_512 => [14, 'sha512'],
Expand Down
62 changes: 33 additions & 29 deletions src/Common/XMLReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
namespace PhpOffice\Common;

use DOMDocument;
use DOMElement;
use DOMNodeList;
use DOMXpath;
use ZipArchive;

Expand All @@ -33,24 +31,24 @@ class XMLReader
/**
* DOMDocument object
*
* @var DOMDocument
* @var \DOMDocument
*/
private $dom = null;
private $dom;

/**
* DOMXpath object
*
* @var DOMXpath
* @var \DOMXpath
*/
private $xpath = null;
private $xpath;

/**
* Get DOMDocument from ZipArchive
*
* @param string $zipFile
* @param string $xmlFile
*
* @return DOMDocument|false
* @return \DOMDocument|false
*
* @throws \Exception
*/
Expand All @@ -60,9 +58,15 @@ public function getDomFromZip(string $zipFile, string $xmlFile)
throw new \Exception('Cannot find archive file.');
}

$zip = new ZipArchive();
$zip = new \ZipArchive();
$zip->open($zipFile);
$content = $zip->getFromName($xmlFile);

// Files downloaded from Sharepoint are somehow different and fail on the leading slash.
if ($content === false && substr($xmlFile, 0, 1) === '/') {
$content = $zip->getFromName(substr($xmlFile, 1));
}

$zip->close();

if ($content === false) {
Expand All @@ -77,7 +81,7 @@ public function getDomFromZip(string $zipFile, string $xmlFile)
*
* @param string $content
*
* @return DOMDocument
* @return \DOMDocument
*/
public function getDomFromString(string $content)
{
Expand All @@ -86,7 +90,7 @@ public function getDomFromString(string $content)
$originalLibXMLEntityValue = libxml_disable_entity_loader(true);
}

$this->dom = new DOMDocument();
$this->dom = new \DOMDocument();
$this->dom->loadXML($content);

if (\PHP_VERSION_ID < 80000) {
Expand All @@ -100,17 +104,17 @@ public function getDomFromString(string $content)
* Get elements
*
* @param string $path
* @param DOMElement $contextNode
* @param \DOMElement $contextNode
*
* @return DOMNodeList<DOMElement>
* @return \DOMNodeList<\DOMElement>
*/
public function getElements(string $path, DOMElement $contextNode = null)
public function getElements(string $path, \DOMElement $contextNode = null)
{
if ($this->dom === null) {
return new DOMNodeList();
return new \DOMNodeList();
}
if ($this->xpath === null) {
$this->xpath = new DOMXpath($this->dom);
$this->xpath = new \DOMXpath($this->dom);
}

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

return $this->xpath->registerNamespace($prefix, $namespaceURI);
Expand All @@ -146,15 +150,15 @@ public function registerNamespace($prefix, $namespaceURI)
* Get element
*
* @param string $path
* @param DOMElement $contextNode
* @param \DOMElement $contextNode
*
* @return DOMElement|null
* @return \DOMElement|null
*/
public function getElement($path, DOMElement $contextNode = null): ?DOMElement
public function getElement($path, \DOMElement $contextNode = null): ?\DOMElement
{
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
return $elements->item(0) instanceof DOMElement ? $elements->item(0) : null;
return $elements->item(0) instanceof \DOMElement ? $elements->item(0) : null;
}

return null;
Expand All @@ -164,18 +168,18 @@ public function getElement($path, DOMElement $contextNode = null): ?DOMElement
* Get element attribute
*
* @param string $attribute
* @param DOMElement $contextNode
* @param \DOMElement $contextNode
* @param string $path
*
* @return string|null
*/
public function getAttribute($attribute, DOMElement $contextNode = null, $path = null)
public function getAttribute($attribute, \DOMElement $contextNode = null, $path = null)
{
$return = null;
if ($path !== null) {
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
/** @var DOMElement $node Type hint */
/** @var \DOMElement $node Type hint */
$node = $elements->item(0);
$return = $node->getAttribute($attribute);
}
Expand All @@ -192,11 +196,11 @@ public function getAttribute($attribute, DOMElement $contextNode = null, $path =
* Get element value
*
* @param string $path
* @param DOMElement $contextNode
* @param \DOMElement $contextNode
*
* @return string|null
*/
public function getValue($path, DOMElement $contextNode = null)
public function getValue($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);
if ($elements->length > 0) {
Expand All @@ -210,11 +214,11 @@ public function getValue($path, DOMElement $contextNode = null)
* Count elements
*
* @param string $path
* @param DOMElement $contextNode
* @param \DOMElement $contextNode
*
* @return int
*/
public function countElements($path, DOMElement $contextNode = null)
public function countElements($path, \DOMElement $contextNode = null)
{
$elements = $this->getElements($path, $contextNode);

Expand All @@ -225,11 +229,11 @@ public function countElements($path, DOMElement $contextNode = null)
* Element exists
*
* @param string $path
* @param DOMElement $contextNode
* @param \DOMElement $contextNode
*
* @return bool
*/
public function elementExists($path, DOMElement $contextNode = null)
public function elementExists($path, \DOMElement $contextNode = null)
{
return $this->getElements($path, $contextNode)->length > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/XMLWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function writeElementBlock(string $element, $attributes, string $value =
*
* @return void
*/
public function writeElementIf(bool $condition, string $element, ?string $attribute = null, $value = null)
public function writeElementIf(bool $condition, string $element, string $attribute = null, $value = null)
{
if ($condition) {
if (is_null($attribute)) {
Expand Down
Loading

0 comments on commit 1e968b2

Please sign in to comment.