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

BitrateAssertionsTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 11
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A ensureValidBitRateUnit() 0 4 2
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