Passed
Push — master ( 1d7877...f5fd25 )
by Davis
37s
created

GetPost   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A run() 10 10 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:12 AM
7
 */
8
9
namespace DavisPeixoto\BlogCore\Service;
10
11
12
use DavisPeixoto\BlogCore\Interfaces\ServiceInterface;
13
use DavisPeixoto\BlogCore\Repository\AbstractPostRepository;
14
use Psr\Log\LoggerInterface;
15
use Exception;
16
use Ramsey\Uuid\UuidInterface;
17
use stdClass;
18
19
/**
20
 * Class GetPost
21
 * @package DavisPeixoto\BlogCore\Service
22
 */
23 View Code Duplication
class GetPost implements ServiceInterface
24
{
25
    /**
26
     * @var AbstractPostRepository
27
     */
28
    private $postRepository;
29
30
    /**
31
     * @var UuidInterface
32
     */
33
    private $uuid;
34
35
    /**
36
     * @var LoggerInterface
37
     */
38
    private $logger;
39
40
    /**
41
     * GetPost constructor.
42
     * @param AbstractPostRepository $postRepository
43
     * @param UuidInterface $uuid
44
     * @param LoggerInterface $logger
45
     */
46 3
    public function __construct(AbstractPostRepository $postRepository, UuidInterface $uuid, LoggerInterface $logger)
47
    {
48 3
        $this->postRepository = $postRepository;
49 3
        $this->uuid = $uuid;
50 3
        $this->logger = $logger;
51 3
    }
52
53
    /**
54
     * @return stdClass|false
55
     */
56 3
    public function run()
57
    {
58
        try {
59 3
            return $this->postRepository->get($this->uuid);
60 1
        } catch (Exception $e) {
61 1
            $this->logger->error($e->getMessage());
62
        }
63
64 1
        return false;
65
    }
66
}
67