Completed
Pull Request — master (#9)
by Davis
02:21
created

AbstractGetService   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 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 44
loc 44
ccs 10
cts 10
cp 1
rs 10
c 0
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/30/17
6
 * Time: 7:21 PM
7
 */
8
9
namespace DavisPeixoto\BlogCore\Service;
10
11
12
use DavisPeixoto\BlogCore\Interfaces\RepositoryInterface;
13
use DavisPeixoto\BlogCore\Interfaces\ServiceInterface;
14
use Exception;
15
use Psr\Log\LoggerInterface;
16
use stdClass;
17
18
/**
19
 * Class AbstractGetService
20
 * @package DavisPeixoto\BlogCore\Service
21
 */
22 View Code Duplication
abstract class AbstractGetService 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...
23
{
24
    /**
25
     * @var RepositoryInterface
26
     */
27
    protected $repository;
28
29
    /**
30
     * @var string
31
     */
32
    protected $uuid;
33
34
    /**
35
     * @var LoggerInterface
36
     */
37
    protected $logger;
38
39
    /**
40
     * AbstractGetService constructor.
41
     * @param RepositoryInterface $repository
42
     * @param string $uuid
43
     * @param LoggerInterface $logger
44
     */
45 12
    public function __construct(RepositoryInterface $repository, string $uuid, LoggerInterface $logger)
46
    {
47 12
        $this->repository = $repository;
48 12
        $this->uuid = $uuid;
49 12
        $this->logger = $logger;
50 12
    }
51
52
    /**
53
     * @return stdClass|null
54
     */
55 12
    public function run()
56
    {
57
        try {
58 12
            return $this->repository->get($this->uuid);
59 4
        } catch (Exception $e) {
60 4
            $this->logger->error($e->getMessage());
61
        }
62
63 4
        return null;
64
    }
65
}
66