Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for PHP 8.2 & 8.3 #52

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
4 changes: 2 additions & 2 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
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
56 changes: 27 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,7 +58,7 @@ 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);
$zip->close();
Expand All @@ -77,7 +75,7 @@ public function getDomFromZip(string $zipFile, string $xmlFile)
*
* @param string $content
*
* @return DOMDocument
* @return \DOMDocument
*/
public function getDomFromString(string $content)
{
Expand All @@ -86,7 +84,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 +98,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 +134,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 +144,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 +162,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 +190,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 +208,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 +223,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
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Common\Tests\Adapter\Zip;
namespace PhpOffice\Common\Tests\Adapter\Zip;

use PhpOffice\Common\Adapter\Zip\ZipInterface;
use PhpOffice\Common\Tests\TestHelperZip;

abstract class AbstractZipAdapterTest extends \PHPUnit\Framework\TestCase
abstract class AbstractZipAdapter extends \PHPUnit\Framework\TestCase
{
/**
* @var string
Expand Down
Loading
Loading