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.

UuidFormatter   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 0
loc 74
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A write() 0 20 2
A getFormattedVersion() 0 4 1
A getFormattedVariant() 0 4 1
A getContent() 0 6 1
1
<?php
2
/**
3
 * This file is part of the ramsey/uuid-console application
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright Copyright (c) Ben Ramsey <[email protected]>
9
 * @license http://opensource.org/licenses/MIT MIT
10
 * @link https://packagist.org/packages/ramsey/uuid-console Packagist
11
 * @link https://github.com/ramsey/uuid-console GitHub
12
 */
13
14
namespace Ramsey\Uuid\Console\Util;
15
16
use Ramsey\Uuid\Uuid;
17
use Ramsey\Uuid\UuidInterface;
18
use Ramsey\Uuid\Console\Util\Formatter\V1Formatter;
19
use Ramsey\Uuid\Console\Util\Formatter\V2Formatter;
20
use Ramsey\Uuid\Console\Util\Formatter\V3Formatter;
21
use Ramsey\Uuid\Console\Util\Formatter\V4Formatter;
22
use Ramsey\Uuid\Console\Util\Formatter\V5Formatter;
23
use Symfony\Component\Console\Helper\Table;
24
25
class UuidFormatter
26
{
27
28
    private static $versionMap = [
29
        1 => '1 (time and node based)',
30
        2 => '2 (DCE security based)',
31
        3 => '3 (name based, MD5)',
32
        4 => '4 (random data based)',
33
        5 => '5 (name based, SHA-1)'
34
    ];
35
36
    private static $variantMap = [
37
        Uuid::RESERVED_NCS => 'Reserved',
38
        Uuid::RFC_4122 => 'RFC 4122',
39
        Uuid::RESERVED_MICROSOFT => 'Reserved for Microsoft use.',
40
        Uuid::RESERVED_FUTURE => 'Reserved for future use.'
41
    ];
42
43
    private static $formatters;
44
45
    public function __construct()
46
    {
47
        if (self::$formatters == null) {
48
            self::$formatters = [
49
                1 => new V1Formatter(),
50
                2 => new V2Formatter(),
51
                3 => new V3Formatter(),
52
                4 => new V4Formatter(),
53
                5 => new V5Formatter()
54
            ];
55
        }
56
    }
57
58
    public function write(Table $table, UuidInterface $uuid)
59
    {
60
        $table->addRows(array(
61
            array('encode:', 'STR:', (string) $uuid),
62
            array('',        'INT:', (string) $uuid->getInteger()),
63
        ));
64
65
        if ($uuid->getVariant() == Uuid::RFC_4122) {
66
            $table->addRows(array(
67
                array('decode:', 'variant:',$this->getFormattedVariant($uuid)),
68
                array('',        'version:', $this->getFormattedVersion($uuid)),
69
            ));
70
71
            $table->addRows($this->getContent($uuid));
72
        } else {
73
            $table->addRows(array(
74
                array('decode:', 'variant:', 'Not an RFC 4122 UUID'),
75
            ));
76
        }
77
    }
78
79
    public function getFormattedVersion(UuidInterface $uuid)
80
    {
81
        return self::$versionMap[$uuid->getVersion()];
82
    }
83
84
    public function getFormattedVariant(UuidInterface $uuid)
85
    {
86
        return self::$variantMap[$uuid->getVariant()];
87
    }
88
89
    /**
90
     * Returns content as an array of rows, each row being an array containing column values.
91
     */
92
    public function getContent(UuidInterface $uuid)
93
    {
94
        $formatter = self::$formatters[$uuid->getVersion()];
95
96
        return $formatter->getContent($uuid);
97
    }
98
}
99