Completed
Push — master ( aeb3a4...04afb5 )
by brian
01:57
created

Tokens::isSeparator()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4286
cc 3
eloc 6
nc 3
nop 2
crap 3
1
<?php
2
3
/**
4
 * @copyright   (c) 2006-present brian ridley
5
 * @author      brian ridley <[email protected]>
6
 * @license     http://opensource.org/licenses/MIT MIT
7
 */
8
9
namespace ptlis\ConNeg\Parser;
10
11
/**
12
 * Class constants used for tokenization.
13
 */
14
class Tokens
15
{
16
    /**
17
     * Token that indicates the boundary between variant data
18
     */
19
    const VARIANT_SEPARATOR = ',';
20
21
    /**
22
     * Token that indicates the boundary between the variant & any params attached to it.
23
     */
24
    const PARAMS_SEPARATOR = ';';
25
26
    /**
27
     * Token that splits the mime type & subtypes.
28
     */
29
    const MIME_SEPARATOR = '/';
30
31
    /**
32
     * Token that splits params into keys and values.
33
     */
34
    const PARAMS_KV_SEPARATOR = '=';
35
36
37
    /**
38
     * Return true if the provided string is one of the separator tokens defined in this class.
39
     *
40
     * @param string $string
41
     * @param bool $mimeField
42
     *
43
     * @return bool
44
     */
45 80
    public static function isSeparator($string, $mimeField)
46
    {
47
        $separatorList = array(
48 80
            self::VARIANT_SEPARATOR,
49 80
            self::PARAMS_SEPARATOR,
50
            self::PARAMS_KV_SEPARATOR
51 80
        );
52
53 80
        return in_array($string, $separatorList) || ($mimeField && Tokens::MIME_SEPARATOR === $string);
54
    }
55
}
56