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

DeletePost::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

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