Passed
Push — master ( a8b983...5b3176 )
by Adrien
10:48
created

ConfigurationRepository::getOrCreate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Repository;
6
7
use Application\Model\Configuration;
8
9
class ConfigurationRepository extends AbstractRepository
10
{
11
    /**
12
     * Get or create the configuration for the given key
13
     */
14
    public function getOrCreate(string $key): Configuration
15
    {
16
        $configuration = $this->findOneByKey($key);
17
        if (!$configuration) {
18
            $configuration = new Configuration($key);
19
            $this->getEntityManager()->persist($configuration);
20
        }
21
22
        return $configuration;
23
    }
24
}
25