WhenTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A shouldReturnTruncate() 0 18 1
1
<?php
2
3
namespace Prelude\Tests;
4
5
use function Prelude\when;
6
use function Prelude\pipe;
7
8
class WhenTest extends \PHPUnit\Framework\TestCase
9
{
10
    /**
11
     * @test
12
     */
13
    public function shouldReturnTruncate()
14
    {
15
        $append = function ($x) {
16
            return function ($y) use ($x) {
17
                return $y.$x;
18
            };
19
        };
20
        $chunk = function ($str) {
21
            return substr($str, 0, 10);
22
        };
23
        $pred = function ($str) {
24
            return strlen($str) > 10;
25
        };
26
        $truncate = when($pred)(pipe($chunk, $append('…')));
27
28
        $this->assertEquals('12345', $truncate('12345'));
29
        $this->assertEquals('0123456789…', $truncate('0123456789ABC'));
30
    }
31
}
32