Completed
Push — master ( 7905cb...b738e4 )
by Davis
01:31
created

CreateTag   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 42
loc 42
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A run() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: davis
5
 * Date: 7/23/17
6
 * Time: 3:06 AM
7
 */
8
9
namespace DavisPeixoto\BlogCore\Service;
10
11
12
use DavisPeixoto\BlogCore\Entity\Tag;
13
use DavisPeixoto\BlogCore\Interfaces\ServiceInterface;
14
use DavisPeixoto\BlogCore\Repository\TagRepository;
15
use Exception;
16
use Psr\Log\LoggerInterface;
17
use Ramsey\Uuid\UuidInterface;
18
19
/**
20
 * Class CreateTag
21
 * @package DavisPeixoto\BlogCore\Service
22
 */
23 View Code Duplication
class CreateTag implements ServiceInterface
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    /**
26
     * @var TagRepository
27
     */
28
    private $tagRepository;
29
30
    /**
31
     * @var Tag
32
     */
33
    private $tag;
34
35
    /**
36
     * @var LoggerInterface
37
     */
38
    private $logger;
39
40
    /**
41
     * CreateTag constructor.
42
     * @param TagRepository $tagRepository
43
     * @param Tag $tag
44
     * @param LoggerInterface $logger
45
     */
46
    public function __construct(TagRepository $tagRepository, Tag $tag, LoggerInterface $logger)
47
    {
48
        $this->tagRepository = $tagRepository;
49
        $this->tag = $tag;
50
        $this->logger = $logger;
51
    }
52
53
    /**
54
     * @return UuidInterface|null
55
     */
56
    public function run()
57
    {
58
        try {
59
            return $this->tagRepository->save($this->tag);
60
        } catch (Exception $e) {
61
            $this->logger->error($e->getMessage());
62
        }
63
64
        return null;
65
    }
66
}
67