GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PlainString::toFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace MysqlUuid\Formats;
4
5
/**
6
 * The traditional UUID string format
7
 */
8
class PlainString implements Format
9
{
10
    const FORMAT = '/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i';
11
12
    /**
13
     * Whether the given value appears to fit this format
14
     *
15
     * @param string $value
16
     * @return boolean
17
     */
18 4
    public function isValid($value)
19
    {
20 4
        return (boolean)preg_match(self::FORMAT, $value);
21
    }
22
23
    /**
24
     * Converts a formatted value to a set of fields
25
     *
26
     * @param string $value
27
     * @return array<string,string>
28
     */
29 5
    public function toFields($value)
30
    {
31 5
        return array_combine(['time_low', 'time_mid', 'time_high', 'clock_seq', 'node'], explode('-', $value));
32
    }
33
34
    /**
35
     * Converts a set of fields to a formatted value
36
     *
37
     * @param array <string,string> $fields
38
     * @return string
39
     */
40 2 View Code Duplication
    public function fromFields(array $fields)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42 2
        return sprintf(
43 2
            '%s-%s-%s-%s-%s',
44 2
            $fields['time_low'],
45 2
            $fields['time_mid'],
46 2
            $fields['time_high'],
47 2
            $fields['clock_seq'],
48 2
            $fields['node']
49 2
        );
50
    }
51
}
52