endtoend-test-psl/README.md

106 lines
4.2 KiB
Markdown
Raw Normal View History

2019-12-24 01:52:07 +01:00
# Psl - PHP Standard Library
![Unit tests status](https://github.com/azjezz/psl/workflows/unit%20tests/badge.svg?branch=develop)
![Static analysis status](https://github.com/azjezz/psl/workflows/static%20analysis/badge.svg?branch=develop)
![Security analysis status](https://github.com/azjezz/psl/workflows/security%20analysis/badge.svg?branch=develop)
![Coding standards status](https://github.com/azjezz/psl/workflows/coding%20standards/badge.svg?branch=develop)
[![TravisCI Build Status](https://travis-ci.com/azjezz/psl.svg?branch=develop)](https://travis-ci.com/azjezz/psl)
2020-07-06 20:35:34 +02:00
[![Coverage Status](https://coveralls.io/repos/github/azjezz/psl/badge.svg?branch=develop)](https://coveralls.io/github/azjezz/psl?branch=develop)
2020-03-01 12:01:57 +01:00
[![Type Coverage](https://shepherd.dev/github/azjezz/psl/coverage.svg)](https://shepherd.dev/github/azjezz/psl)
2020-09-05 02:58:43 +02:00
[![SymfonyInsight](https://insight.symfony.com/projects/1e053a4a-aaab-4a52-9059-c4883bfd46f7/mini.svg)](https://insight.symfony.com/projects/1e053a4a-aaab-4a52-9059-c4883bfd46f7)
2019-12-25 20:17:14 +01:00
[![Total Downloads](https://poser.pugx.org/azjezz/psl/d/total.svg)](https://packagist.org/packages/azjezz/psl)
[![Latest Stable Version](https://poser.pugx.org/azjezz/psl/v/stable.svg)](https://packagist.org/packages/azjezz/psl)
[![License](https://poser.pugx.org/azjezz/psl/license.svg)](https://packagist.org/packages/azjezz/psl)
2019-12-25 19:39:01 +01:00
Psl is a standard library for PHP, inspired by [hhvm/hsl](https://github.com/hhvm/hsl).
The goal of Psl is to provide a consistent, centralized, well-typed set of APIs for PHP programmers.
2019-12-24 01:52:07 +01:00
## Example
```php
<?php
declare(strict_types=1);
use Psl\{Dict, Str, Vec};
2019-12-24 01:52:07 +01:00
/**
* @psalm-param iterable<?int> $codes
*/
function foo(iterable $codes): string
{
$codes = Vec\filter_nulls($codes);
$chars = Dict\map($codes, fn(int $code): string => Str\chr($code));
2020-07-06 22:45:13 +02:00
return Str\join($chars, ', ');
2019-12-24 01:52:07 +01:00
}
foo([95, 96, null, 98]);
// 'a, b, d'
```
## Installation
2021-01-17 21:07:12 +01:00
Supported installation method is via [composer](https://getcomposer.org):
2019-12-24 01:52:07 +01:00
```console
2020-12-21 19:14:41 +01:00
$ composer require azjezz/psl
2019-12-24 01:52:07 +01:00
```
2021-02-09 21:15:06 +01:00
### Psalm Integration
PSL comes with a [Psalm](https://psalm.dev/) plugin, that improves return type for PSL functions that psalm cannot infer from source code.
To enable the Psalm plugin, add the `Psl\Internal\Psalm\Plugin` class to your psalm configuration file plugins list as follows:
```xml
<psalm>
...
<plugins>
...
<pluginClass class="Psl\Integration\Psalm\Plugin" />
2021-02-09 21:15:06 +01:00
</plugins>
</psalm>
```
2019-12-24 01:52:07 +01:00
## 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.
2019-12-24 01:52:07 +01:00
- 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`)
## Sponsors
Thanks to our sponsors and supporters:
| JetBrains |
|---|
| <a href="https://www.jetbrains.com/?from=PSL ( PHP Standard Library )" title="JetBrains" target="_blank"><img src="https://res.cloudinary.com/azjezz/image/upload/v1599239910/jetbrains_qnyb0o.png" height="120" /></a> |
2019-12-24 01:52:07 +01:00
## License
The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information.