Skip to content

Commit fc4c764

Browse files
committed
1 parent 81025b2 commit fc4c764

20 files changed

+1008
-93
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
- "8.1"
3838
- "8.2"
3939
- "8.3"
40+
- "8.4"
4041

4142
steps:
4243
- name: "Checkout"
@@ -56,6 +57,9 @@ jobs:
5657
- name: "Install dependencies with composer"
5758
uses: ramsey/composer-install@v3
5859

60+
- name: "Run PHPCodeSniffer"
61+
run: php vendor/bin/phpcs
62+
5963
- name: "Run PHPStan"
6064
run: php vendor/bin/phpstan
6165

@@ -75,6 +79,7 @@ jobs:
7579
- "8.1"
7680
- "8.2"
7781
- "8.3"
82+
- "8.4"
7883

7984
steps:
8085
- name: "Checkout"

.phpstan/baseline-lt-8.2.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
ignoreErrors:
3+
- message: "#^Call to method getBytesFromString\\(\\) on an unknown class Random\\\\Randomizer\\.$#"
4+
- message: "#^Instantiated class Random\\\\Engine\\\\Secure not found\\.$#"
5+
- message: "#^Instantiated class Random\\\\Randomizer not found\\.$#"

.phpstan/baseline-lt-8.3.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
ignoreErrors:
3+
- message: "#^Call to an undefined method Random\\\\Randomizer\\:\\:getBytesFromString\\(\\)\\.$#"

.phpstan/ignore-by-php-version.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
$includes = [];
5+
6+
if(PHP_VERSION_ID < 80200){
7+
$includes[] = __DIR__.'/baseline-lt-8.2.neon';
8+
}
9+
elseif(PHP_VERSION_ID < 80300){
10+
$includes[] = __DIR__.'/baseline-lt-8.3.neon';
11+
}
12+
13+
$config = [];
14+
$config['includes'] = $includes;
15+
$config['parameters']['phpVersion'] = PHP_VERSION_ID;
16+
17+
return $config;

README.md

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# chillerlan/php-library-template-nodocs
1+
# chillerlan/php-standard-utilities
22

3-
A template/boilerplate for PHP libraries (similar to [chillerlan/php-library-template](https://github.com/chillerlan/php-library-template) but without phpdocs and readthedocs deployment).
3+
A collection of reusable multi-purpose functions for PHP libraries.
44

55
[![PHP Version Support][php-badge]][php]
66
[![Packagist version][packagist-badge]][packagist]
@@ -9,37 +9,30 @@ A template/boilerplate for PHP libraries (similar to [chillerlan/php-library-tem
99
[![CodeCov][coverage-badge]][coverage]
1010
[![Packagist downloads][downloads-badge]][downloads]
1111

12-
[php-badge]: https://img.shields.io/packagist/php-v/chillerlan/php-library-template-nodocs?logo=php&color=8892BF&logoColor=fff
12+
[php-badge]: https://img.shields.io/packagist/php-v/chillerlan/php-standard-utilities?logo=php&color=8892BF&logoColor=fff
1313
[php]: https://www.php.net/supported-versions.php
14-
[packagist-badge]: https://img.shields.io/packagist/v/chillerlan/php-library-template-nodocs.svg?logo=packagist&logoColor=fff
15-
[packagist]: https://packagist.org/packages/chillerlan/php-library-template-nodocs
16-
[license-badge]: https://img.shields.io/github/license/chillerlan/php-library-template-nodocs
17-
[license]: https://github.com/chillerlan/php-library-template-nodocs/blob/main/LICENSE
18-
[gh-action-badge]: https://img.shields.io/github/actions/workflow/status/chillerlan/php-library-template-nodocs/ci.yml?branch=main&logo=github&logoColor=fff
19-
[gh-action]: https://github.com/chillerlan/php-library-template-nodocs/actions/workflows/ci.yml?query=branch%3Amain
20-
[coverage-badge]: https://img.shields.io/codecov/c/github/chillerlan/php-library-template-nodocs.svg?logo=codecov&logoColor=fff
21-
[coverage]: https://codecov.io/github/chillerlan/php-library-template-nodocs
22-
[downloads-badge]: https://img.shields.io/packagist/dt/chillerlan/php-library-template-nodocs.svg?logo=packagist&logoColor=fff
23-
[downloads]: https://packagist.org/packages/chillerlan/php-library-template-nodocs/stats
14+
[packagist-badge]: https://img.shields.io/packagist/v/chillerlan/php-standard-utilities.svg?logo=packagist&logoColor=fff
15+
[packagist]: https://packagist.org/packages/chillerlan/php-standard-utilities
16+
[license-badge]: https://img.shields.io/github/license/chillerlan/php-standard-utilities
17+
[license]: https://github.com/chillerlan/php-standard-utilities/blob/main/LICENSE
18+
[gh-action-badge]: https://img.shields.io/github/actions/workflow/status/chillerlan/php-standard-utilities/ci.yml?branch=main&logo=github&logoColor=fff
19+
[gh-action]: https://github.com/chillerlan/php-standard-utilities/actions/workflows/ci.yml?query=branch%3Amain
20+
[coverage-badge]: https://img.shields.io/codecov/c/github/chillerlan/php-standard-utilities.svg?logo=codecov&logoColor=fff
21+
[coverage]: https://codecov.io/github/chillerlan/php-standard-utilities
22+
[downloads-badge]: https://img.shields.io/packagist/dt/chillerlan/php-standard-utilities.svg?logo=packagist&logoColor=fff
23+
[downloads]: https://packagist.org/packages/chillerlan/php-standard-utilities/stats
2424

2525
## Overview
2626

2727
### Features
2828

29-
- [GitHub Actions](https://github.com/chillerlan/php-library-template-nodocs/actions) runner
30-
- [Composer](https://getcomposer.org) dependency management
31-
- [PHPUnit](https://phpunit.de) unit tests
32-
- [PHPStan](https://github.com/phpstan/phpstan) static analysis
33-
- [PHPCS](https://github.com/PHPCSStandards/PHP_CodeSniffer) coding standard analyzer
34-
- [PHPMD](https://phpmd.org) mess detector
35-
- [Codecov](https://codecov.io) code coverage analysis
36-
- [phpDocumentor](https://www.phpdoc.org) auto generated API docs
29+
This library features some common functions to reduce overall duplication and avoid certain ugly workarounds (looking at you, phpstan...).
3730

3831

3932
### Requirements
4033

4134
- PHP 8.1+
42-
35+
- extensions: `json`, `mbstring`, `sodium`
4336

4437
## Disclaimer
4538

composer.json

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"$schema": "https://getcomposer.org/schema.json",
3-
"name": "chillerlan/php-library-template-nodocs",
4-
"description": "A PHP Library template/boilerplate.",
3+
"name": "chillerlan/php-standard-utilities",
4+
"description": "A collection of reusable multi-purpose functions for PHP libraries.",
55
"license": "MIT",
66
"type": "library",
7-
"keywords": ["boilerplate", "library-template"],
7+
"keywords": ["functions", "utilities"],
88
"authors": [
99
{
1010
"name": "smiley",
@@ -13,7 +13,7 @@
1313
},
1414
{
1515
"name": "Contributors",
16-
"homepage":"https://github.com/chillerlan/php-library-template-nodocs/graphs/contributors"
16+
"homepage":"https://github.com/chillerlan/php-standard-utilities/graphs/contributors"
1717
}
1818
],
1919
"funding": [
@@ -22,33 +22,36 @@
2222
"url": "https://ko-fi.com/codemasher"
2323
}
2424
],
25-
"homepage": "https://github.com/chillerlan/php-library-template-nodocs",
25+
"homepage": "https://github.com/chillerlan/php-standard-utilities",
2626
"support": {
27-
"issues": "https://github.com/chillerlan/php-library-template-nodocs/issues",
28-
"source": "https://github.com/chillerlan/php-library-template-nodocs"
27+
"issues": "https://github.com/chillerlan/php-standard-utilities/issues",
28+
"source": "https://github.com/chillerlan/php-standard-utilities"
2929
},
3030
"minimum-stability": "stable",
3131
"prefer-stable": true,
3232
"require": {
33-
"php": "^8.1"
33+
"php": "^8.1",
34+
"ext-json": "*",
35+
"ext-mbstring": "*",
36+
"ext-sodium": "*"
3437
},
3538
"require-dev": {
3639
"phpunit/phpunit": "^10.5",
3740
"phpmd/phpmd": "^2.15",
38-
"phpstan/phpstan": "^1.11",
41+
"phpstan/phpstan": "^1.12",
3942
"phpstan/phpstan-deprecation-rules": "^1.2",
4043
"squizlabs/php_codesniffer": "^3.10"
4144
},
4245
"suggest": {
4346
},
4447
"autoload": {
4548
"psr-4": {
46-
"chillerlan\\LibraryTemplate\\": "src"
49+
"chillerlan\\Utilities\\": "src"
4750
}
4851
},
4952
"autoload-dev": {
5053
"psr-4": {
51-
"chillerlan\\LibraryTemplateTest\\": "tests"
54+
"chillerlan\\UtilitiesTest\\": "tests"
5255
}
5356
},
5457
"scripts": {

examples/example.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
/**
33
* example.php
44
*
5-
* @created 08.03.2024
5+
* @created 30.10.2024
66
* @author smiley <[email protected]>
77
* @copyright 2024 smiley
88
* @license MIT
99
*/
1010
declare(strict_types=1);
1111

12-
require_once __DIR__.'/../vendor/autoload.php';
12+
use chillerlan\Utilities\Crypto;
1313

14-
$example = new \chillerlan\LibraryTemplate\Example;
14+
require_once __DIR__.'/../vendor/autoload.php';
1515

16-
echo $example->hello();
16+
var_dump(Crypto::randomString(128));

phpstan-baseline.neon

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
parameters:
2-
ignoreErrors: []
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#1 \\$min \\(0\\) of function random_int expects lower number than parameter \\#2 \\$max \\(int\\<\\-1, max\\>\\)\\.$#"
5+
count: 1
6+
path: src/Crypto.php
7+
8+
-
9+
message: "#^Parameter \\#2 \\$flags of static method chillerlan\\\\Utilities\\\\Str\\:\\:jsonEncode\\(\\) expects int, int\\|null given\\.$#"
10+
count: 1
11+
path: src/File.php
12+
13+
-
14+
message: "#^Parameter \\$length of function file_get_contents expects int\\<0, max\\>\\|null, int\\|null given\\.$#"
15+
count: 1
16+
path: src/File.php

phpstan.dist.neon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ parameters:
44
level: 9
55
tmpDir: .build/phpstan-cache
66
paths:
7-
- examples
7+
# - examples
88
- src
9-
- tests
9+
# - tests
1010

1111
treatPhpDocTypesAsCertain: false
1212

1313
includes:
1414
- phpstan-baseline.neon
15+
- .phpstan/ignore-by-php-version.php
1516
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
1617
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
17-
# - vendor/chillerlan/php-settings-container/rules-magic-access.neon

src/Arr.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Class Arrays
4+
*
5+
* @created 29.10.2024
6+
* @author smiley <[email protected]>
7+
* @copyright 2024 smiley
8+
* @license MIT
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace chillerlan\Utilities;
13+
14+
use function array_key_first;
15+
use function array_key_last;
16+
17+
/**
18+
* Array functions
19+
*/
20+
final class Arr{
21+
22+
/**
23+
* Returns the first element of an array, `null` if the given array is empty.
24+
*
25+
* @param array<string|int, mixed> $array
26+
*
27+
* @codeCoverageIgnore
28+
*/
29+
public static function first(array $array):mixed{
30+
31+
if($array === []){
32+
return null;
33+
}
34+
35+
return $array[array_key_first($array)];
36+
}
37+
38+
/**
39+
* Returns the last element of an array, `null` if the given array is empty.
40+
*
41+
* @param array<string|int, mixed> $array
42+
*
43+
* @codeCoverageIgnore
44+
*/
45+
public static function last(array $array):mixed{
46+
47+
if($array === []){
48+
return null;
49+
}
50+
51+
return $array[array_key_last($array)];
52+
}
53+
54+
}

0 commit comments

Comments
 (0)