Completed
Push — master ( 27c5e0...9ca3e9 )
by Philip
01:39
created

DoctrineUuidCrudService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
c 1
b 0
f 0
wmc 3
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 8 2
A isUuid() 0 4 1
1
<?php
2
3
namespace Dontdrinkandroot\Service;
4
5
class DoctrineUuidCrudService extends DoctrineCrudService
6
{
7
    private $uuidField = 'uuid';
8
9
    public function find($id, $lockMode = null, $lockVersion = null)
10
    {
11
        if ($this->isUuid($id)) {
12
            return $this->findOneBy([$this->uuidField => $id]);
13
        }
14
15
        return parent::find($id, $lockMode, $lockVersion);
16
    }
17
18
    protected function isUuid($id)
19
    {
20
        return 1 === preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $id);
21
    }
22
}
23