Skip to content

Commit

Permalink
Update PHP deps (#30)
Browse files Browse the repository at this point in the history
* Update deps
* Fixes Code style
* Fixed phan issues
* Missed `: void`
* Exclude PHP 8.0 in Travis
  • Loading branch information
SmetDenis committed Apr 28, 2021
1 parent 3a2ae5c commit 54f06ce
Show file tree
Hide file tree
Showing 49 changed files with 440 additions and 329 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#

/.github export-ignore
/.phan export-ignore
/build export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.phan.php export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore

Expand Down
87 changes: 79 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# @link https://github.com/JBZoo/Utils
#

name: Continuous Integration
name: CI

on:
pull_request:
Expand All @@ -21,7 +21,7 @@ on:
branches:
- 'master'
schedule:
- cron: '15 */8 * * *'
- cron: '50 */8 * * *'

env:
COLUMNS: 120
Expand All @@ -35,12 +35,11 @@ jobs:
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4 ]
php-version: [ 7.2, 7.3, 7.4, 8.0 ]
experimental: [ false ]
coverage: [ xdebug, none ]
composer_flags: [ "--prefer-lowest", "" ]
include:
- php-version: "8.0"
experimental: true
- php-version: "8.1"
experimental: true
steps:
Expand All @@ -49,11 +48,11 @@ jobs:
with:
fetch-depth: 0

- name: Setup PHP and composer
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
coverage: ${{ matrix.coverage }}
tools: composer

- name: Build the Project
Expand All @@ -64,10 +63,82 @@ jobs:
continue-on-error: ${{ matrix.experimental }}
run: make test --no-print-directory

- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: PHPUnit - ${{ matrix.php-version }} - ${{ matrix.coverage }}
path: build/


linters:
name: Linters
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4, 8.0 ]
experimental: [ false ]
include:
- php-version: "8.1"
experimental: true
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer

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

- name: 👍 Code Quality
continue-on-error: ${{ matrix.experimental }}
run: make codestyle --no-print-directory

- name: 📝 Build All Reports at Once
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: Linters - ${{ matrix.php-version }}
path: build/


report:
name: Reports
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4, 8.0 ]
experimental: [ false ]
include:
- php-version: "8.1"
experimental: true
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
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
uses: actions/upload-artifact@v2
with:
name: Reports - ${{ matrix.php-version }}
path: build/
2 changes: 1 addition & 1 deletion .phan/config.php → .phan.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

declare(strict_types=1);

$default = include __DIR__ . '/../vendor/jbzoo/codestyle/src/phan/default.php';
$default = include __DIR__ . '/vendor/jbzoo/codestyle/src/phan/default.php';

return array_merge($default, [
'directory_list' => [
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ php:
- 7.3
- 7.4
- 8.0
- nightly

matrix:
fast_finish: true
allow_failures:
- php: 8.0
- php: nightly

env:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^2.11.0",
"jbzoo/toolbox-dev" : "^2.13.1",
"symfony/process" : ">=4.4"
},

Expand Down
21 changes: 20 additions & 1 deletion src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Arr
final class Arr
{
/**
* Remove the duplicates from an array.
Expand Down Expand Up @@ -475,4 +475,23 @@ public static function implode(string $glue, array $array): string

return $result;
}

/**
* @param array $array
* @param string|float|int|bool|null $value
* @return array
*/
public static function removeByValue(array $array, $value): array
{
return array_filter(
$array,
/**
* @param string|float|int|bool|null $arrayItem
*/
static function ($arrayItem) use ($value): bool {
return $value !== $arrayItem;
},
ARRAY_FILTER_USE_BOTH
);
}
}
2 changes: 1 addition & 1 deletion src/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @package JBZoo\Utils
*/
class Cli
final class Cli
{
public const STDIN = 0;
public const STDOUT = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @package JBZoo\Utils
*/
class Csv
final class Csv
{
public const LENGTH_LIMIT = 10000000;

Expand Down
8 changes: 5 additions & 3 deletions src/Dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @package JBZoo\Utils
*/
class Dates
final class Dates
{
public const MINUTE = 60;
public const HOUR = 3600;
Expand Down Expand Up @@ -110,7 +110,7 @@ public static function timezone($timezone = null): DateTimeZone
public static function is(?string $date): bool
{
$time = strtotime((string)$date);
return $time > 10000;
return $time > 0;
}

/**
Expand Down Expand Up @@ -210,7 +210,9 @@ public static function isYesterday($time): bool
*/
public static function formatTime(float $seconds): string
{
if ($seconds < 2) {
$minValuableSeconds = 2;

if ($seconds < $minValuableSeconds) {
return number_format($seconds, 3) . ' sec';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @package JBZoo\Utils
*/
class Email
final class Email
{
/**
* Create random email
Expand Down
2 changes: 1 addition & 1 deletion src/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @package JBZoo\Utils
*/
class Env
final class Env
{
public const VAR_NULL = 1;
public const VAR_BOOL = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Class Exception
* @package JBZoo\Utils
*/
class Exception extends \RuntimeException
final class Exception extends \RuntimeException
{

}
2 changes: 1 addition & 1 deletion src/FS.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.ShortClassName)
*/
class FS
final class FS
{
public const TYPE_SOCKET = 0xC000;
public const TYPE_SYMLINK = 0xA000;
Expand Down
2 changes: 1 addition & 1 deletion src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @SuppressWarnings(PHPMD.TooManyMethods)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class Filter
final class Filter
{
/**
* Apply custom filter to variable
Expand Down
6 changes: 4 additions & 2 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @package JBZoo\Utils
*/
class Http
final class Http
{
/**
* Transmit headers that force a browser to display the download file dialog.
Expand Down Expand Up @@ -164,7 +164,9 @@ public static function getHeaders(): array
if (0 === stripos($authorizationHeader, 'basic ')) {
// Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
$exploded = explode(':', (string)base64_decode((string)substr($authorizationHeader, 6)), 2);
if (count($exploded) === 2) {

$expectedNumOfParts = 2;
if (count($exploded) === $expectedNumOfParts) {
[$headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']] = $exploded;
}
} elseif (empty($_SERVER['PHP_AUTH_DIGEST']) && (0 === stripos($authorizationHeader, 'digest '))) {
Expand Down
25 changes: 15 additions & 10 deletions src/IP.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @package JBZoo\Utils
* @SuppressWarnings(PHPMD.ShortClassName)
*/
class IP
final class IP
{
/**
* Returns the IP address of the client.
Expand Down Expand Up @@ -80,8 +80,9 @@ public static function v4InRange(string $ipAddress, string $range): bool
// fix the range argument
$blocks = explode('.', $range);

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

Expand Down Expand Up @@ -134,15 +135,19 @@ public static function getNetMask(string $ipAddress): ?string
{
$ipAddressLong = ip2long($ipAddress);

$mask = 0xFFFFFFFF;
if (($ipAddressLong & 0x80000000) === 0) {
$mask = 0xFF000000;
} elseif (($ipAddressLong & 0xC0000000) === 0x80000000) {
$mask = 0xFFFF0000;
} elseif (($ipAddressLong & 0xE0000000) === 0xC0000000) {
$mask = 0xFFFFFF00;
$maskLevel1 = 0x80000000;
$maskLevel2 = 0xC0000000;
$maskLevel3 = 0xE0000000;

$resultMask = 0xFFFFFFFF;
if (($ipAddressLong & $maskLevel1) === 0) {
$resultMask = 0xFF000000;
} elseif (($ipAddressLong & $maskLevel2) === $maskLevel1) {
$resultMask = 0xFFFF0000;
} elseif (($ipAddressLong & $maskLevel3) === $maskLevel2) {
$resultMask = 0xFFFFFF00;
}

return long2ip($mask) ?: null;
return long2ip($resultMask) ?: null;
}
}
Loading

0 comments on commit 54f06ce

Please sign in to comment.