Passed
Push — master ( 9e5fe0...88d9d6 )
by Tom
04:35
created

Prefix   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 39
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 1
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A filter() 0 9 2
A verify() 0 9 2
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Value;
6
7
use Ktomk\Pipelines\Utility\App;
8
use UnexpectedValueException;
9
10
/**
11
 * Pipelines Prefix
12
 *
13
 * @package Ktomk\Pipelines\Value
14
 */
15
abstract class Prefix
16
{
17
    const DEFAULT_PREFIX = App::UTILITY_NAME;
18
19
    /**
20
     * @param string $prefix
21
     *
22
     * @return string
23
     */
24 2
    public static function verify($prefix)
25
    {
26 2
        if (preg_match('~^[a-z]{3,}$~', $prefix)) {
27 2
            return $prefix;
28
        }
29
30 1
        throw new UnexpectedValueException(sprintf(
31 1
            'invalid prefix: "%s"; a prefix is only lower-case letters with a minimum length of three characters',
32
            $prefix
33
        ));
34
    }
35
36
    /**
37
     * filter a prefix
38
     *
39
     * always return a verified prefix (string)
40
     *
41
     * @param null|string $prefix [optional] if null, defaults to the default prefix
42
     *
43
     * @return string verified prefix
44
     */
45 1
    public static function filter($prefix = null)
46
    {
47 1
        $buffer = $prefix;
48
49 1
        if (null === $buffer) {
50 1
            $buffer = self::DEFAULT_PREFIX;
51
        }
52
53 1
        return self::verify($buffer);
54
    }
55
}
56