ConfigurationRepository::getOrCreate()   A
last analyzed

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 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 6
rs 10
c 0
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
/**
10
 * @extends AbstractRepository<Configuration>
11
 */
12
class ConfigurationRepository extends AbstractRepository
13
{
14
    /**
15
     * Get or create the configuration for the given key.
16
     */
17
    public function getOrCreate(string $key): Configuration
18
    {
19
        $configuration = $this->findOneByKey($key);
20
        if (!$configuration) {
21
            $configuration = new Configuration($key);
22
            $this->getEntityManager()->persist($configuration);
23
        }
24
25
        return $configuration;
26
    }
27
}
28