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

DoctrineUuidCrudService::isUuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 1
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 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