Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
tests:
name: Tests (PHP ${{ matrix.php }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none

- uses: ramsey/composer-install@v3
with:
dependency-versions: highest

- run: vendor/bin/codecept run unit

quality:
name: PHPStan & PSR-12
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
coverage: none

- uses: ramsey/composer-install@v3

- run: composer phpstan
- run: composer phpcs
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# GeekLab-ToolBox
[![Build Status](https://travis-ci.com/ellisgl/GeekLab-ToolBox.svg?branch=release)](https://travis-ci.com/ellisgl/GeekLab-ToolBox)
[![CI](https://github.com/ellisgl/GeekLab-ToolBox/actions/workflows/ci.yml/badge.svg)](https://github.com/ellisgl/GeekLab-ToolBox/actions/workflows/ci.yml)
[![Packagist Version](https://img.shields.io/packagist/v/geeklab/toolbox)](https://packagist.org/packages/geeklab/toolbox)
[![PHP Version](https://img.shields.io/packagist/dependency-v/geeklab/toolbox/php)](https://packagist.org/packages/geeklab/toolbox)
[![PHPStan](https://img.shields.io/badge/PHPStan-level%2010-brightgreen)](https://phpstan.org/)

Just some "utility" classes for PHP.

Expand Down
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
"codeception/codeception": "^5.0",
"spatie/phpunit-snapshot-assertions": "^4.2",
"digitickets/phpunit-errorhandler": "^4.1",
"codeception/module-asserts": "^3.0"
"codeception/module-asserts": "^3.0",
"phpstan/phpstan": "^2",
"squizlabs/php_codesniffer": "^3"
},
"autoload" : {
"psr-4" : {
"GeekLab\\" : "src"
"autoload": {
"psr-4": {
"GeekLab\\": "src"
}
},
"scripts": {
"test": "codecept run unit",
"phpstan": "phpstan analyse --no-progress",
"phpcs": "phpcs src --standard=PSR12 -n"
}
}
145 changes: 144 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 10
paths:
- src
19 changes: 9 additions & 10 deletions src/ToolBox/Arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ class Arrays
/**
* Recursive array_walk, since array_walk_recursive only deal with the outer leafs / nodes.
*
* @param array $array
* @param callable $callback
* @param array<mixed> $array
* @param callable $callback
*/
public static function explore(array &$array, callable $callback): void
{
array_walk($array, static function (&$value, $key) use (&$array, $callback)
{
array_walk($array, static function (&$value, $key) use (&$array, $callback) {
if (is_array($value)) {
self::explore($value, $callback);
}
Expand All @@ -27,12 +26,12 @@ public static function explore(array &$array, callable $callback): void
*/

/**
* @param array $array
* @param array<mixed> $array
* @param int | string $oldKey
* @param int | string $newKey
* @param bool $recursive
*
* @return array
* @return array<mixed>
*/
public static function renameKey(
array $array,
Expand Down Expand Up @@ -60,7 +59,7 @@ public static function renameKey(
/**
* Return the first key in an array.
*
* @param array $array
* @param array<mixed> $array
*
* @return int | string | null
*/
Expand All @@ -74,7 +73,7 @@ public static function firstKey(array $array): int | string | null
/**
* Return the last key in an array.
*
* @param array $array
* @param array<mixed> $array
*
* @return int | null | string
*/
Expand All @@ -87,7 +86,7 @@ public static function lastKey(array $array): int | string | null
/**
* Return the first value in an array
*
* @param array $array
* @param array<mixed> $array
*
* @return mixed
*/
Expand All @@ -99,7 +98,7 @@ public static function firstValue(array $array): mixed
/**
* Return the last value in an array
*
* @param array $array
* @param array<mixed> $array
*
* @return mixed
*/
Expand Down
9 changes: 5 additions & 4 deletions src/ToolBox/Is.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ class Is
* Is something empty, 0 and '0' values count as not empty.
* http://php.net/manual/en/function.empty.php#78269
*
* @param $something
* @param bool $nullValid Should NULL be considered as not empty?
* @param mixed $something
* @param bool $nullValid Should NULL be considered as not empty?
* @return bool
*/
public static function empty($something, bool $nullValid = false): bool
public static function empty(mixed $something, bool $nullValid = false): bool
{
return (('' === $something || (NULL === $something && !$nullValid)) && 0 !== $something && '0' !== $something);
// Only '' and NULL (unless $nullValid) are empty, so 0 and '0' are never empty.
return '' === $something || (null === $something && !$nullValid);
}
}
Loading