BookingController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 9
nc 1
nop 4
1
<?php
2
3
namespace JhFlexiTime\Controller;
4
5
use JhFlexiTime\Repository\UserSettingsRepositoryInterface;
6
use JhFlexiTime\Service\BookingService;
7
use JhFlexiTime\Service\TimeCalculatorService;
8
use JhFlexiTime\Validator\UniqueBooking;
9
use Zend\Form\FormInterface;
10
use Zend\Mvc\Controller\AbstractActionController;
11
use Zend\View\Model\ViewModel;
12
use Zend\Validator\Date as DateValidator;
13
14
/**
15
 * Class BookingController
16
 * @package JhFlexiTime\Controller
17
 * @author Aydin Hassan <[email protected]>s
18
 */
19
class BookingController extends AbstractActionController
20
{
21
    use GetSetDateTrait;
22
23
    /**
24
     * @var \JhFlexiTime\Form\BookingForm
25
     */
26
    protected $bookingForm;
27
28
    /**
29
     * @var \JhFlexiTime\Service\BookingService
30
     */
31
    protected $bookingService;
32
33
    /**
34
     * @var \JhFlexiTime\Service\TimeCalculatorService
35
     */
36
    protected $timeCalculatorService;
37
38
    /**
39
     * @var UserSettingsRepositoryInterface
40
     */
41
    protected $userSettingsRepository;
42
43
    /**
44
     * @param BookingService $bookingService
45
     * @param TimeCalculatorService $timeCalculatorService
46
     * @param FormInterface $bookingForm
47
     */
48
    public function __construct(
49
        BookingService $bookingService,
50
        TimeCalculatorService $timeCalculatorService,
51
        FormInterface $bookingForm,
52
        UserSettingsRepositoryInterface $userSettingsRepository
53
    ) {
54
        $this->bookingService           = $bookingService;
55
        $this->bookingForm              = $bookingForm;
0 ignored issues
show
Documentation Bug introduced by
$bookingForm is of type object<Zend\Form\FormInterface>, but the property $bookingForm was declared to be of type object<JhFlexiTime\Form\BookingForm>. 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...
56
        $this->timeCalculatorService    = $timeCalculatorService;
57
        $this->userSettingsRepository   = $userSettingsRepository;
58
    }
59
60
    /**
61
     * @return ViewModel
62
     */
63
    public function listAction()
64
    {
65
66
        $month  = (string) $this->params()->fromQuery('m');
67
        $year   = (string) $this->params()->fromQuery('y');
68
        $period = $this->getDate($month, $year);
69
70
        $user           = $this->zfcUserAuthentication()->getIdentity();
0 ignored issues
show
Documentation Bug introduced by
The method zfcUserAuthentication does not exist on object<JhFlexiTime\Controller\BookingController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
71
        $userSettings   = $this->userSettingsRepository->findOneByUser($user);
72
        $records        = $this->bookingService->getUserBookingsForMonth($user, $period);
73
        $pagination     = $this->bookingService->getPagination($period);
74
        $totals         = $this->timeCalculatorService->getTotals($user, $userSettings->getFlexStartDate(), $period);
75
76
        return new ViewModel([
77
            'bookings' => [
78
                'records'       => $records,
79
                'totals'        => $totals,
80
                'user'          => $user,
81
            ],
82
            'pagination' => $pagination,
83
            'date'       => $period,
84
            'today'      => new \DateTime("today"),
85
            'form'       => $this->bookingForm,
86
        ]);
87
    }
88
}
89