Passed
Push — master ( 176280...4c9570 )
by Xavier
01:42
created

stringify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
use Tightenco\Collect\Support\Arr;
4
use PubPeerFoundation\PublicationDataExtractor\Support\DateHelper;
5
6
if (! function_exists('get_class_name')) {
7
    /**
8
     * @param $object
9
     * @return string
10
     */
11
    function get_class_name($object)
12
    {
13
        $className = get_class($object);
14
        $pos = strrpos($className, '\\');
15
16
        return substr($className, $pos + 1);
17
    }
18
}
19
20
if (! function_exists('date_from_parts')) {
21
    /**
22
     * Get Carbon Date Object from parts.
23
     *
24
     * @param  array $array
25
     * @return mixed
26
     */
27
    function date_from_parts($array)
28
    {
29
        return DateHelper::dateFromDateParts($array);
30
    }
31
}
32
33
if (! function_exists('date_from_pub_date')) {
34
    /**
35
     * Get Carbon Date Object from pub_date.
36
     *
37
     * @param  $object
38
     * @return mixed
39
     */
40
    function date_from_pub_date($object)
41
    {
42
        return DateHelper::dateFromPubDate($object);
43
    }
44
}
45
46
if (! function_exists('date_from_parseable_format')) {
47
    /**
48
     * Get Carbon Date Object from parseable string.
49
     *
50
     * @param  string $string
51
     * @return mixed
52
     */
53
    function date_from_parseable_format($string)
54
    {
55
        return DateHelper::dateFromParseableFormat($string);
56
    }
57
}
58
59
if (! function_exists('get_string')) {
60
    /**
61
     * Get string from array path.
62
     *
63
     * @param array $array
64
     * @param $key
65
     * @param  null  $default
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
66
     * @return mixed
67
     */
68
    function get_string($array, $key, $default = null)
69
    {
70
        return stringify(data_get($array, $key, $default));
71
    }
72
}
73
74
if (! function_exists('get_array')) {
75
    /**
76
     * Get array from array path.
77
     *
78
     * @param array $target
79
     * @param $key
80
     * @param  array $default
81
     * @return array
82
     */
83
    function get_array($target, $key, $default = [])
84
    {
85
        $target = is_array($target) ? array_filter($target) : $target;
0 ignored issues
show
introduced by
The condition is_array($target) is always true.
Loading history...
86
87
        return Arr::wrap(data_get($target, $key, $default));
88
    }
89
}
90
91
if (! function_exists('stringify')) {
92
    /**
93
     * Convert entry to string.
94
     *
95
     * @param  mixed  $data
96
     * @return string
97
     */
98
    function stringify($data)
99
    {
100
        if (is_array($data)) {
101
            return stringify($data[0]);
102
        }
103
104
        return (string) trim($data);
105
    }
106
}
107