PHPackages                             peekandpoke/psi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. peekandpoke/psi

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

peekandpoke/psi
===============

Php Simple Iterations. Inspired by Java Streams Api.

v1.2.0(7y ago)25.5k1BSD-3-ClausePHPPHP &gt;=7.0

Since May 9Pushed 7y ago2 watchersCompare

[ Source](https://github.com/PeekAndPoke/psi)[ Packagist](https://packagist.org/packages/peekandpoke/psi)[ RSS](/packages/peekandpoke-psi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (41)Used By (1)

[![Code Coverage](https://camo.githubusercontent.com/1323daf102b9e8106940d0cc3018577d1e162ca926c302745fff6e9805b90562/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5065656b416e64506f6b652f7073692f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PeekAndPoke/psi/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b17fe52b6b913e9610ff656f5021109e8af4507fc79acdc2afa40d782fe28b3d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5065656b416e64506f6b652f7073692f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PeekAndPoke/psi/?branch=master)[![Build Status](https://camo.githubusercontent.com/d0af40112b79173f821a6df9eb7283c08b1426fd75896770f9baabb3458da378/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5065656b416e64506f6b652f7073692f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/PeekAndPoke/psi/build-status/master)

Introduction
============

[](#introduction)

PSI helps you to write cleaner and more stable PHP-Code. Especially when it comes to iterating, filtering, mapping, sorting arrays or array-like data.

PSI consists of multiple small operations that can be combined and chained. Doing so results in easier to read and more expressive code.

PSI supports PHP versions &gt;= 7.0

TOC
===

[](#toc)

- [Examples](#examples)
- [Details Docs](#detailed-documentation)
- [UnitTests](#unittests)
- [Releases](#releases)
- [Todos and ideas](#todos-and-ideas)

Examples
--------

[](#examples)

Let's have a look at some examples.

### Get all adults

[](#get-all-adults)

```
/** @var Person[] $input */
$input = $service->getStuff();

/** @var Person[] $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filter(function (Person $p) { return $p->getAge() >= 18; })
  ->toArray();
```

In plain PHP this might looks like:

```
/** @var Person[] $input */
$ipnut = $service->getStuff();

$result = [];

foreach ($input as $item) {

  if ($item instanceof Person && $item->getAge() >= 18) {
    $result[] = $item
  }
}

```

### Get all adults and sort them by age

[](#get-all-adults-and-sort-them-by-age)

```
/** @var Person[] $input */
$input = $service->getStuff();

/** @var Person[] $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filter(function (Person $p) { return $p->getAge() >= 18; })
  ->sortBy(function (Person $p) { return $p->getAge(); })
  ->toArray();
```

In plain PHP this might looks like:

```
/** @var Person[] $input */
$ipnut = $service->getStuff();

$result = [];

foreach ($input as $item) {

  if ($item instanceof Person && $item->getAge() >= 18) {
    $result[] = $item
  }
}

usort($result, function (Person $p1, Person $p2) {

  return $p1->getAge()  $p2->getAge();
});
```

### Get all adults and sort them by age descending

[](#get-all-adults-and-sort-them-by-age-descending)

```
/** @var Person[] $input */
$input = $service->getStuff();

/** @var Person[] $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filter(function (Person $p) { return $p->getAge() >= 18; })
  ->sortBy(function (Person $p) { return $p->getName(); })
  ->reverse()
  ->toArray();
```

Mapping
-------

[](#mapping)

With *Psi::map()* you can convert incoming data.

For example lets convert all persons to ints (the persons age)

```
/** @var Person[] $input */
$input = $service->getStuff();

$result = Psi::it($input)
  ->map(function (Person $p) { return $p->getAge(); })
  ->toArray();
```

This might result in

```
[10, 20, 18, 31, ...]

```

We could also convert each Person into something else.

```
/** @var Person[] $input */
$input = $service->getStuff();

$result = Psi::it($input)
  ->sortBy(function (Person $p) { return $p->getName(); })
  ->map(function (Person $p) { return [ $p->getName(), $p->getAge() ]; })
  ->toArray();
```

This might result in

```
[["Elsa", 20], ["Joe", 10], ["John", 18], ["Mary", 31], ...]

```

Advanced filtering
------------------

[](#advanced-filtering)

With *Psi::filterBy()* you can combine mapping and filtering.

Let's get all adults by checking the age using Psi\\IsGreaterThanOrEqual().

The example below will also give you all Persons with an age greater than or equal to 18.

```
$input = $service->getStuff();

/** @var Person[] $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filterBy(
    function (Person $p) { return $p->getAge(); }, // map the input
    new Psi\IsGreaterThanOrEqual(18)               // apply filter on the mapped value
  )
  ->toArray();
```

Check if all or any elements match
----------------------------------

[](#check-if-all-or-any-elements-match)

With *Psi::all()* you can check if all elements match the given condition

```
$result = Psi::it([1, 1, 1])
    ->all(new Psi\IsEqualTo(1));  // true, all elements are equal to 1

$result = Psi::it([1, 1, 1])
    ->all(function ($it) { return $it === 1 });  // true, all elements are equal to 1

$result = Psi::it([1, 2, 3])
    ->all(new Psi\IsEqualTo(1));  // false, not all elements are equal to 1

$result = Psi::it([])
    ->all(new Psi\IsEqualTo(1));  // true, since no element does not match the condition
```

With *Psi::any()* you can check if there is at least one element matching the condition

```
$result = Psi::it([2, 1, 4])
    ->any(new Psi\IsEqualTo(1));  // true, there is one element that is equal to 1

$result = Psi::it([2, 1, 4])
    ->any(function ($it) { return $it === 1 });  // true, there is one element that is equal to 1

$result = Psi::it([2, 3, 4])
    ->any(new Psi\IsEqualTo(1));  // false, there is no element that is equal to 1

$result = Psi::it([])
    ->any(new Psi\IsEqualTo(1));  // false, when there is no element in the list, then none can match
```

Grouping
--------

[](#grouping)

Let's group all persons by their age

```
$input = $service->getStuff();

/** @var Person[] $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->groupBy(
    function (Person $p) { return $p->getAge(); },   // define the group
  )
  ->toKeyValueArray();                               // toKeyValueArray() will preserve keys, in our case the age-groups

var_dump($result);
```

This might output:

```
array(3) {
  [7] =>
  array(2) {
    [0] =>
    object(Person) ...
    [1] =>
    object(Person) ...
  }
  [15] =>
  array(1) {
    [0] =>
    object(Person) ...
    ...
  }
  [21] =>
  array (2) {
    ...
  }
  ...
}

```

Multiple inputs
---------------

[](#multiple-inputs)

You can pass multiple array or array-like parameters to Psi::it(... $inputs)

```
/** @var Person[] $result */
$result = Psi::it(
    $service->getStuff(),
    $service->getMoreStuff(),
    $service->getEvenMoreStuff()
  )
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->toArray();
```

Skip and Limit
--------------

[](#skip-and-limit)

Let's get up to 5 adults but skip the first 10:

```
$input = $service->getStuff();

/** @var Person[] $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filter(function (Person $p) { return $p->getAge() >= 18; })
  ->skip(10)
  ->limit(5)
  ->toArray();
```

Or let's skip the first 10 no matter what they are and then get up to 5 adults

```
$input = $service->getStuff();

/** @var Person[] $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->skip(10)
  ->filter(function (Person $p) { return $p->getAge() >= 18; })
  ->limit(5)
  ->toArray();
```

Or let's skip the first 10, then get up to 5 and then filter the adults out of these

```
$input = $service->getStuff();

/** @var Person[] $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->skip(10)
  ->limit(5)
  ->filter(function (Person $p) { return $p->getAge() >= 18; })
  ->toArray();
```

Count, sum, min, max, average, median
-------------------------------------

[](#count-sum-min-max-average-median)

Let's count the number of adults:

```
$input = $service->getStuff();

/** @var float $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filter(function (Person $p) { return $p->getAge() >= 18; })
  ->count();
```

Let's sum the age of all persons:

```
$input = $service->getStuff();

/** @var float $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->map(function (Person $p) { return $p->getAge(); })
  ->sum();
```

Let's get the youngest age of all people we know:

```
$input = $service->getStuff();

/** @var float $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->map(function (Person $p) { return $p->getAge(); })
  ->min();
```

Let's get the oldest age of all:

```
$input = $service->getStuff();

/** @var float $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->map(function (Person $p) { return $p->getAge(); })
  ->max();
```

Let's get the average age:

```
$input = $service->getStuff();

/** @var float $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->map(function (Person $p) { return $p->getAge(); })
  ->avg();
```

Let's get the median age:

```
$input = $service->getStuff();

/** @var float $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->map(function (Person $p) { return $p->getAge(); })
  ->median();
```

Let's get the median age of all adults:

```
$input = $service->getStuff();

/** @var float $result */
$result = Psi::it($input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filter(function (Person $p) { return $p->getAge() >= 18; })
  ->map(function (Person $p) { return $p->getAge(); })
  ->median();
```

Get first, last, random
-----------------------

[](#get-first-last-random)

Let's get the first person that fits a certain condition (name starting with "A")

```
/** @var Person|null $result */
$result = Psi::it(input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filterBy(
    function(function (Person $p) { return $p->getName(); }),
    new Psi\Str\IsStartingWith('A')
  )
  ->getFirst()

```

Let's get the last person that fits a certain condition (name starting with "A")

```
/** @var Person|null $result */
$result = Psi::it(input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filterBy(
    function(function (Person $p) { return $p->getName(); }),
    new Psi\Str\IsStartingWith('A')
  )
  ->getLast()

```

Let's get a random person that fits a certain condition (name starting with "A")

```
/** @var Person|null $result */
$result = Psi::it(input)
  ->filter(new Psi\IsInstanceOf(Person::class))
  ->filterBy(
    function(function (Person $p) { return $p->getName(); }),
    new Psi\Str\IsStartingWith('A')
  )
  ->getRandom()

```

Detailed Documentation
======================

[](#detailed-documentation)

Filters - type checks
---------------------

[](#filters---type-checks)

### IsArray and IsNotArray

[](#isarray-and-isnotarray)

Filters for Arrays using is\_array()

```
$result = Psi::it($input)->filter(new Psi\IsArray())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotArray())->toArray();
```

### IsBool and IsNotBool

[](#isbool-and-isnotbool)

Filter for Booleans using is\_bool()

```
$result = Psi::it($input)->filter(new Psi\IsBool())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotBool())->toArray();
```

### IsCallable and IsNotCallable

[](#iscallable-and-isnotcallable)

Filter for Callables using is\_callable()

```
$result = Psi::it($input)->filter(new Psi\IsCallable())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotCallable())->toArray();
```

### IsDateString and IsNotDateString

[](#isdatestring-and-isnotdatestring)

Checks if the given string is a string that would be understood be new \\DateTime($str)

```
$result = Psi::it($input)->filter(new Psi\IsDateString())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotDateString())->toArray();
```

### IsEmpty and IsNotEmpty

[](#isempty-and-isnotempty)

Filter for empty things using empty()

```
$result = Psi::it($input)->filter(new Psi\IsEmpty())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotEmpty())->toArray();
```

### IsInstanceOf and IsNotInstanceOf

[](#isinstanceof-and-isnotinstanceof)

Filter for class instance

```
$result = Psi::it($input)->filter(new Psi\IsInstanceOf())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotInstanceOf())->toArray();
```

### IsInteger and IsNotInteger

[](#isinteger-and-isnotinteger)

Filter for integers using is\_int()

```
$result = Psi::it($input)->filter(new Psi\IsInteger())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotInteger())->toArray();
```

### IsIntegerString and IsNotIntegerString

[](#isintegerstring-and-isnotintegerstring)

Filter for strings that contain an integer

```
$result = Psi::it($input)->filter(new Psi\IsIntegerString())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotIntegerString())->toArray();
```

### IsNull and IsNotNull

[](#isnull-and-isnotnull)

Filter for nulls

```
$result = Psi::it($input)->filter(new Psi\IsNull())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotNull())->toArray();
```

### IsNumeric and IsNotNumeric

[](#isnumeric-and-isnotnumeric)

Filter for numeric values using is\_numeric()

```
$result = Psi::it($input)->filter(new Psi\IsNull())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotNull())->toArray();
```

### IsObject and IsNotObject

[](#isobject-and-isnotobject)

Filter for objects

```
$result = Psi::it($input)->filter(new Psi\IsObject())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotObject())->toArray();
```

### IsResource and IsNotResource

[](#isresource-and-isnotresource)

Filter for resources

```
$result = Psi::it($input)->filter(new Psi\IsResource())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotResource())->toArray();
```

### IsScalar and IsNotScalar

[](#isscalar-and-isnotscalar)

Filter for scalar values using is\_scalar()

```
$result = Psi::it($input)->filter(new Psi\IsResource())->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotResource())->toArray();
```

Filter - comparison
-------------------

[](#filter---comparison)

### IsEqualTo and IsNotEqualTo

[](#isequalto-and-isnotequalto)

Filter for NON type safe eqaulity (==). See IsSame / IsNotSame for === comparison

```
$result = Psi::it($input)->filter(new Psi\IsEqualTo("Summer"))->toArray();

$result = Psi::it($input)->filter(new Psi\IsNotEqualTo("Winter"))->toArray();
```

UnitTests
=========

[](#unittests)

First install all dependencies

```
./composer install
```

Then run all tests

```
vendor/bin/phpunit
```

Releases
========

[](#releases)

new in v1.2.0
-------------

[](#new-in-v120)

*REMOVED PHP 5.6 SUPPORT*

Added

- Psi::all()
- Psi::any()

new in v1.1.0
-------------

[](#new-in-v110)

Moved mapper ToFloat, ToInteger, ToString to Psi\\Map...

Old versions are kept for compatibility and marked as deprecated.

new in v0.6.4
-------------

[](#new-in-v064)

### Psi::chunk

[](#psichunk)

Will split the stream into chunks of the given size.

```
Psi::it(range(0, 10))
  ->chunk(3)
  ->toArray();
```

will result in

```
[
  [0, 1, 2],
  [3, 4, 5],
  [6, 7, 8],
  [9, 10]
]

```

### Psi::skip

[](#psiskip)

Skips the first n elements in the current stream

```
Psi::it(range(0, 20))
  ->filter(new IsMultipleOf(2))
  ->skip(5)
  ->toArray();
```

will result in

```
[10, 12, 14, 16, 18, 20]

```

### Psi::limit

[](#psilimit)

Limits the result to the first n element in the current stream

```
Psi::it(range(0, 20))
  ->filter(new IsMultipleOf(2))
  ->limit(5)
  ->toArray();
```

will result in

```
[0, 2, 4, 6, 8]

```

### Psi::takeWhile

[](#psitakewhile)

Take all elements of the input stream while the condition is met

```
Psi::it(range(0, 20))
  ->takeWhile(new Psi\IsLessThan(5))
  ->toArray();
```

will result in

```
[0, 1, 2, 3, 4]

```

### Psi::takeUntil

[](#psitakeuntil)

Take all elements of the input stream until the condition is met

```
Psi::it(range(0, 20))
  ->takeUntil(new Psi\IsGreaterThan(5))
  ->toArray();
```

will result in

```
[0, 1, 2, 3, 4, 5]

```

### Psi::getLast

[](#psigetlast)

Get the last element of the stream.

```
Psi::it([1, 2, 3])
  ->filter(function ($i) { return $i < 3; })
  ->getLast()
```

will result in

```
2
```

### Psi::getRandom

[](#psigetrandom)

Will select a random element from the stream.

```
Psi::it([1, 2, 3])
  ->filter(function ($i) { return $i < 3; })
  ->getRandom()
```

will result in

```
1 or 2

```

### Num::IsMultipleOf and Num::IsNotMultipleOf

[](#numismultipleof-and-numisnotmultipleof)

Filters all numbers that are a multiple of the given factor

```
Psi::it([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
  ->filter(new Psi\Num\IsMultipleOf(3))
  ->toArray();
```

will result in

```
[0, 3, 6, 9]

```

### Num::IsPrime and Num::IsNotPrime

[](#numisprime-and-numisnotprime)

Filters all number that are prime number.

CAUTION: do not use this impl for big numbers, a it can be very slow.

```
Psi::it(range(0, 30))
    ->filter(new Psi\Num\IsPrime())
    ->toArray();
```

will result in

```
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

```

new in v0.6.3
-------------

[](#new-in-v063)

### Psi::filterBy()

[](#psifilterby)

In order to by able to use all other matchers on nested property / values of input objects, the method Psi::filterBy() was added

```
$result = Psi::it($persons)
  ->filterBy(
    function (Person $p) { return $p->getAge(); },
    new IsLessThan(18)
  )
  ->toArray()
```

### Psi::uniqueBy

[](#psiuniqueby)

Finds unique elements by first passing them through a mapper.

```
$result = Psi::it($persons)
  ->uniqueBy(
    function (Person $p) { return $person->getName(); }
  )
  ->toArray();
```

### ToFloat

[](#tofloat)

Maps inputs to floats.

```
$result = Psi::it($values)
  ->map(new Psi\ToFloat())
  ->toArray();
```

### ToInteger

[](#tointeger)

Maps inputs to integers.

```
$result = Psi::it($values)
  ->map(new Psi\ToInteger())
  ->toArray();
```

### ToString

[](#tostring)

Maps inputs to strings.

```
$result = Psi::it($values)
  ->map(new Psi\ToString())
  ->toArray();
```

### Str::IsStartingWith and Str::IsNotStartingWith - with or with case

[](#strisstartingwith-and-strisnotstartingwith---with-or-with-case)

Filters all strings starting with the given needle. By default case-sensitive. Pass false as the second parameter to be non-case-sensitive.

```
$result = Psi::it($values)
  ->filter(new Psi\Str\IsStartingWith('a'))
  ->toArray();

$result = Psi::it($values)
  ->filter(new Psi\Str\IsNotStartingWith('a', false))
  ->toArray();
```

### Str::IsEndingWith and Str::IsNotEndingWith - with or without case

[](#strisendingwith-and-strisnotendingwith---with-or-without-case)

Filters all strings ending with the given needle. By default case-sensitive. Pass false as the second parameter to be non-case-sensitive.

```
$result = Psi::it($values)
  ->filter(new Psi\Str\IsEndingWith('a'))
  ->toArray();

$result = Psi::it($values)
  ->filter(new Psi\Str\IsNotEndingWith('a', false))
  ->toArray();
```

### Str::IsContaining and Str::IsNotContaining - with or without case

[](#striscontaining-and-strisnotcontaining---with-or-without-case)

Filters all strings containing the given needle. By default case-sensitive. Pass false as the second parameter to be non-case-sensitive.

```
$result = Psi::it($values)
  ->filter(new Psi\Str\IsContaining('a'))
  ->toArray();

$result = Psi::it($values)
  ->filter(new Psi\Str\IsNotContaining('a', false))
  ->toArray();
```

### Str::IsMatchingRegex and Str::IsNotMatchingRegex

[](#strismatchingregex-and-strisnotmatchingregex)

Filters all strings containing the given needle. By default case-sensitive. Pass false as the second parameter to be non-case-sensitive.

```
$result = Psi::it($values)
  ->filter(new Psi\Str\IsMatchingRegex('/[0-9]{2,}'))
  ->toArray();

$result = Psi::it($values)
  ->filter(new Psi\Str\IsNotMatchingRegex('/ABC/i'))
  ->toArray();
```

### Str::WithoutAccents

[](#strwithoutaccents)

Modifies a string by replacing special characters with the "normal" form, e.g.

```
Dragoş  ->  Dragos

Ärmel   ->  Aermel
Blüte   ->  Bluete
Straße  ->  Strasse

passé   ->  passe

```

```
$result = Psi::it($values)
  ->map(new Psi\Str\WithoutAccents())
  ->toArray();
```

new in v0.6.0 to v0.6.2
-----------------------

[](#new-in-v060-to-v062)

The internal folder structure was changed:

- public interface live now on the root level
- some over-engineering was removed (some classes removed)
- interface no longer have names like "UnaryFunctionInterface" but "UnaryFunction"

new in v0.5.0
-------------

[](#new-in-v050)

### Psi::groupBy

[](#psigroupby)

```
Psi::it(
  [ ['name' => 'a', 'val' => 1], ['name' => 'a', 'val' => 2], ['name' => 'b', 'val' => 1] ]
)
->groupBy(
  function ($o) { return $o['name']; }
)
->toArray()
```

would become

```
['a' => [ ['name' => 'a', 'val' => 1], ['name' => 'a', 'val' => 2] ], 'b' => ... ]
```

### Psi::sortBy

[](#psisortby)

Sort a list of objects by one of their properties, e.g. sorting persons by their age

```
$result = Psi::it($values)
  ->filterBy(
    function (Person $p) { return $p->getAge(); }
  )
  ->toArray()

```

Todos and ideas
---------------

[](#todos-and-ideas)

### general

[](#general)

- make custom TerminalOperations possible Psi::reduce()

### Unary filter functions for strings

[](#unary-filter-functions-for-strings)

String-Mappers

- Str::Camelize (StrToCamelCase)
- ... camel to dashes (StrToSlug)
- Str::UcFirst, Str::LcFirst
- Str::StrReplace
- Str::StrMbReplace
- Str::StrRegexReplace
- Str::StrMbRegexReplace

... for PHP-Types ... LocalDate::isSameDay

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~72 days

Total

40

Last Release

2800d ago

Major Versions

v0.6.3 → v1.0.02017-12-03

PHP version history (5 changes)v0.1.0PHP &gt;=5.3

v0.1.1PHP &gt;=5.4

v0.2.3PHP &gt;=5.5.10

v0.4.2PHP &gt;=5.6

v1.2.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/753129?v=4)[Karsten Gerber](/maintainers/PeekAndPoke)[@PeekAndPoke](https://github.com/PeekAndPoke)

---

Top Contributors

[![PeekAndPoke](https://avatars.githubusercontent.com/u/753129?v=4)](https://github.com/PeekAndPoke "PeekAndPoke (143 commits)")

---

Tags

functional-programmingimmutabilityphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/peekandpoke-psi/health.svg)

```
[![Health](https://phpackages.com/badges/peekandpoke-psi/health.svg)](https://phpackages.com/packages/peekandpoke-psi)
```

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)[symfony/filesystem

Provides basic utilities for the filesystem

4.6k669.1M3.2k](/packages/symfony-filesystem)[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k234.7M20.6k](/packages/friendsofphp-php-cs-fixer)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.0M191](/packages/danielstjules-stringy)[rubix/ml

A high-level machine learning and deep learning library for the PHP language.

2.2k1.4M28](/packages/rubix-ml)[voku/portable-utf8

Portable UTF-8 library - performance optimized (unicode) string functions for php.

52322.4M40](/packages/voku-portable-utf8)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
