ValidateByteRangeTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 17
rs 10

1 Method

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