Go to file
2020-09-01 06:52:37 +01:00
docs Initial commit 2019-12-24 02:01:46 +01:00
src [Asio] ignore code coverage for WrappedResult::getException() 2020-09-01 06:52:37 +01:00
tests/Psl [Iter] test merge and zip 2020-09-01 06:52:09 +01:00
.coveralls.yml add coveralls integration 2019-12-25 19:39:01 +01:00
.gitattributes add .gitattributes 2020-08-24 22:09:11 +01:00
.gitignore ignore test logs 2020-08-27 15:45:10 +01:00
.php_cs.dist reconfigure php-cs-fixer 2019-12-25 20:41:33 +01:00
.scrutinizer.yml improve type coverage (#24) 2020-07-07 23:10:51 +01:00
.stickler.yml add stickler integration 2019-12-25 20:44:30 +01:00
.travis.yml add roave security advisories, and psalm taint analysis (#31) 2020-07-11 23:06:11 +01:00
appveyor.yml run tests on appveyor (#35) 2020-07-12 18:27:37 +01:00
composer.json [Json] introduce the JSON API (#46) 2020-08-08 05:09:49 +01:00
LICENSE Initial commit 2019-12-24 02:01:46 +01:00
phpunit.xml.dist [Iter] add tests (#34) 2020-07-16 16:11:54 +01:00
psalm.xml remove function stubs from psalm configurations (#32) 2020-07-11 23:45:32 +01:00
README.md add appveyor badge 2020-07-12 18:33:29 +01:00

Psl - PHP Standard Library

TravisCI Build Status Appveyor Build status Scrutinizer Build Status Coverage Status Type Coverage Scrutinizer Code Quality Code Intelligence Status Total Downloads Latest Stable Version License

Psl is a standard library for PHP, inspired by hhvm/hsl.

The goal of Psl is to provide a consistent, centralized, well-typed set of APIs for PHP programmers.

Example

<?php

declare(strict_types=1);

use Psl\Str;
use Psl\Iter;

/**
 * @psalm-param iterable<?int> $codes
 */
function foo(iterable $codes): string
{
    /** @var Iter\Iterator<int> $codes */
    $codes = Iter\filter_nulls($codes);
    /** @var Iter\Iterator<string> $chars */
    $chars = Iter\map($codes, fn(int $code): string => Str\chr($code));

    return Str\join($chars, ', ');
}

foo([95, 96, null, 98]);
// 'a, b, d'

Installation

This package doesn't have a stable release yet, but you can still install it using composer :

$ composer require azjezz/psl:dev-develop

Documentation

Documentation is not available yet.

Principles

  • All functions should be typed as strictly as possible
  • The library should be internally consistent
  • References may not be used
  • Arguments should be as general as possible. For example, for array functions, prefer iterable inputs where practical, falling back to array when needed.
  • Return types should be as specific as possible
  • All files should contain declare(strict_types=1);

Consistency Rules

This is not exhaustive list.

  • Functions argument order should be consistent within the library
    • All iterable-related functions take the iterable as the first argument ( e.g. Iter\map and Iter\filter )
    • $haystack, $needle, and $pattern are in the same order for all functions that take them
  • Functions should be consistently named.
  • If an operation can conceivably operate on either keys or values, the default is to operate on the values - the version that operates on keys should have _key suffix (e.g. Iter\last, Iter\last_key, Iter\contains, Iter\contains_key )
  • Find-like operations that can fail should return ?T; a second function should be added with an x suffix that uses an invariant to return T (e.g. Arr\last, Arr\lastx)
  • Iterable functions that do an operation based on a user-supplied keying function for each element should be suffixed with _by (e.g. Arr\sort_by, Iter\group_by, Math\max_by)

License

The MIT License (MIT). Please see LICENSE for more information.