Skip to content

Commit

Permalink
Added support for PHP 8.2 & 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Dec 11, 2023
1 parent b1e46e8 commit 12b7e0d
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
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
5 changes: 5 additions & 0 deletions composer.json
Expand Up @@ -27,5 +27,10 @@
"psr-4": {
"PhpOffice\\Common\\": "src/Common/"
}
},
"autoload-dev": {
"psr-4": {
"PhpOffice\\Common\\Tests\\": "tests/Common/Tests"
}
}
}
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -5,6 +5,7 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
Expand Down
6 changes: 2 additions & 4 deletions src/Common/Adapter/Zip/PclZipAdapter.php
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
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
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
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
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
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
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
@@ -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
4 changes: 2 additions & 2 deletions tests/Common/Tests/Adapter/Zip/PclZipAdapterTest.php
@@ -1,11 +1,11 @@
<?php

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

use PhpOffice\Common\Adapter\Zip\PclZipAdapter;
use PhpOffice\Common\Adapter\Zip\ZipInterface;

class PclZipAdapterTest extends AbstractZipAdapterTest
class PclZipAdapterTest extends AbstractZipAdapter
{
protected function createAdapter(): ZipInterface
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Common/Tests/Adapter/Zip/ZipArchiveAdapterTest.php
@@ -1,11 +1,11 @@
<?php

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

use PhpOffice\Common\Adapter\Zip\ZipArchiveAdapter;
use PhpOffice\Common\Adapter\Zip\ZipInterface;

class ZipArchiveAdapterTest extends AbstractZipAdapterTest
class ZipArchiveAdapterTest extends AbstractZipAdapter
{
protected function createAdapter(): ZipInterface
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Common/Tests/DrawingTest.php
Expand Up @@ -86,7 +86,7 @@ public function testCentimetersPoints(): void
{
$this->assertEquals(0, Drawing::centimetersToPoints());
$this->assertEquals(28.346456692913385, Drawing::centimetersToPoints(1));
$this->assertEquals(31.181102362204726, Drawing::centimetersToPoints(1.1));
$this->assertEquals(31.181102362204722, Drawing::centimetersToPoints(1.1));
}

public function testTwips(): void
Expand Down

0 comments on commit 12b7e0d

Please sign in to comment.