Passed
Push — master ( f5fd25...253018 )
by Davis
35s
created

CreateTrail::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 6
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
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\AbstractTrailRepository;
14
use DavisPeixoto\BlogCore\Entity\Trail;
15
use Exception;
16
use Psr\Log\LoggerInterface;
17
use Ramsey\Uuid\UuidInterface;
18
19
/**
20
 * Class CreateTrail
21
 * @package DavisPeixoto\BlogCore\Service
22
 */
23 View Code Duplication
class CreateTrail implements ServiceInterface
24
{
25
    /**
26
     * @var AbstractTrailRepository
27
     */
28
    private $trailRepository;
29
30
    /**
31
     * @var Trail
32
     */
33
    private $trail;
34
35
    /**
36
     * @var LoggerInterface
37
     */
38
    private $logger;
39
40
    /**
41
     * CreateTrail constructor.
42
     * @param AbstractTrailRepository $trailRepository
43
     * @param Trail $trail
44
     * @param LoggerInterface $logger
45
     */
46 2
    public function __construct(AbstractTrailRepository $trailRepository, Trail $trail, LoggerInterface $logger)
47
    {
48 2
        $this->trailRepository = $trailRepository;
49 2
        $this->trail = $trail;
50 2
        $this->logger = $logger;
51 2
    }
52
53
    /**
54
     * @return UuidInterface|null
55
     */
56 2
    public function run()
57
    {
58
        try {
59 2
            return $this->trailRepository->save($this->trail);
60 1
        } catch (Exception $e) {
61 1
            $this->logger->error($e->getMessage());
62
        }
63
64 1
        return null;
65
    }
66
}
67