Completed
Push — master ( 759a3c...0a5dc9 )
by Mohamed
04:06
created

CardView   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 92.86%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 31
ccs 13
cts 14
cp 0.9286
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A insertView() 0 20 3
1
<?php
2
3
/*
4
 * This file is part of the Moo\FlashCardBundle package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Moo\FlashCardBundle\Repository;
13
14
use Doctrine\ORM\EntityRepository;
15
use Moo\FlashCardBundle\Entity;
16
17
/**
18
 * CardView is a repository class for the card view entity.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 */
22
class CardView extends EntityRepository
23
{
24
    /**
25
     * Insert a view count
26
     *
27
     * @param Entity\Card $card
28
     * @param string      $ip
29
     *
30
     * @return bool|Entity\CardView
31
     */
32 1
    public function insertView(Entity\Card $card, $ip)
33
    {
34 1
        $view = false;
35 1
        if ($card->getId() == 0) {
36
            return $view;
37
        }
38
39 1
        $isExists = $this->findOneBy(['card' => $card, 'ip' => ip2long($ip)]);
40 1
        if (!$isExists) {
41 1
            $view = new Entity\CardView();
42 1
            $view->setCard($card);
43 1
            $view->setTimestamp(new \DateTime());
44 1
            $view->setIp($ip);
45 1
            $em = $this->getEntityManager();
46 1
            $em->persist($view);
47 1
            $em->flush();
48
        }
49
50 1
        return $view;
51
    }
52
}
53