pull()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace BrenoRoosevelt;
5
6
/**
7
 * Pulls and returns an element by key
8
 *
9
 * @param array $set The array containing the elements/keys
10
 * @param string|int $key The key to be pulled
11
 * @param mixed $default default value that will be returned if the key does not exist
12
 * @return mixed|null pulled element or `default` parameter
13
 */
14
function pull(array &$set, $key, $default = null)
15
{
16
    $value = $set[$key] ?? $default;
17
    unset($set[$key]);
18
19
    return $value;
20
}
21