Completed
Push — master ( 528f7d...f4b721 )
by Kacper
04:19
created

Helper.php ➔ dd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * XMPP Library
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Xmpp\Utils\helper;
17
use Kadet\Xmpp\Utils\Dumper;
18
19
/**
20
 * Returns exception friendly type of value.
21
 *
22
 * @param $value
23
 * @return string
24
 */
25
function typeof($value) : string
26
{
27
    if(is_object($value)) {
28
        return "object of type ".get_class($value);
29
    } elseif(is_resource($value)) {
30
        return get_resource_type($value).' resource';
31
    } else {
32
        return gettype($value);
33
    }
34
}
35
36
function partial(callable $callable, $argument, int $position = 0) : callable
37
{
38
    return function(...$arguments) use ($callable, $argument, $position) {
39
        $arguments = array_merge(
40
            array_slice($arguments, 0, $position),
41
            [ $argument ],
42
            array_slice($arguments, $position)
43
        );
44
45
        return $callable(...$arguments);
46
    };
47
}
48
49
function dd($value)
50
{
51
    echo Dumper::get()->dump($value).PHP_EOL.PHP_EOL;
52
}
53
54
function format($string, array $arguments = [])
55
{
56
    return str_replace(array_map(function($e) { return "{{$e}}"; }, array_keys($arguments)), $arguments, $string);
57
}
58