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

PricesEventBlockService::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\Repository\TicketCostRepository;
6
use Doctrine\Common\Persistence\ObjectRepository;
7
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
8
use Sonata\BlockBundle\Block\BlockContextInterface;
9
use Stfalcon\Bundle\EventBundle\Entity\Event;
10
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
15
/**
16
 * PricesEventBlockService.
17
 */
18
class PricesEventBlockService extends AbstractBlockService
19
{
20
    /** @var TicketCostRepository */
21
    private $ticketCostRepository;
22
23
    /**
24
     * PricesEventBlockService constructor.
25
     *
26
     * @param string           $name
27
     * @param EngineInterface  $templating
28
     * @param ObjectRepository $ticketCostRepository
29
     */
30
    public function __construct($name, EngineInterface $templating, ObjectRepository $ticketCostRepository)
31
    {
32
        parent::__construct($name, $templating);
33
34
        $this->ticketCostRepository = $ticketCostRepository;
0 ignored issues
show
Documentation Bug introduced by
$ticketCostRepository is of type Doctrine\Common\Persistence\ObjectRepository, but the property $ticketCostRepository was declared to be of type Application\Bundle\Defau...ry\TicketCostRepository. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function execute(BlockContextInterface $blockContext, Response $response = null)
41
    {
42
        $event = $blockContext->getSetting('event');
43
44
        if (!$event instanceof Event) {
45
            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...
46
        }
47
48
        $eventCurrentCost = $this->ticketCostRepository->getEventCurrentCost($event);
49
        $ticketCosts = $this->ticketCostRepository->getEventTicketsCost($event);
50
51
        return $this->renderResponse($blockContext->getTemplate(), [
52
            'block' => $blockContext->getBlock(),
53
            'ticketCosts' => $ticketCosts,
54
            'currentPrice' => $eventCurrentCost,
55
            'event' => $event,
56
        ], $response);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function configureSettings(OptionsResolver $resolver)
63
    {
64
        $resolver->setDefaults([
65
            'template' => 'ApplicationDefaultBundle:Redesign/Event:event_price.html.twig',
66
            'event' => null,
67
            'event_block' => null,
68
        ]);
69
    }
70
}
71