RedirectManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 36
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A findAndUpdate() 0 15 2
1
<?php
2
3
namespace Zenstruck\RedirectBundle\Service;
4
5
use Doctrine\Persistence\ObjectManager;
6
use Zenstruck\RedirectBundle\Model\Redirect;
7
8
/**
9
 * @author Kevin Bond <[email protected]>
10
 */
11
class RedirectManager
12
{
13
    private $class;
14
15
    private $om;
16
17
    /**
18
     * @param string $class The Redirect class name
19
     */
20 5
    public function __construct($class, ObjectManager $om)
21
    {
22 5
        $this->class = $class;
23 5
        $this->om = $om;
24 5
    }
25
26
    /**
27
     * @param string $source
28
     *
29
     * @return Redirect|null
30
     */
31 5
    public function findAndUpdate($source)
32
    {
33
        /** @var Redirect|null $redirect */
34 5
        $redirect = $this->om->getRepository($this->class)->findOneBy(['source' => $source]);
35
36 5
        if (null === $redirect) {
37 2
            return null;
38
        }
39
40 3
        $redirect->increaseCount();
41 3
        $redirect->updateLastAccessed();
42 3
        $this->om->flush();
43
44 3
        return $redirect;
45
    }
46
}
47