Passed
Branch master (e39bed)
by thomas
01:58
created

Util::networkByCoinName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 2
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Trezor\Device;
6
7
use BitWasp\TrezorProto\CoinType;
8
use BitWasp\TrezorProto\Features;
9
10
class Util
11
{
12
    /**
13
     * @param string $coinName
14
     * @param Features $features
15
     * @return CoinType|null
16
     */
17 2
    public static function networkByCoinName(string $coinName, Features $features)
18
    {
19 2
        foreach ($features->getCoinsList() as $coinType) {
20
            /** @var CoinType $coinType */
21 2
            if ($coinType->getCoinName() === $coinName) {
22 2
                return $coinType;
23
            }
24
        }
25
26 1
        return null;
27
    }
28
29
    /**
30
     * @param string $shortcut
31
     * @param Features $coinTypes
32
     * @return CoinType|null
33
     */
34 2
    public static function networkByCoinShortcut(string $shortcut, Features $coinTypes)
35
    {
36 2
        foreach ($coinTypes->getCoinsList() as $coinType) {
37
            /** @var CoinType $coinType */
38 2
            if ($coinType->getCoinShortcut() === $shortcut) {
39 2
                return $coinType;
40
            }
41
        }
42
43 1
        return null;
44
    }
45
}
46