Passed
Push — master ( 6ba3d6...287c0c )
by Xavier
05:28
created

find_emails_in_array()   A

Complexity

Conditions 1
Paths 1

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 1
eloc 3
nc 1
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  mixed $default
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 dot access key.
77
     *
78
     * @param mixed $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;
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 (empty($data)) {
101
            return '';
102
        }
103
104
        if (is_array($data)) {
105
            return stringify($data[0]);
106
        }
107
108
        return (string) trim($data);
109
    }
110
}
111
112
if (! function_exists('find_emails_in_array')) {
113
    /**
114
     * Find emails in array.
115
     *
116
     * @param  array $array
117
     * @return array
118
     */
119
    function find_emails_in_array($array)
120
    {
121
        $pattern = '/(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))/iD';
122
123
        preg_match_all($pattern, implode(' ', $array), $matches);
124
125
        return $matches[0];
126
    }
127
}
128