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

DoctrineUuidCrudService::find()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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