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

ListPosts::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
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\PostRepository;
14
use Psr\Log\LoggerInterface;
15
use Exception;
16
use stdClass;
17
18
/**
19
 * Class ListPosts
20
 * @package DavisPeixoto\BlogCore\Service
21
 */
22 View Code Duplication
class ListPosts 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 PostRepository
26
     */
27
    private $postRepository;
28
29
    /**
30
     * @var array
31
     */
32
    private $filters;
33
34
    /**
35
     * @var LoggerInterface
36
     */
37
    private $logger;
38
39
    /**
40
     * ListPosts constructor.
41
     * @param PostRepository $postRepository
42
     * @param array $filters
43
     * @param LoggerInterface $logger
44
     */
45
    public function __construct(PostRepository $postRepository, Array $filters, LoggerInterface $logger)
46
    {
47
        $this->postRepository = $postRepository;
48
        $this->filters = $filters;
49
        $this->logger = $logger;
50
    }
51
52
    /**
53
     * @return array|stdClass[]
54
     */
55
    public function run(): array
56
    {
57
        try {
58
            return $this->postRepository->getList($this->filters);
59
        } catch (Exception $e) {
60
            $this->logger->error($e->getMessage());
61
        }
62
63
        return [];
64
    }
65
}
66