Skip to content

Commit

Permalink
Merge 3c9d5eb into b1e46e8
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Dec 11, 2023
2 parents b1e46e8 + 3c9d5eb commit e9dac3a
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 64 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
8 changes: 3 additions & 5 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,9 +17,9 @@ 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) {
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
36 changes: 17 additions & 19 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 Down Expand Up @@ -100,14 +98,14 @@ 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);
Expand Down Expand Up @@ -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
24 changes: 12 additions & 12 deletions tests/Common/Tests/Microsoft/PasswordEncoderTest.php
Expand Up @@ -31,13 +31,13 @@ class PasswordEncoderTest extends \PHPUnit\Framework\TestCase
*/
public function testEncodePassword(): void
{
//given
// Given
$password = 'test';

//when
// When
$hashPassword = PasswordEncoder::hashPassword($password);

//then
// Then
$this->assertEquals('M795/MAlmGU8RIsY9Q9uDLHC7bk=', $hashPassword);
}

Expand All @@ -46,14 +46,14 @@ public function testEncodePassword(): void
*/
public function testEncodePasswordWithSalt(): void
{
//given
// Given
$password = 'test';
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');

//when
// When
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_SHA_1, $salt);

//then
// Then
$this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
}

Expand All @@ -62,14 +62,14 @@ public function testEncodePasswordWithSalt(): void
*/
public function testDefaultsToSha1IfUnsupportedAlgorithm(): void
{
//given
// Given
$password = 'test';
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');

//when
// When
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt);

//then
// Then
$this->assertEquals('QiDOcpia1YzSVJPiKPwWebl9p/0=', $hashPassword);
}

Expand All @@ -78,14 +78,14 @@ public function testDefaultsToSha1IfUnsupportedAlgorithm(): void
*/
public function testEncodePasswordWithNullAsciiCodeInPassword(): void
{
//given
// Given
$password = 'test' . chr(0);
$salt = base64_decode('uq81pJRRGFIY5U+E9gt8tA==');

//when
// When
$hashPassword = PasswordEncoder::hashPassword($password, PasswordEncoder::ALGORITHM_MAC, $salt, 1);

//then
// Then
$this->assertEquals('rDV9sgdDsztoCQlvRCb1lF2wxNg=', $hashPassword);
}
}

0 comments on commit e9dac3a

Please sign in to comment.