Skip to content

Commit

Permalink
Minimal PHP version is 7.4 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis authored Jun 5, 2022
1 parent e199d72 commit 8959733
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 158 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,9 @@ jobs:
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4, 8.0 ]
experimental: [ false ]
php-version: [ 7.4, 8.0, 8.1 ]
coverage: [ xdebug, none ]
composer_flags: [ "--prefer-lowest", "" ]
include:
- php-version: "8.1"
experimental: true
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -56,18 +52,15 @@ jobs:
tools: composer

- name: Build the Project
continue-on-error: ${{ matrix.experimental }}
run: make update --no-print-directory

- name: 🧪 PHPUnit Tests
continue-on-error: ${{ matrix.experimental }}
run: make test --no-print-directory

- name: Uploading coverage to coveralls
if: ${{ matrix.coverage == 'xdebug' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make report-coveralls --no-print-directory
run: make report-coveralls --no-print-directory || true

- name: Upload Artifacts
uses: actions/upload-artifact@v2
Expand All @@ -81,7 +74,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4 ]
php-version: [ 7.4, 8.0, 8.1 ]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -112,7 +105,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4, 8.0 ]
php-version: [ 7.4, 8.0, 8.1 ]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -126,11 +119,9 @@ jobs:
tools: composer

- name: Build the Project
continue-on-error: ${{ matrix.experimental }}
run: make update --no-print-directory

- name: 📝 Build Reports
continue-on-error: ${{ matrix.experimental }}
run: make report-all --no-print-directory

- name: Upload Artifacts
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
],

"require" : {
"php" : ">=7.2",
"php" : ">=7.4",
"ext-posix" : "*",
"ext-filter" : "*",
"ext-dom" : "*"
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^3.1.0",
"symfony/process" : ">=4.4"
"jbzoo/toolbox-dev" : "^4.0.1",
"symfony/process" : ">=4.4,<6.0"
},

"suggest" : {
Expand Down Expand Up @@ -62,8 +62,8 @@

"config" : {
"optimize-autoloader" : true,
"allow-plugins": {
"composer/package-versions-deprecated": false
"allow-plugins" : {
"composer/package-versions-deprecated" : false
}
},

Expand Down
27 changes: 15 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@copyright Copyright (C) JBZoo.com, All rights reserved.
@link https://github.com/JBZoo/Utils
-->
<phpunit bootstrap="tests/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
Expand All @@ -23,24 +24,26 @@
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/coverage_xml/main.xml"/>
<php outputFile="build/coverage_cov/main.cov"/>
<text outputFile="php://stdout" showUncoveredFiles="false" showOnlySummary="true"/>
</report>
</coverage>

<testsuites>
<testsuite name="PHPUnit">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/coverage_xml/main.xml"/>
<log type="coverage-php" target="build/coverage_cov/main.cov"/>
<log type="junit" target="build/coverage_junit/main.xml"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" showOnlySummary="true"/>
<junit outputFile="build/coverage_junit/main.xml"/>
</logging>

</phpunit>
2 changes: 1 addition & 1 deletion src/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function checkDns(string $email): bool

$domain = self::extractDomain($email);

return !(\checkdnsrr($domain, 'MX') === false);
return \checkdnsrr($domain);
}

/**
Expand Down
18 changes: 5 additions & 13 deletions src/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,14 @@ public static function v4InRange(string $ipAddress, string $range): bool

// $netMask is a CIDR size block
// fix the range argument
$blocks = \explode('.', $range);

$expectedNumOfParts = 4;
/** @phan-suppress-next-line PhanPossiblyInfiniteLoop */
while (\count($blocks) < $expectedNumOfParts) {
$blocks[] = '0';
}

[$blockA, $blockB, $blockC, $blockD] = $blocks;
$blocks = \explode('.', $range, 4);

$range = \sprintf(
'%u.%u.%u.%u',
(int)(empty($blockA) ? '0' : $blockA),
(int)(empty($blockB) ? '0' : $blockB),
(int)(empty($blockC) ? '0' : $blockC),
(int)(empty($blockD) ? '0' : $blockD)
(int)($blocks[0] ?? 0),
(int)($blocks[1] ?? 0),
(int)($blocks[2] ?? 0),
(int)($blocks[3] ?? 0)
);

$rangeDec = \ip2long($range);
Expand Down
4 changes: 2 additions & 2 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ public static function imageCopyMergeAlpha(

// Get image width and height and percentage
$opacity /= 100;
$width = (int)\imagesx($srcImg);
$height = (int)\imagesy($srcImg);
$width = \imagesx($srcImg) ?: 0;
$height = \imagesy($srcImg) ?: 0;

// Turn alpha blending off
self::addAlpha($srcImg, false);
Expand Down
15 changes: 1 addition & 14 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class Str
*
* @var string
*/
public static $encoding = 'UTF-8';
public static string $encoding = 'UTF-8';

/**
* Strip all whitespaces from the given string.
Expand Down Expand Up @@ -340,19 +340,6 @@ public static function slug(string $text = '', bool $isCache = false): string
return $cache[$text];
}

/**
* Check is mbstring overload standard functions
* @return bool
*/
public static function isOverload(): bool
{
if (\defined('MB_OVERLOAD_STRING') && self::isMBString()) {
return (bool)(Filter::int(Sys::iniGet('mbstring.func_overload')) & \MB_OVERLOAD_STRING);
}

return false;
}

/**
* Check is mbstring loaded
*
Expand Down
2 changes: 1 addition & 1 deletion src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class Url
*/
public static function addArg(array $newParams, ?string $uri = null): string
{
$uri = $uri ?? ($_SERVER['REQUEST_URI'] ?? '');
$uri ??= ($_SERVER['REQUEST_URI'] ?? '');

// Parse the URI into it's components
$parsedUri = data((array)\parse_url((string)$uri));
Expand Down
11 changes: 3 additions & 8 deletions src/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ public static function escape($rawXmlContent): string
$rawXmlContent
);

$rawXmlContent = \str_replace(
return \str_replace(
['&', '<', '>', '"', "'"],
['&amp;', '&lt;', '&gt;', '&quot;', '&apos;'],
$rawXmlContent
);

return $rawXmlContent;
}

/**
Expand Down Expand Up @@ -121,13 +119,10 @@ public static function array2Dom(
$document = self::createFromString();
}

$domElement = $domElement ?? $document;
$domElement ??= $document;

if (\array_key_exists('_text', $xmlAsArray) && $xmlAsArray['_text'] !== null) {
$newNode = $document->createTextNode($xmlAsArray['_text']);
if ($newNode !== false) {
$domElement->appendChild($newNode);
}
$domElement->appendChild(new \DOMText($xmlAsArray['_text']));
}

if (\array_key_exists('_cdata', $xmlAsArray) && $xmlAsArray['_cdata'] !== null) {
Expand Down
4 changes: 2 additions & 2 deletions src/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@

declare(strict_types=1);

$_SERVER['REQUEST_TIME_FLOAT'] = $_SERVER['REQUEST_TIME_FLOAT'] ?? microtime(true);
$_SERVER['REQUEST_TIME'] = $_SERVER['REQUEST_TIME'] ?? $_SERVER['REQUEST_TIME_FLOAT'];
$_SERVER['REQUEST_TIME_FLOAT'] ??= microtime(true);
$_SERVER['REQUEST_TIME'] ??= $_SERVER['REQUEST_TIME_FLOAT'];
2 changes: 1 addition & 1 deletion tests/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function getGravatarUrlProvider(): array

public function testRandomEmail(): void
{
isTrue(Email::check(Email::random()));
isTrue((bool)Email::check(Email::random()));
isTrue(Email::isValid(Email::random()));

isNotSame(Email::random(), Email::random());
Expand Down
2 changes: 1 addition & 1 deletion tests/FileSystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function testFirstLine(): void

public function testPerms(): void
{
isFalse(FS::perms('/no/such/file'));
isFalse((bool)FS::perms('/no/such/file'));
}

public function testWritable(): void
Expand Down
6 changes: 3 additions & 3 deletions tests/SysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public function testIsPHPVersion(): void

public function testGetMemory(): void
{
isTrue(Sys::getMemory());
isTrue(Sys::getMemory(true));
isTrue(Sys::getMemory(false));
isTrue((bool)Sys::getMemory());
isTrue((bool)Sys::getMemory(true));
isTrue((bool)Sys::getMemory(false));
}

public function testGetDocumentRoot(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/TimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public function testSecondsToTimeStringInMillisecond($string, $seconds): void

public function testGetRequestTime(): void
{
isTrue(Timer::getRequestTime());
isTrue(Timer::getRequestTime() > 0);
}

public function testTimeSinceStart(): void
{
isTrue(Timer::timeSinceStart());
isTrue(Timer::timeSinceStart() > 0);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/UtilsReadmeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
class UtilsReadmeTest extends AbstractReadmeTest
{
protected $packageName = 'Utils';
protected string $packageName = 'Utils';

protected function setUp(): void
{
Expand Down
Loading

0 comments on commit 8959733

Please sign in to comment.