ValidateByteRangeTrait::validateByteRange()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/**
4
 * PHP Client for DDN Web Object Scalar (WOS) API
5
 *
6
 * @license http://opensource.org/licenses/MIT
7
 * @link    https://github.com/caseyamcl/wosclient
8
 * @version 1.0
9
 * @package caseyamcl/wosclient
10
 * @author  Casey McLaughlin <[email protected]>
11
 *
12
 * For the full copyright and license information, please view the LICENSE
13
 * file that was distributed with this source code.
14
 *
15
 * ------------------------------------------------------------------
16
 */
17
18
namespace WosClient\Helper;
19
20
use WosClient\Exception\InvalidParameterException;
21
22
/**
23
 * Helper to validate a byte range header value
24
 *
25
 * The value must be in ###-### format
26
 *
27
 * @author Casey McLaughlin <[email protected]>
28
 */
29
trait ValidateByteRangeTrait
30
{
31
    /**
32
     * Verifies that byte range is in ####-#### format
33
     *
34
     * @param  string $byteRange
35
     * @throws \RuntimeException  If invalid byte range specified
36
     */
37
    protected function validateByteRange($byteRange)
38
    {
39
        if (! preg_match('/^(\d+)?-(\d+)?$/', $byteRange)) {
40
            throw new InvalidParameterException(
41
                "Invalid range specification (must be in ###-### format); multiple rangers are not supported"
42
            );
43
        }
44
    }
45
}
46