Completed
Pull Request — master (#95)
by
unknown
01:39
created

BlockResourceResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 41
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A findOrLog() 0 15 2
1
<?php
2
3
/**
4
 * This file was created by the developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Resolver;
14
15
use BitBag\SyliusCmsPlugin\Entity\BlockInterface;
16
use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface;
17
use Psr\Log\LoggerInterface;
18
19
/**
20
 * @author Mikołaj Król <[email protected]>
21
 */
22
final class BlockResourceResolver implements BlockResourceResolverInterface
23
{
24
    /**
25
     * @var BlockRepositoryInterface
26
     */
27
    private $blockRepository;
28
29
    /**
30
     * @var LoggerInterface
31
     */
32
    private $logger;
33
34
    /**
35
     * @param BlockRepositoryInterface $blockRepository
36
     * @param LoggerInterface $logger
37
     */
38
    public function __construct(BlockRepositoryInterface $blockRepository, LoggerInterface $logger)
39
    {
40
        $this->blockRepository = $blockRepository;
41
        $this->logger = $logger;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function findOrLog(string $code): ?BlockInterface
48
    {
49
        $block = $this->blockRepository->findOneEnabledByCode($code);
50
51
        if (false === $block instanceof BlockInterface) {
52
            $this->logger->warning(sprintf(
53
                'Block with "%s" code was not found in the database.',
54
                $code
55
            ));
56
57
            return null;
58
        }
59
60
        return $block;
61
    }
62
}
63