PHP code example of letsdrink / ouzo-goodies

1. Go to this page and download the library: Download letsdrink/ouzo-goodies library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

letsdrink / ouzo-goodies example snippets


$result = FluentArray::from($users)
             ->map(Functions::extractField('name'))
             ->filter(Functions::notEmpty())
             ->unique()
             ->toArray();

$result = FluentIterator::fromArray([1, 2, 3])
             ->cycle()
             ->limit(10)
             ->reindex()
             ->toArray(); // [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]

$product = new Product(['name' => 'super phone']);

$function = FluentFunctions::extractField('name')
      ->removePrefix('super')
      ->prepend(' extra')
      ->append('! ')
      ->surroundWith("***");

$result = Functions::call($function, $product); //=> '*** extra phone! ***'

$phones = Arrays::filter($products, FluentFunctions::extractField('type')->equals('PHONE'));

$cities = Arrays::map($users, Functions::extract()->getAddress('home')->city);

$string = Clock::now()
    ->plusYears(1)
    ->plusMonths(2)
    ->minusDays(3)
    ->format();

$product1 = new Product(['name' => 'b']);
$product2 = new Product(['name' => 'c']);
$product3 = new Product(['name' => 'a']);

$result = Arrays::sort([$product1, $product2, $product3], Comparator::compareBy('name'));

$animals = ['cat', 'dog', 'pig'];
Assert::thatArray($animals)->hasSize(3)->contains('cat');

Assert::thatString("Frodo")
     ->startsWith("Fro")
     ->endsWith("do")
     ->contains("rod")
     ->doesNotContain("fro")
     ->hasSize(5);

$mock = Mock::create();
Mock::when($mock)->someMethod('arg')->thenReturn('123');

$result = $mock->someMethod('arg');

$this->assertEquals('123', $result);
Mock::verify($mock)->method('arg');

$foo = new Foo();

CatchException::when($foo)->method();

CatchException::assertThat()->isInstanceOf("FooException");