Passed
Push — master ( 41a056...2c31fa )
by Alec
02:47
created

swapTo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Helpers;
4
5
use AlecRabbit\Helpers\Classes\Picklock;
6
use AlecRabbit\Helpers\Classes\System;
7
8
if (!function_exists(__NAMESPACE__ . '\callMethod')) {
9
    /**
10
     * Calls method $methodName of object/class $objectOrClass using arguments ...$args.
11
     *
12
     * @param mixed $objectOrClass
13
     * @param string $methodName
14
     * @param mixed ...$args
15
     * @return mixed
16
     */
17
    function callMethod($objectOrClass, string $methodName, ...$args)
18
    {
19
        return
20 2
            Picklock::callMethod($objectOrClass, $methodName, ...$args);
21
    }
22
}
23
24
if (!function_exists(__NAMESPACE__ . '\getValue')) {
25
    /**
26
     * Gets value of property $propName of an object/class $objectOrClass
27
     *
28
     * @param mixed $objectOrClass
29
     * @param string $propName
30
     * @return mixed
31
     */
32
    function getValue($objectOrClass, string $propName)
33
    {
34
        return
35 2
            Picklock::getValue($objectOrClass, $propName);
36
    }
37
}
38
39
if (!function_exists(__NAMESPACE__ . '\inContainer')) {
40
    /**
41
     * Determine if run in container
42
     *
43
     * @return bool
44
     */
45
    function inContainer(): bool
46
    {
47 1
        return System::inContainer();
48
    }
49
}
50
51
if (!function_exists(__NAMESPACE__ . '\swap')) {
52
    /**
53
     * Swap variables values by references
54
     *
55
     * @param mixed $var1
56
     * @param mixed $var2
57
     * @return void
58
     */
59
    function swap(&$var1, &$var2): void
60
    {
61 5
        [$var1, $var2] = [$var2, $var1];
62 5
    }
63
}
64
65
if (!function_exists(__NAMESPACE__ . '\inRange')) {
66
    /**
67
     * Checks if int is in range
68
     *
69
     * @param int $value
70
     * @param int $min
71
     * @param int $max
72
     * @return bool
73
     */
74
    function inRange(int $value, int $min, int $max): bool
75
    {
76 7
        if ($min > $max) {
77 1
            swap($min, $max);
78
        }
79 7
        return ($min <= $value && $value <= $max);
80
    }
81
}
82