Go to file
2021-03-27 20:10:18 +01:00
.github remove unused function call suppression (#165) 2021-03-24 09:23:04 +01:00
docs [Dict/Vec] optimize functions by using builtin array functions when possible (#169) 2021-03-26 09:14:11 +01:00
integration/Psalm recommand using the psalm-plugin package over builtin integration (#170) 2021-03-27 20:10:18 +01:00
src [Dict/Vec] optimize functions by using builtin array functions when possible (#169) 2021-03-26 09:14:11 +01:00
tests [Dict/Vec] optimize functions by using builtin array functions when possible (#169) 2021-03-26 09:14:11 +01:00
.gitattributes update git attributes (#109) 2021-01-17 17:08:49 +01:00
.gitignore ignore test logs 2020-08-27 15:45:10 +01:00
.php_cs.dist update documentation workflow, split component documentation, use PSL in documentation generator. 2021-03-15 03:02:42 +01:00
.phpcs.xml tweak phpcs configurations 2020-09-05 16:29:08 +01:00
CODE_OF_CONDUCT.md add CODE OF CONDUCT 2020-09-03 12:59:09 +02:00
composer.json recommand using the psalm-plugin package over builtin integration (#170) 2021-03-27 20:10:18 +01:00
LICENSE Initial commit 2019-12-24 02:01:46 +01:00
phpunit.xml.dist [Filesystem] Introduce filesystem component 2021-03-08 07:29:51 +01:00
psalm.xml remove unused function call suppression (#165) 2021-03-24 09:23:04 +01:00
README.md recommand using the psalm-plugin package over builtin integration (#170) 2021-03-27 20:10:18 +01:00
SECURITY.md add security policy 2020-09-30 22:22:19 +01:00

Psl - PHP Standard Library

Unit tests status Static analysis status Security analysis status Coding standards status Coding standards status Coverage Status Type Coverage 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, Vec};

/**
 * @psalm-param iterable<?int> $codes
 */
function foo(iterable $codes): string
{
    $codes = Vec\filter_nulls($codes);

    $chars = Vec\map($codes, fn(int $code): string => Str\chr($code));

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

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

Installation

Supported installation method is via composer:

composer require azjezz/psl

Psalm Integration

Please refer to the php-standard-library/psalm-plugin repository.

Documentation

You can read through the API documentation in docs/README.md.

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 )
  • 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)

Sponsors

Thanks to our sponsors and supporters:

JetBrains

License

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