Skip to content

Commit 2a5b662

Browse files
authored
Fixes deps + GA (#28)
* Fixes dependencies (facepalm) * Init Github Actions * Code style fixes (psalm)
1 parent 4b34529 commit 2a5b662

14 files changed

Lines changed: 271 additions & 235 deletions

File tree

.github/workflows/main.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#
2+
# JBZoo Toolbox - Utils
3+
#
4+
# This file is part of the JBZoo Toolbox project.
5+
# For the full copyright and license information, please view the LICENSE
6+
# file that was distributed with this source code.
7+
#
8+
# @package Utils
9+
# @license MIT
10+
# @copyright Copyright (C) JBZoo.com, All rights reserved.
11+
# @link https://github.com/JBZoo/Utils
12+
#
13+
14+
name: Continuous Integration
15+
16+
on:
17+
pull_request:
18+
branches:
19+
- "*"
20+
push:
21+
branches:
22+
- 'master'
23+
schedule:
24+
- cron: '15 */8 * * *'
25+
26+
env:
27+
COLUMNS: 120
28+
TERM_PROGRAM: Hyper
29+
30+
jobs:
31+
phpunit:
32+
name: PHPUnit
33+
runs-on: ubuntu-latest
34+
env:
35+
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
36+
strategy:
37+
matrix:
38+
php-version: [ 7.2, 7.3, 7.4 ]
39+
experimental: [ false ]
40+
composer_flags: [ "--prefer-lowest", "" ]
41+
include:
42+
- php-version: "8.0"
43+
experimental: true
44+
- php-version: "8.1"
45+
experimental: true
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v2
49+
with:
50+
fetch-depth: 0
51+
52+
- name: Setup PHP and composer
53+
uses: shivammathur/setup-php@v2
54+
with:
55+
php-version: ${{ matrix.php-version }}
56+
coverage: xdebug
57+
tools: composer
58+
59+
- name: Build the Project
60+
continue-on-error: ${{ matrix.experimental }}
61+
run: make update --no-print-directory
62+
63+
- name: 🧪 PHPUnit Tests
64+
continue-on-error: ${{ matrix.experimental }}
65+
run: make test --no-print-directory
66+
67+
- name: 👍 Code Quality
68+
continue-on-error: ${{ matrix.experimental }}
69+
run: make codestyle --no-print-directory
70+
71+
- name: 📝 Build All Reports at Once
72+
continue-on-error: ${{ matrix.experimental }}
73+
run: make report-all --no-print-directory

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ endif
1919
update: ##@Project Install/Update all 3rd party dependencies
2020
$(call title,"Install/Update all 3rd party dependencies")
2121
@echo "Composer flags: $(JBZOO_COMPOSER_UPDATE_FLAGS)"
22-
@composer update $(JBZOO_COMPOSER_UPDATE_FLAGS)
22+
@composer update --no-progress $(JBZOO_COMPOSER_UPDATE_FLAGS)
2323

2424

2525
test-all: ##@Project Run all project tests at once

composer.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,15 @@
2626
],
2727

2828
"require" : {
29-
"php" : ">=7.2",
30-
"ext-posix" : "*",
31-
"ext-filter" : "*",
32-
"ext-dom" : "*",
33-
34-
"jbzoo/toolbox-ci" : "^1.3.5"
29+
"php" : ">=7.2",
30+
"ext-posix" : "*",
31+
"ext-filter" : "*",
32+
"ext-dom" : "*"
3533
},
3634

3735
"require-dev" : {
38-
"jbzoo/codestyle" : "^2.10.0",
39-
"jbzoo/phpunit" : "^4.7.0",
40-
"jbzoo/data" : "^4.1.3",
41-
"symfony/process" : "^5.2.4",
42-
"symfony/polyfill-mbstring" : "^1.22.1"
36+
"jbzoo/toolbox-dev" : "^2.11.0",
37+
"symfony/process" : ">=4.4"
4338
},
4439

4540
"suggest" : {

src/Dates.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function toStamp($time = null, bool $currentIsDefault = true): int
5151
}
5252

5353
if (null !== $time) {
54-
$time = is_numeric($time) ? (int)$time : (int)strtotime((string)$time);
54+
$time = is_numeric($time) ? (int)$time : (int)strtotime($time);
5555
}
5656

5757
if (!$time) {

src/Email.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static function isValid(?string $email): bool
226226
private static function extractDomain(string $email): string
227227
{
228228
$parts = explode('@', $email);
229-
$domain = (string)array_pop($parts);
229+
$domain = array_pop($parts);
230230

231231
if (Sys::isFunc('idn_to_utf8')) {
232232
return (string)idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);

src/FS.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public static function ext(?string $path): string
424424
*/
425425
public static function base(?string $path): string
426426
{
427-
return (string)pathinfo((string)$path, PATHINFO_BASENAME);
427+
return pathinfo((string)$path, PATHINFO_BASENAME);
428428
}
429429

430430
/**
@@ -435,7 +435,7 @@ public static function base(?string $path): string
435435
*/
436436
public static function filename(?string $path): string
437437
{
438-
return (string)pathinfo((string)$path, PATHINFO_FILENAME);
438+
return pathinfo((string)$path, PATHINFO_FILENAME);
439439
}
440440

441441
/**
@@ -446,7 +446,7 @@ public static function filename(?string $path): string
446446
*/
447447
public static function dirName(?string $path): string
448448
{
449-
return (string)pathinfo((string)$path, PATHINFO_DIRNAME);
449+
return pathinfo((string)$path, PATHINFO_DIRNAME);
450450
}
451451

452452
/**

src/Filter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function _($value, $filters = 'raw')
4444
{
4545
if (is_string($filters)) {
4646
$filters = Str::trim($filters);
47-
$filters = (array)explode(',', $filters);
47+
$filters = explode(',', $filters);
4848

4949
foreach ($filters as $filter) {
5050
$filterName = self::cmd($filter);
@@ -236,7 +236,7 @@ public static function path(string $value): string
236236
{
237237
$pattern = '#^[A-Za-z0-9_\/-]+[A-Za-z0-9_\.-]*([\\\\\/][A-Za-z0-9_-]+[A-Za-z0-9_\.-]*)*$#';
238238
preg_match($pattern, $value, $matches);
239-
return isset($matches[0]) ? (string)$matches[0] : '';
239+
return $matches[0] ?? '';
240240
}
241241

242242
/**

src/Stats.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Class Stats
2222
* @package JBZoo\Utils
2323
*
24-
* @see https://github.com/phpbench/phpbench/blob/master/lib/Math/Statistics.php
24+
* @see https://github.com/phpbench/phpbench/blob/master/lib/Math/Statistics.php
2525
*/
2626
class Stats
2727
{
@@ -128,7 +128,7 @@ public static function linSpace(float $min, float $max, int $num = 50, bool $end
128128
* For a better implementation copy:
129129
* http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.histogram.html
130130
*
131-
* @param array $values
131+
* @param float[] $values
132132
* @param int $steps
133133
* @param float|null $lowerBound
134134
* @param float|null $upperBound
@@ -141,6 +141,10 @@ public static function histogram(
141141
?float $lowerBound = null,
142142
?float $upperBound = null
143143
): array {
144+
if (empty($values)) {
145+
throw new Exception('Empty array of values is given');
146+
}
147+
144148
$min = $lowerBound ?? min($values);
145149
$max = $upperBound ?? max($values);
146150

src/Str.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function parseLines(string $text, bool $toAssoc = true): array
5858
$text = self::clean($text, false, false, false);
5959

6060
$text = str_replace(["\n", "\r", "\r\n", PHP_EOL], "\n", $text);
61-
$lines = (array)explode("\n", $text);
61+
$lines = explode("\n", $text);
6262

6363
$result = [];
6464
foreach ($lines as $line) {
@@ -135,7 +135,7 @@ public static function htmlEnt(string $string, bool $encodedEntities = false): s
135135
return (string)preg_replace($regExp, '&', strtr($string, $transTable));
136136
}
137137

138-
return (string)htmlentities($string, ENT_QUOTES, self::$encoding);
138+
return htmlentities($string, ENT_QUOTES, self::$encoding);
139139
}
140140

141141
/**
@@ -385,7 +385,7 @@ public static function len(string $string): int
385385
return (int)mb_strlen($string, self::$encoding);
386386
}
387387

388-
return (int)strlen($string);
388+
return strlen($string);
389389
}
390390

391391
/**
@@ -526,7 +526,7 @@ public static function low($string): string
526526
return (string)mb_strtolower((string)$string, self::$encoding);
527527
}
528528

529-
return (string)strtolower((string)$string);
529+
return strtolower((string)$string);
530530
}
531531

532532
/**
@@ -543,7 +543,7 @@ public static function up($string): string
543543
return (string)mb_strtoupper((string)$string, self::$encoding);
544544
}
545545

546-
return (string)strtoupper((string)$string);
546+
return strtoupper((string)$string);
547547
}
548548

549549
/**
@@ -559,7 +559,7 @@ public static function subCount(string $haystack, string $needle): int
559559
return (int)mb_substr_count($haystack, $needle, self::$encoding);
560560
}
561561

562-
return (int)substr_count($haystack, $needle);
562+
return substr_count($haystack, $needle);
563563
}
564564

565565
/**

src/Sys.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static function getUserName(): ?string
5757
{
5858
$userInfo = posix_getpwuid(posix_geteuid());
5959
if ($userInfo && isset($userInfo['name'])) {
60-
return $userInfo['name'] ?? null;
60+
return $userInfo['name'];
6161
}
6262

6363
return null;
@@ -74,7 +74,7 @@ public static function getHome(): ?string
7474
{
7575
$userInfo = posix_getpwuid(posix_geteuid());
7676
if ($userInfo && isset($userInfo['dir'])) {
77-
return (string)$userInfo['dir'];
77+
return $userInfo['dir'];
7878
}
7979

8080
if (array_key_exists('HOMEDRIVE', $_SERVER)) {

0 commit comments

Comments
 (0)