Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
18d637e
Update test.yaml
alankoroma Mar 19, 2025
fac27ab
Update test.yaml
alankoroma Mar 24, 2025
c2b1bfb
Update test.yaml
alankoroma Mar 25, 2025
eb76375
Update composer.json
alankoroma Mar 25, 2025
4a2349c
Create php83.Dockerfile
alankoroma Mar 25, 2025
5ea4152
Create php84.Dockerfile
alankoroma Mar 25, 2025
eeda637
Create docker-compose.yml
alankoroma Mar 25, 2025
6a40885
Update test.yaml
alankoroma Mar 25, 2025
4909d7a
Update docker-compose.yml
alankoroma Mar 26, 2025
dc35460
Update composer.json
alankoroma Mar 26, 2025
1e6f580
Update test.yaml
alankoroma Mar 27, 2025
a6af026
Update composer.json
alankoroma Mar 27, 2025
73cbf64
Create 84.Dockerfile
alankoroma Mar 27, 2025
97fada0
Update docker-compose.yml
alankoroma Mar 27, 2025
7b9ebeb
change directory
alankoroma Mar 27, 2025
469c988
changes for php 84
alankoroma Mar 27, 2025
e6da151
fix deprecation message
alankoroma Mar 27, 2025
d810729
fix deprecation message
alankoroma Mar 27, 2025
9196b1d
fix error
alankoroma Mar 27, 2025
388922a
fix deprecation message
alankoroma Mar 30, 2025
d761e9a
fix issues with floats being used as array keys
alankoroma Mar 30, 2025
3d7d257
Update ExponentialSequence.php
alankoroma Mar 30, 2025
d6d3d7c
Update LinearSequence.php
alankoroma Mar 30, 2025
71304c8
Update ErrorToExceptionTest.php
alankoroma Mar 31, 2025
cf481fd
Update GroupTest.php
alankoroma Mar 31, 2025
b4b1fba
Update RepeatTest.php
alankoroma Mar 31, 2025
37d5810
fix linting issues
alankoroma Mar 31, 2025
da97a35
Update test.yaml
alankoroma Mar 31, 2025
e86b51f
remove docker config
alankoroma Mar 31, 2025
aee25c6
clean up codebase
alankoroma Sep 22, 2025
a4741ee
clean up codebase
alankoroma Sep 22, 2025
e4ccce7
clean up codebase
alankoroma Sep 22, 2025
5582ea4
clean up codebase
alankoroma Sep 22, 2025
6812eac
clean up codebase
alankoroma Sep 22, 2025
d016f82
added docker config
alankoroma Sep 22, 2025
f6e650f
fix php cs fixer
alankoroma Sep 22, 2025
095d92c
remove deprecated test
alankoroma Sep 23, 2025
c1bc92e
Update test.yaml
alankoroma Sep 23, 2025
8e91a3b
Update test.yaml
alankoroma Sep 23, 2025
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
51 changes: 25 additions & 26 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
name: Test

on: [push, pull_request]
on:
push:
branches: [ main ]
pull_request:
branches: '*'

jobs:
test:
name: PHP ${{ matrix.php-version }} (${{ matrix.experimental && 'experimental' || 'full support' }})
name: PHP ${{ matrix.php-version }}

runs-on: ubuntu-18.04
runs-on: ubuntu-latest
timeout-minutes: 10

strategy:
fail-fast: false
matrix:
php-version:
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
experimental: [false]
include:
- php-version: 8.1
experimental: true

continue-on-error: ${{ matrix.experimental }}
- 8.4
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
Expand All @@ -34,11 +28,21 @@ jobs:
coverage: pcov
tools: composer:v2

- name: Install Composer dependencies
uses: ramsey/composer-install@v1
- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
composer-options: --prefer-dist
continue-on-error: ${{ matrix.experimental }}
path: vendor
key: ${{ runner.os }}-${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php-versions }}-composer

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress

- name: Setup PCOV
run: |
Expand All @@ -47,9 +51,4 @@ jobs:
continue-on-error: true

- name: Run Tests
run: composer tests
continue-on-error: ${{ matrix.experimental }}

- name: Check coding style
run: composer coding-style
continue-on-error: ${{ matrix.experimental }}
run: composer test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ phpcs.xml
phpunit.xml
.idea/
.phpunit.result.cache
.php-cs-fixer.cache
2 changes: 1 addition & 1 deletion .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'native_function_invocation' => true,
Expand Down
22 changes: 15 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "lstrojny/functional-php",
"name": "tithely/functional-php",
"description": "Functional primitives for PHP",
"keywords": [
"functional"
Expand All @@ -17,12 +17,12 @@
}
],
"require": {
"php": "^7.1|~8"
"php": "^8.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "~3.0",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.5",
"friendsofphp/php-cs-fixer": "^2.17"
"phpunit/phpunit": "^9.6",
"friendsofphp/php-cs-fixer": "v3.84"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -132,8 +132,16 @@
}
},
"scripts": {
"tests": "vendor/bin/phpunit",
"coding-style": "vendor/bin/phpcs && vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php_cs.dist",
"clear": "rm -rf vendor/"
"test": "vendor/bin/phpunit",
"test:84": "docker exec -w /app functional_php_84 ./vendor/bin/phpunit --colors=always --no-coverage",
"lint:scan": "vendor/bin/php-cs-fixer fix src --config=.php-cs-fixer.dist.php --dry-run",
"lint:fix": "vendor/bin/php-cs-fixer fix src --config=.php-cs-fixer.dist.php",
"clear": "rm -rf vendor/",
"clean-vendor": "rm -rf vendor && rm -rf composer.lock",
"docker:start": "docker compose -p functional_php -f docker/docker-compose.yml up -d",
"docker:stop": "docker compose -p functional_php -f docker/docker-compose.yml down",
"docker:rebuild": "docker compose -p functional_php -f docker/docker-compose.yml build --force-rm && docker-compose -p functional_php -f docker/docker-compose.yml up -d --remove-orphans",
"docker:rebuild:nocache": "docker compose -p functional_php -f docker/docker-compose.yml build --force-rm --no-cache && docker-compose -p functional_php -f docker/docker-compose.yml up -d --remove-orphans",
"docker:shell": "docker exec -w /app -it functional_php_84 /bin/bash"
}
}
2 changes: 2 additions & 0 deletions docker/custom.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
post_max_size = 100M
max_execution_time = 300
17 changes: 17 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
functional_php_84:
build:
dockerfile: docker/php/84.Dockerfile
context: ../
container_name: functional_php_84
volumes:
- ../:/app
networks:
- tithely_hub_code-network
environment:
- CONF_DISABLED=xdebug
- PCOV_ENABLED=1
- PCOV_DIRECTORY=/app
networks:
tithely_hub_code-network:
external: true
13 changes: 13 additions & 0 deletions docker/php/84.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM tithely/php:8.4-apache-dev

#------------------------------
# Begin changes below this note
#------------------------------

# Install custom packages
RUN apt-get update -qq && \
apt-get install -qq \
vim

# Copy custom php.ini settings
COPY docker/custom.ini /usr/local/etc/php/conf.d/custom_overrides.ini
4 changes: 2 additions & 2 deletions src/Functional/CompareObjectHashOn.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* Returns a comparison function that can be used with e.g. `usort()`
*
* @param callable $comparison A function that compares the two values. Pick e.g. strcmp() or strnatcasecmp()
* @param callable $keyFunction A function that takes an argument and returns the value that should be compared
* @param callable|null $keyFunction A function that takes an argument and returns the value that should be compared
* @return callable
* @no-named-arguments
*/
function compare_object_hash_on(callable $comparison, callable $keyFunction = null)
function compare_object_hash_on(callable $comparison, ?callable $keyFunction = null)
{
$keyFunction = $keyFunction ? compose($keyFunction, 'spl_object_hash') : 'spl_object_hash';

Expand Down
4 changes: 2 additions & 2 deletions src/Functional/CompareOn.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* Returns a comparison function that can be used with e.g. `usort()`
*
* @param callable $comparison A function that compares the two values. Pick e.g. strcmp() or strnatcasecmp()
* @param callable $reducer A function that takes an argument and returns the value that should be compared
* @param callable|null $reducer A function that takes an argument and returns the value that should be compared
* @return callable
* @no-named-arguments
*/
function compare_on(callable $comparison, callable $reducer = null)
function compare_on(callable $comparison, ?callable $reducer = null)
{
if ($reducer === null) {
return static function ($left, $right) use ($comparison) {
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Concat.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* Concatenates zero or more strings
*
* @param string[] ...$strings
* @param string ...$strings
* @return string
* @no-named-arguments
*/
Expand Down
1 change: 1 addition & 0 deletions src/Functional/Curry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @param bool $required curry optional parameters ?
* @return callable a curryied version of the given function
* @no-named-arguments
* @throws \ReflectionException
*/
function curry(callable $function, $required = true)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Inspired by JavaScript’s `Object.entries`, and Python’s `enumerate`,
* convert a key-value map into an array of key-value pairs
*
* @see Functional\from_entries
* @see from_entries
* @param Traversable|array $collection
* @param int $start
* @return array
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Every.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @return bool
* @no-named-arguments
*/
function every($collection, callable $callback = null)
function every($collection, ?callable $callback = null)
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/Functional/First.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @return mixed
* @no-named-arguments
*/
function first($collection, callable $callback = null)
function first($collection, ?callable $callback = null)
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/Functional/FromEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Inspired by JavaScript’s `Object.fromEntries`,
* convert an array of key-value pairs into a key-value map
*
* @see Functional\entries
* @see entries
* @param Traversable|array $collection
* @return array
* @no-named-arguments
Expand Down
23 changes: 11 additions & 12 deletions src/Functional/Functional.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

final class Functional
{

/**
* @see \Function\ary
*/
Expand Down Expand Up @@ -254,58 +253,58 @@ final class Functional
const less_than_or_equal = '\Functional\less_than_or_equal';

/**
* @see \Functional\lexicographic_compare
* @see lexicographic_compare
*/
const lexicographic_compare = '\Functional\lexicographic_compare';

/**
* @see \Functional\map
* @see map
*/
const map = '\Functional\map';

/**
* @see \Functional\matching
* @see matching
* @deprecated
*/
const match = '\Functional\match';

/**
* @see \Functional\matching
* @see matching
*/
const matching = '\Functional\matching';

/**
* @see \Functional\maximum
* @see maximum
*/
const maximum = '\Functional\maximum';

/**
* @see \Functional\memoize
* @see memoize
*/
const memoize = '\Functional\memoize';

/**
* @see \Functional\minimum
* @see minimum
*/
const minimum = '\Functional\minimum';

/**
* @see \Functional\none
* @see none
*/
const none = '\Functional\none';

/**
* @see \Functional\noop
* @see noop
*/
const noop = '\Functional\noop';

/**
* @see \Functional\not
* @see not
*/
const not = '\Functional\not';

/**
* @see \Functional\omit_keys
* @see omit_keys
*/
const omit_keys = '\Functional\omit_keys';

Expand Down
5 changes: 5 additions & 0 deletions src/Functional/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ function group($collection, callable $callback)

InvalidArgumentException::assertValidArrayKey($groupKey, __FUNCTION__);

// Avoid implicit conversion, since float numbers cannot be used as array keys
if (\is_numeric($groupKey)) {
$groupKey = (int) $groupKey;
}

if (!isset($groups[$groupKey])) {
$groups[$groupKey] = [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Functional/Head.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* Alias for Functional\first
*
* @param Traversable|array $collection
* @param callable $callback
* @param callable|null $callback
* @return mixed
* @no-named-arguments
*/
function head($collection, callable $callback = null)
function head($collection, ?callable $callback = null)
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @return mixed
* @no-named-arguments
*/
function last($collection, callable $callback = null)
function last($collection, ?callable $callback = null)
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Memoize.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @return mixed
* @no-named-arguments
*/
function memoize(callable $callback = null, $arguments = [], $key = null)
function memoize(?callable $callback = null, $arguments = [], $key = null)
{
static $storage = [];
if ($callback === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/None.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @return bool
* @no-named-arguments
*/
function none($collection, callable $callback = null)
function none($collection, ?callable $callback = null)
{
InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Pick.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @return mixed
* @no-named-arguments
*/
function pick($collection, $index, $default = null, callable $callback = null)
function pick($collection, $index, $default = null, ?callable $callback = null)
{
InvalidArgumentException::assertArrayAccess($collection, __FUNCTION__, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @return boolean
* @no-named-arguments
*/
function poll(callable $callback, $timeout, Traversable $delaySequence = null)
function poll(callable $callback, $timeout, ?Traversable $delaySequence = null)
{
InvalidArgumentException::assertIntegerGreaterThanOrEqual($timeout, 0, __FUNCTION__, 2);

Expand Down
Loading
Loading