Skip to content

Commit 25c56a3

Browse files
committed
Update all PHP dependencies
This way we can share the same dependencies across PHP 7.4 to PHP 8.1, and simplify our CI pipeline
1 parent 2074382 commit 25c56a3

File tree

83 files changed

+215
-288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+215
-288
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,8 @@ jobs:
3636
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
3737
restore-keys: ${{ runner.os }}-composer-
3838

39-
- name: Update PHPUnit version for PHP 8
40-
id: composer-lock
41-
if: "startsWith(matrix.php-version, '8.')"
42-
run: |
43-
rm -f composer.lock
44-
echo "::set-output name=flags::--ignore-platform-reqs"
45-
composer remove phpunit/phpunit --dev --no-update --no-interaction
46-
composer require phpunit/phpunit ^8.0 --dev --no-update
47-
4839
- name: Install dependencies
49-
run: composer update --no-progress --prefer-dist --optimize-autoloader ${{ steps.composer-lock.outputs.flags }}
50-
51-
- name: Update code to make PHPUnit 8 compatible
52-
if: "startsWith(matrix.php-version, '8.')"
53-
run: |
54-
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUpBeforeClass()$/function setUpBeforeClass(): void/' {} \;
55-
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDownAfterClass()$/function tearDownAfterClass(): void/' {} \;
56-
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function setUp()$/function setUp(): void/' {} \;
57-
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/function tearDown()$/function tearDown(): void/' {} \;
58-
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertContains(/->assertStringContainsString(/' {} \;
59-
find ./tests/ -name "*.php" -type f -exec sed -i -e 's/->assertNotContains(/->assertStringNotContainsString(/' {} \;
60-
find ./tests/ -name "*.php" -type f -exec sed -i -e "s/->assertInternalType('array', /->assertIsArray(/" {} \;
61-
sed -i "s/\$this->addWarning('The @expectedException,/\/\/\$this->addWarning('The @expectedException,/" ./vendor/phpunit/phpunit/src/Framework/TestCase.php
62-
sed -i "s/self::createWarning('The optional \$delta/\/\/self::createWarning('The optional \$delta/" ./vendor/phpunit/phpunit/src/Framework/Assert.php
40+
run: composer install --no-progress --prefer-dist --optimize-autoloader
6341

6442
- name: Setup problem matchers for PHP
6543
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

composer.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,24 @@
5959
},
6060
"require": {
6161
"php": "^7.4 || ^8.0",
62+
"ext-dom": "*",
63+
"ext-json": "*",
6264
"ext-xml": "*",
63-
"laminas/laminas-escaper": "^2.2",
65+
"laminas/laminas-escaper": "^2.10",
6466
"symfony/process": "^5.4"
6567
},
6668
"require-dev": {
6769
"ext-zip": "*",
6870
"ext-gd": "*",
69-
"phpunit/phpunit": "^4.8.36 || ^7.0",
70-
"squizlabs/php_codesniffer": "^2.9 || ^3.5",
71-
"friendsofphp/php-cs-fixer": "^2.2",
72-
"phpmd/phpmd": "2.*",
73-
"phploc/phploc": "2.* || 3.* || 4.* || 5.* || 6.* || 7.*",
74-
"dompdf/dompdf":"0.8.* || 1.0.*",
75-
"tecnickcom/tcpdf": "^6.4",
76-
"mpdf/mpdf": "5.7.4 || 6.* || 7.* || 8.*",
77-
"php-coveralls/php-coveralls": "1.1.0 || ^2.0"
71+
"dompdf/dompdf": "^2.0",
72+
"friendsofphp/php-cs-fixer": "^3.11",
73+
"mpdf/mpdf": "^8.1",
74+
"php-coveralls/php-coveralls": "^2.5",
75+
"phploc/phploc": "^7.0",
76+
"phpmd/phpmd": "^2.13",
77+
"phpunit/phpunit": "^9.5",
78+
"squizlabs/php_codesniffer": "^3.7",
79+
"tecnickcom/tcpdf": "^6.5"
7880
},
7981
"suggest": {
8082
"ext-zip": "Allows writing OOXML and ODF",

src/PhpWord/Element/PreserveText.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct($text = null, $fontStyle = null, $paragraphStyle = n
6060
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
6161

6262
$this->text = SharedText::toUTF8($text);
63-
$matches = preg_split('/({.*?})/', $this->text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
63+
$matches = preg_split('/({.*?})/', $this->text ?? '', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
6464
if (isset($matches[0])) {
6565
$this->text = $matches;
6666
}

src/PhpWord/Reader/MsDoc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,9 @@ private function readSprm($sprm)
14991499
{
15001500
$oSprm = new \stdClass();
15011501
$oSprm->isPmd = $sprm & 0x01FF;
1502-
$oSprm->f = ($sprm / 512) & 0x0001;
1503-
$oSprm->sgc = ($sprm / 1024) & 0x0007;
1504-
$oSprm->spra = ($sprm / 8192);
1502+
$oSprm->f = (int)($sprm / 512) & 0x0001;
1503+
$oSprm->sgc = (int)($sprm / 1024) & 0x0007;
1504+
$oSprm->spra = (int)($sprm / 8192);
15051505

15061506
return $oSprm;
15071507
}

src/PhpWord/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public static function getPdfRendererPath()
255255
*/
256256
public static function setPdfRendererPath($libraryBaseDir)
257257
{
258-
if (false === file_exists($libraryBaseDir) || false === is_readable($libraryBaseDir)) {
258+
if (!$libraryBaseDir || false === file_exists($libraryBaseDir) || false === is_readable($libraryBaseDir)) {
259259
return false;
260260
}
261261
self::$pdfRendererPath = $libraryBaseDir;

src/PhpWord/Shared/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ protected static function parseStyle($attribute, $styles)
620620

621621
foreach ($properties as $property) {
622622
list($cKey, $cValue) = array_pad(explode(':', $property, 2), 2, null);
623-
$cValue = trim($cValue);
623+
$cValue = trim($cValue ?? '');
624624
$cKey = strtolower(trim($cKey));
625625
switch ($cKey) {
626626
case 'text-decoration':

src/PhpWord/Shared/XMLWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function __construct($pTemporaryStorage = self::STORAGE_MEMORY, $pTempora
5959
if ($pTemporaryStorage == self::STORAGE_MEMORY) {
6060
$this->openMemory();
6161
} else {
62-
if (!is_dir($pTemporaryStorageDir)) {
62+
if (!$pTemporaryStorageDir || !is_dir($pTemporaryStorageDir)) {
6363
$pTemporaryStorageDir = sys_get_temp_dir();
6464
}
6565
// Create temporary filename
@@ -178,6 +178,6 @@ public function writeAttribute($name, $value)
178178
$value = json_encode($value);
179179
}
180180

181-
return parent::writeAttribute($name, $value);
181+
return parent::writeAttribute($name, $value ?? '');
182182
}
183183
}

src/PhpWord/Writer/RTF/Element/Title.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function getStyles()
2929
/** @var \PhpOffice\PhpWord\Element\Title $element Type hint */
3030
$element = $this->element;
3131
$style = $element->getStyle();
32-
$style = str_replace('Heading', 'Heading_', $style);
32+
$style = str_replace('Heading', 'Heading_', $style ?? '');
3333
$style = \PhpOffice\PhpWord\Style::getStyle($style);
3434
if ($style instanceof \PhpOffice\PhpWord\Style\Font) {
3535
$this->fontStyle = $style;

src/PhpWord/Writer/RTF/Style/Paragraph.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public function write()
6565
$content .= $alignments[$style->getAlignment()];
6666
}
6767
$content .= $this->writeIndentation($style->getIndentation());
68-
$content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore));
69-
$content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter));
68+
$content .= $this->getValueIf($spaceBefore !== null, '\sb' . round($spaceBefore??0));
69+
$content .= $this->getValueIf($spaceAfter !== null, '\sa' . round($spaceAfter??0));
7070
$lineHeight = $style->getLineHeight();
7171
if ($lineHeight) {
7272
$lineHeightAdjusted = (int) ($lineHeight * 240);

tests/PhpWord/ComplexType/FootnotePropertiesTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,33 +46,30 @@ public function testSetGetNormal()
4646

4747
/**
4848
* Test throws exception if wrong position given
49-
*
50-
* @expectedException \InvalidArgumentException
5149
*/
5250
public function testWrongPos()
5351
{
52+
$this->expectException(\InvalidArgumentException::class);
5453
$footnoteProp = new FootnoteProperties();
5554
$footnoteProp->setPos(NumberFormat::LOWER_ROMAN);
5655
}
5756

5857
/**
5958
* Test throws exception if wrong number format given
60-
*
61-
* @expectedException \InvalidArgumentException
6259
*/
6360
public function testWrongNumFmt()
6461
{
62+
$this->expectException(\InvalidArgumentException::class);
6563
$footnoteProp = new FootnoteProperties();
6664
$footnoteProp->setNumFmt(FootnoteProperties::POSITION_DOC_END);
6765
}
6866

6967
/**
7068
* Test throws exception if wrong number restart given
71-
*
72-
* @expectedException \InvalidArgumentException
7369
*/
7470
public function testWrongNumRestart()
7571
{
72+
$this->expectException(\InvalidArgumentException::class);
7673
$footnoteProp = new FootnoteProperties();
7774
$footnoteProp->setNumRestart(NumberFormat::LOWER_ROMAN);
7875
}

0 commit comments

Comments
 (0)