BitrateAssertionsTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 14
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ensureValidBitRateUnit() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @see       https://github.com/soluble-io/soluble-mediatools for the canonical repository
7
 *
8
 * @copyright Copyright (c) 2018-2020 Sébastien Vanvelthem. (https://github.com/belgattitude)
9
 * @license   https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT
10
 */
11
12
namespace Soluble\MediaTools\Common\Assert;
13
14
use Soluble\MediaTools\Common\Exception\InvalidArgumentException;
15
16
trait BitrateAssertionsTrait
17
{
18
    /**
19
     * Ensure that a bitrate is valid (optional unit: k or M ).
20
     *
21
     * @throws InvalidArgumentException
22
     */
23 10
    private function ensureValidBitRateUnit(string $bitrate): void
24
    {
25 10
        if (preg_match('/^\d+(k|M)?$/i', $bitrate) !== 1) {
26 2
            throw new InvalidArgumentException(
27 2
                sprintf(
28 2
                    'Invalid bitrate given: "%s" (int(K|M)?)',
29
                    $bitrate
30
                )
31
            );
32
        }
33 8
    }
34
}
35