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

DescriptionEventBlockService::configureSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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\Event;
8
use Stfalcon\Bundle\EventBundle\Entity\EventBlock;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
use Symfony\Component\OptionsResolver\OptionsResolver;
12
13
/**
14
 * Class DescriptionEventBlockService.
15
 */
16
class DescriptionEventBlockService extends AbstractBlockService
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function execute(BlockContextInterface $blockContext, Response $response = null)
22
    {
23
        $event = $blockContext->getSetting('event');
24
25
        if (!$event instanceof Event) {
26
            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...
27
        }
28
29
        $about = $event->getAbout();
30
        if (!$about) {
31
            $eventBlock = $blockContext->getSetting('event_block');
32
33
            if ($eventBlock instanceof EventBlock) {
34
                $about = $eventBlock->getText();
35
            }
36
        }
37
38
        return $this->renderResponse($blockContext->getTemplate(), [
39
            'block' => $blockContext->getBlock(),
40
            'settings' => $blockContext->getSettings(),
41
            'event' => $event,
42
            'about' => $about,
43
        ], $response);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function configureSettings(OptionsResolver $resolver)
50
    {
51
        $resolver->setDefaults([
52
            'template' => 'ApplicationDefaultBundle:Redesign/Event:event.description.html.twig',
53
            'event' => null,
54
            'event_block' => null,
55
        ]);
56
    }
57
}
58