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

ProgramEventBlockService::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 Application\Bundle\DefaultBundle\Service\EventService;
6
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
7
use Sonata\BlockBundle\Block\BlockContextInterface;
8
use Stfalcon\Bundle\EventBundle\Entity\Event;
9
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
use Symfony\Component\OptionsResolver\OptionsResolver;
13
14
/**
15
 * Class ProgramEventBlockService.
16
 */
17
class ProgramEventBlockService extends AbstractBlockService
18
{
19
    /** @var EventService */
20
    private $eventService;
21
22
    /**
23
     * ProgramEventBlockService constructor.
24
     *
25
     * @param string          $name
26
     * @param EngineInterface $templating
27
     * @param EventService    $eventService
28
     */
29
    public function __construct($name, EngineInterface $templating, EventService $eventService)
30
    {
31
        parent::__construct($name, $templating);
32
33
        $this->eventService = $eventService;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function execute(BlockContextInterface $blockContext, Response $response = null)
40
    {
41
        $event = $blockContext->getSetting('event');
42
43
        if (!$event instanceof Event) {
44
            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...
45
        }
46
47
        $pages = $this->eventService->getEventPages($event);
48
        $programPage = isset($pages['programPage']) ? $pages['programPage'] : null;
49
50
        return $this->renderResponse($blockContext->getTemplate(), [
51
            'block' => $blockContext->getBlock(),
52
            'program_page' => $programPage,
53
        ], $response);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function configureSettings(OptionsResolver $resolver)
60
    {
61
        $resolver->setDefaults([
62
            'template' => 'ApplicationDefaultBundle:Redesign/Event:event.program.html.twig',
63
            'event' => null,
64
            'event_block' => null,
65
        ]);
66
    }
67
}
68