Completed
Push — master ( 227e03...1b465c )
by Artem
10:47 queued 05:43
created

TextEventBlockService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 12
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 12 2
A configureSettings() 0 6 1
1
<?php
2
3
namespace Application\Bundle\DefaultBundle\Service\EventBlock;
4
5
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
6
use Sonata\BlockBundle\Block\BlockContextInterface;
7
use Stfalcon\Bundle\EventBundle\Entity\EventBlock;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
use Symfony\Component\OptionsResolver\OptionsResolver;
11
12
/**
13
 * Class TextEventBlockService.
14
 */
15
class TextEventBlockService extends AbstractBlockService
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function execute(BlockContextInterface $blockContext, Response $response = null)
21
    {
22
        $eventBlock = $blockContext->getSetting('event_block');
23
24
        if (!$eventBlock instanceof EventBlock) {
25
            return new NotFoundHttpException();
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Symfony\Compo...NotFoundHttpException() returns the type Symfony\Component\HttpKe...n\NotFoundHttpException which is incompatible with the return type mandated by Sonata\BlockBundle\Block...iceInterface::execute() of Symfony\Component\HttpFoundation\Response.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
26
        }
27
28
        return $this->renderResponse($blockContext->getTemplate(), [
29
            'block' => $blockContext->getBlock(),
30
            'event_block' => $eventBlock,
31
        ], $response);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function configureSettings(OptionsResolver $resolver)
38
    {
39
        $resolver->setDefaults([
40
            'template' => 'ApplicationDefaultBundle:Redesign/Event:event.text_block.html.twig',
41
            'event' => null,
42
            'event_block' => null,
43
        ]);
44
    }
45
}
46