AbstractBinaryUuidType   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 31.43 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 11
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToPHPValue() 11 11 2
A convertToDatabaseValue() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Explicit Architecture POC,
7
 * which is created on top of the Symfony Demo application.
8
 *
9
 * (c) Herberto Graça <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Acme\App\Infrastructure\Persistence\Doctrine\Type;
16
17
use Acme\PhpExtension\Identity\AbstractUuidId;
18
use Doctrine\DBAL\Platforms\AbstractPlatform;
19
use Ramsey\Uuid\Doctrine\UuidBinaryType;
20
use Ramsey\Uuid\Uuid as RamseyUuid;
21
22
/**
23
 * This type mapper stores the UUIDs in binary format, in the DB.
24
 * This makes it faster to query on the IDs and they take less space (they only take 16 characters as opposed to the
25
 * UUID 36 characters string).
26
 * However, if you look at the UUID stored in the DB, you won't be able to see the actual UUID, only its byte string.
27
 */
28
abstract class AbstractBinaryUuidType extends UuidBinaryType
29
{
30
    use TypeTrait;
31
32
    /**
33
     * @throws \Doctrine\DBAL\Types\ConversionException
34
     *
35
     * @return AbstractUuidId|null
36
     */
37 View Code Duplication
    public function convertToPHPValue($value, AbstractPlatform $platform)
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...
38
    {
39
        /** @var RamseyUuid $ramseyUuid */
40
        $ramseyUuid = parent::convertToPHPValue($value, $platform);
41
42
        if ($ramseyUuid === null) {
43
            return null;
44
        }
45
46
        return $this->createSpecificObject((string) $ramseyUuid);
47
    }
48
49
    /**
50
     * @param AbstractUuidId $value
51
     *
52
     * @throws \Doctrine\DBAL\Types\ConversionException
53
     *
54
     * @return string
55
     */
56
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
57
    {
58
        $uuidString = (string) $value;
59
60
        return parent::convertToDatabaseValue($uuidString, $platform);
61
    }
62
}
63