AbstractGetService   A
last analyzed

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