Passed
Push — master ( bf86e6...5ea322 )
by Sébastien
07:21
created

BitrateAssertionsTrait::ensureValidBitRateUnit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Common\Assert;
6
7
use Soluble\MediaTools\Common\Exception\InvalidArgumentException;
8
9
trait BitrateAssertionsTrait
10
{
11
    /**
12
     * Ensure that a bitrate is valid (optional unit: k or M ).
13
     *
14
     * @throws InvalidArgumentException
15
     */
16
    protected function ensureValidBitRateUnit(string $bitrate): void
17
    {
18
        if (preg_match('/^\d+(k|M)?$/i', $bitrate) !== 1) {
19
            throw new InvalidArgumentException(sprintf('"%s"', $bitrate));
20
        }
21
    }
22
}
23