Completed
Pull Request — master (#106)
by Litera
08:36
created

RegistrationPresenter::getEventService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Presenters;
4
5
use DateTime;
6
use App\Entities\VisitorEntity;
7
use App\Models\MeetingModel;
8
use App\Models\VisitorModel;
9
use App\Models\ProgramModel;
10
use App\Models\MealModel;
11
use App\Services\SkautIS\UserService;
12
use App\Services\Emailer;
13
use App\Services\VisitorService;
14
use App\Services\ProgramService;
15
use Tracy\Debugger;
16
use App\Components\Forms\RegistrationForm;
17
use App\Components\Forms\Factories\IRegistrationFormFactory;
18
use App\Services\SkautIS\EventService;
19
use Skautis\Wsdl\WsdlException;
20
21
/**
22
 * Registration controller
23
 *
24
 * This file handles the registration of visitors
25
 *
26
 * @author Tomas Litera
27
 * @copyright 2013-06-12 <[email protected]>
28
 * @package srazvs
29
 */
30
class RegistrationPresenter extends VisitorPresenter
31
{
32
33
	/**
34
	 * @var VisitorModel
35
	 */
36
	private $visitorModel;
37
38
	/**
39
	 * @var ProgramModel
40
	 */
41
	private $programModel;
42
43
	/**
44
	 * @var UserService
45
	 */
46
	private $userService;
47
48
	/**
49
	 * @var ProgramService
50
	 */
51
	private $programService;
52
53
	/**
54
	 * @var boolean
55
	 */
56
	private $disabled = false;
57
58
	/**
59
	 * @var IRegistrationFormFactory
60
	 */
61
	private $registrationFormFactory;
62
63
	/**
64
	 * @var EventService
65
	 */
66
	protected $skautisEventService;
67
68
	/**
69
	 * @param MeetingModel   $meetingModel
70
	 * @param UserService    $userService
71
	 * @param VisitorModel   $visitorModel
72
	 * @param MealModel      $mealModel
73
	 * @param ProgramModel   $programModel
74
	 * @param VisitorService $visitorService
75
	 */
76
	public function __construct(
77
		MeetingModel $meetingModel,
78
		UserService $userService,
79
		VisitorModel $visitorModel,
80
		MealModel $mealModel,
81
		ProgramModel $programModel,
82
		Emailer $emailer,
83
		VisitorService $visitorService,
84
		ProgramService $programService,
85
		EventService $skautisEvent
86
	) {
87
		$this->setMeetingModel($meetingModel);
88
		$this->setUserService($userService);
89
		$this->setVisitorModel($visitorModel);
90
		$this->setMealModel($mealModel);
91
		$this->setProgramModel($programModel);
92
		$this->setEmailer($emailer);
93
		$this->setVisitorService($visitorService);
94
		$this->setProgramService($programService);
95
		$this->setEventService($skautisEvent);
96
	}
97
98
	/**
99
	 * @return IRegistrationFormFactory
100
	 */
101
	public function getRegistrationFormFactory(): IRegistrationFormFactory
102
	{
103
		return $this->registrationFormFactory;
104
	}
105
106
	/**
107
	 * Injector
108
	 *
109
	 * @param  IRegistrationFormFactory $factory
110
	 */
111
112
	protected $error = FALSE;
113
114
	protected $hash = NULL;
115
	private $item;
116
	private $mealData;
117
	private $user;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
118
	private $event;
119
120
	public function injectRegistrationFormFactory(IRegistrationFormFactory $factory)
121
	{
122
		$this->registrationFormFactory = $factory;
123
	}
124
125
	/**
126
	 * @return void
127
	 */
128
	public function startup()
129
	{
130
		parent::startup();
131
132
		$this->getMeetingModel()->setMeetingId($this->getMeetingId());
133
134
		if($this->getDebugMode()) {
135
			$this->getMeetingModel()->setRegistrationHandlers(1);
136
			$this->setMeetingId(1);
137
		} else {
138
			$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId());
139
		}
140
141
		//$this->user = $this->container->getService('userService');
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
142
		//$this->event = $this->container->getService('eventService');
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
143
144
		$template = $this->getTemplate();
145
146
		$template->page_title = "Registrace srazu VS";
0 ignored issues
show
Bug introduced by
Accessing page_title on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Coding Style Comprehensibility introduced by
The string literal Registrace srazu VS does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
147
		$template->meeting_heading = $this->getMeetingModel()->getRegHeading();
0 ignored issues
show
Bug introduced by
Accessing meeting_heading on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
148
		$template->isRegistrationOpen = $this->getMeetingModel()->isRegOpen($this->getDebugMode());
0 ignored issues
show
Bug introduced by
Accessing isRegistrationOpen on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
149
	}
150
151
	/**
152
	 * Process data from form
153
	 *
154
	 * @return void
155
	 */
156 View Code Duplication
	public function actionCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
157
	{
158
		try {
159
			$postData = $this->getHttpRequest()->getPost();
160
			$postData['meeting'] = $this->getMeetingId();
161
162
			$guid = $this->getVisitorService()->create($postData);
163
			$result = $this->sendRegistrationSummary($postData, $guid);
164
165
			Debugger::log('Creation of registration('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO);
166
			$this->flashMessage('Registrace(' . $guid . ') byla úspěšně založena.', self::FLASH_TYPE_OK);
167
		} catch(Exception $e) {
0 ignored issues
show
Bug introduced by
The class App\Presenters\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
168
			Debugger::log('Creation of registration('. $guid .') failed, result: ' .  $e->getMessage(), Debugger::ERROR);
0 ignored issues
show
Bug introduced by
The variable $guid does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
169
			$this->flashMessage('Creation of registration failed, result: ' . $e->getMessage(), self::FLASH_TYPE_ERROR);
170
		}
171
172
		$this->redirect('Registration:check', $guid);
173
	}
174
175
	/**
176
	 * @param  string  $guid
177
	 * @return void
178
	 */
179 View Code Duplication
	public function actionUpdate($guid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
180
	{
181
		try {
182
			$postData = $this->getHttpRequest()->getPost();
183
184
			$result = $this->getVisitorService()->update($guid, $postData);
185
			$result = $this->sendRegistrationSummary($postData, $guid);
186
187
			Debugger::log('Modification of registration('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO);
188
			$this->flashMessage('Registrace(' . $guid . ') byla úspěšně upravena.', self::FLASH_TYPE_OK);
189
		} catch(Exception $e) {
0 ignored issues
show
Bug introduced by
The class App\Presenters\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
190
			Debugger::log('Modification of registration('. $guid .') failed, result: ' .  $e->getMessage(), Debugger::ERROR);
191
			$this->flashMessage('Modification of registration(' . $guid . ') failed, result: ' . $e->getMessage(), self::FLASH_TYPE_ERROR);
192
		}
193
194
		$this->redirect('Registration:check', $guid);
195
	}
196
197
	/**
198
	 * @return void
199
	 */
200
	public function renderDefault()
201
	{
202
		$template = $this->getTemplate();
203
204
		////otevirani a uzavirani prihlasovani
205
		$disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal disabled does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
206
		$template->disabled = $disabled;
0 ignored issues
show
Bug introduced by
Accessing disabled on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
207
		$template->loggedIn = $this->getUserService()->isLoggedIn();
0 ignored issues
show
Bug introduced by
Accessing loggedIn on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
208
209
		if($this->getUserService()->isLoggedIn()) {
210
			$this['registrationForm']->setDefaults(($this->useLoggedVisitor())->toArray());
211
		}
212
	}
213
214
	/**
215
	 * @param  string  $guid
216
	 * @return void
217
	 */
218
	public function renderCheck($guid)
219
	{
220
		$visitor = $this->getVisitorModel()->findByGuid($guid);
221
222
		$this->getMeetingModel()->setRegistrationHandlers($visitor->meeting);
223
224
		$template = $this->getTemplate();
225
		$template->guid = $guid;
0 ignored issues
show
Bug introduced by
Accessing guid on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
226
		$template->visitor = $visitor;
0 ignored issues
show
Bug introduced by
Accessing visitor on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
227
		$template->meetingId = $visitor->meeting;
0 ignored issues
show
Bug introduced by
Accessing meetingId on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
228
		$template->meals = $this->getMealModel()->findByVisitorId($visitor->id);
0 ignored issues
show
Bug introduced by
Accessing meals on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
229
		$template->province = $this->getMeetingModel()->getProvinceNameById($visitor->province);
0 ignored issues
show
Bug introduced by
Accessing province on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
230
		$template->programs = $this->getProgramModel()->findByVisitorId($visitor->id);
0 ignored issues
show
Bug introduced by
Accessing programs on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
231
	}
232
233
	/**
234
	 * @param  string $guid
235
	 * @return void
236
	 */
237
	public function renderEdit($guid)
238
	{
239
		$visitor = $this->getVisitorService()->findByGuid($guid);
240
		$meetingId = $visitor['meeting'];
241
242
		$this->getMeetingModel()->setRegistrationHandlers($meetingId);
243
244
		$template = $this->getTemplate();
245
		$template->guid = $guid;
0 ignored issues
show
Bug introduced by
Accessing guid on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
246
		$template->meetingId = $meetingId;
0 ignored issues
show
Bug introduced by
Accessing meetingId on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
247
		$template->loggedIn = $this->getUserService()->isLoggedIn();
0 ignored issues
show
Bug introduced by
Accessing loggedIn on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
248
		$template->disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled";
0 ignored issues
show
Bug introduced by
Accessing disabled on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal disabled does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
249
250
		$this['registrationForm']->setDefaults($visitor);
251
	}
252
253
	/**
254
	 * @return RegistrationFormControl
255
	 */
256
	protected function createComponentRegistrationForm(): RegistrationForm
257
	{
258
		$control = $this->registrationFormFactory->create();
259
		$control->setMeetingId($this->getMeetingId());
260
		$control->onRegistrationSave[] = function(RegistrationForm $control, $newVisitor) {
261
			try {
262
				$guid = $this->getVisitorService()->create((array) $newVisitor);
263
264
				if($this->getUserService()->isLoggedIn() && $this->getMeetingModel()->findCourseId()) {
265
					$this->getEventService()->insertEnroll(
266
						$this->getUserService()->getSkautis()->getUser()->getLoginId(),
267
						$this->getMeetingModel()->findCourseId(),
268
						// TODO: get real phone number
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
269
						'123456789'
270
					);
271
				}
272
273
				$result = $this->sendRegistrationSummary((array) $newVisitor, $guid);
274
275
				Debugger::log('Storage of visitor('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO);
276
				$this->flashMessage('Účastník(' . $guid . ') byl úspěšně uložen.', self::FLASH_TYPE_OK);
277
			} catch(WsdlException $e) {
278
				Debugger::log('Storage of visitor('. $guid .') failed, result: ' . $e->getMessage(), Debugger::WARNING);
279
				$this->flashMessage('Uložení účastníka (' . $guid . ') selhalo. Účastník je již zaregistrován.', self::FLASH_TYPE_ERROR);
280
			} catch(Exception $e) {
0 ignored issues
show
Bug introduced by
The class App\Presenters\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
281
				Debugger::log('Storage of visitor('. $guid .') failed, result: ' .  $e->getMessage(), Debugger::ERROR);
282
				$this->flashMessage('Uložení účastníka selhalo, chyba: ' . $e->getMessage(), self::FLASH_TYPE_ERROR);
283
			}
284
285
			$this->redirect('Registration:check', $guid);
286
		};
287
288
		return $control;
289
	}
290
291
	/**
292
	 * @return VisitorEntity
293
	 */
294
	protected function useLoggedVisitor(): VisitorEntity
295
	{
296
		$userDetail = $this->getUserService()->getUserDetail();
297
		$skautisUser = $this->getUserService()->getPersonalDetail($userDetail->ID_Person);
298
		$membership = $this->getUserService()->getPersonUnitDetail($userDetail->ID_Person);
299
300
		if(!preg_match('/^[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}$/', $membership->RegistrationNumber)) {
301
			$skautisUserUnit = $this->getUserService()->getParentUnitDetail($membership->ID_Unit)[0];
302
		} else {
303
			$skautisUserUnit = $this->getUserService()->getUnitDetail($membership->ID_Unit);
304
		}
305
306
		$visitor = new VisitorEntity;
307
		$visitor->name = $skautisUser->FirstName;
308
		$visitor->surname = $skautisUser->LastName;
309
		$visitor->nick = $skautisUser->NickName;
310
		$visitor->email = $skautisUser->Email;
311
		$visitor->street = $skautisUser->Street;
312
		$visitor->city = $skautisUser->City;
313
		$visitor->postal_code = preg_replace('/\s+/', '', $skautisUser->Postcode);
314
		$visitor->birthday = (new DateTime($skautisUser->Birthday))->format('d. m. Y');
315
		$visitor->group_name = $skautisUserUnit->DisplayName;
316
		$visitor->group_num = $skautisUserUnit->RegistrationNumber;
317
		if(isset($membership->Unit)) {
318
			$visitor->troop_name = $membership->Unit;
319
		}
320
321
		return $visitor;
322
	}
323
324
	/**
325
	 * @return MealModel
326
	 */
327
	protected function getMealModel()
328
	{
329
		return $this->mealModel;
330
	}
331
332
	/**
333
	 * @param  MealModel $model
334
	 * @return $this
335
	 */
336
	protected function setMealModel(MealModel $model)
337
	{
338
		$this->mealModel = $model;
339
340
		return $this;
341
	}
342
343
	/**
344
	 * @return MeetingModel
345
	 */
346
	protected function getMeetingModel()
347
	{
348
		return $this->meetingModel;
349
	}
350
351
	/**
352
	 * @param  MeetingModel $model
353
	 * @return $this
354
	 */
355
	protected function setMeetingModel(MeetingModel $model)
356
	{
357
		$this->meetingModel = $model;
358
359
		return $this;
360
	}
361
362
	/**
363
	 * @return VisitorModel
364
	 */
365
	protected function getVisitorModel()
366
	{
367
		return $this->visitorModel;
368
	}
369
370
	/**
371
	 * @param  VisitorModel $model
372
	 * @return $this
373
	 */
374
	protected function setVisitorModel(VisitorModel $model)
375
	{
376
		$this->visitorModel = $model;
377
378
		return $this;
379
	}
380
381
	/**
382
	 * @return ProgramModel
383
	 */
384
	protected function getProgramModel()
385
	{
386
		return $this->programModel;
387
	}
388
389
	/**
390
	 * @param  ProgramModel $model
391
	 * @return $this
392
	 */
393
	protected function setProgramModel(ProgramModel $model)
394
	{
395
		$this->programModel = $model;
396
397
		return $this;
398
	}
399
400
	/**
401
	 * @return UserService
402
	 */
403
	protected function getUserService()
404
	{
405
		return $this->userService;
406
	}
407
408
	/**
409
	 * @param  UserService $service
410
	 * @return $this
411
	 */
412
	protected function setUserService(UserService $service)
413
	{
414
		$this->userService = $service;
415
416
		return $this;
417
	}
418
419
	/**
420
	 * @return ProgramService
421
	 */
422
	protected function getProgramService()
423
	{
424
		return $this->programService;
425
	}
426
427
	/**
428
	 * @param  ProgramService $service
429
	 * @return $this
430
	 */
431
	protected function setProgramService(ProgramService $service)
432
	{
433
		$this->programService = $service;
434
435
		return $this;
436
	}
437
438
	/**
439
	 * @return EventService
440
	 */
441
	protected function getEventService(): EventService
442
	{
443
		return $this->skautisEventService;
444
	}
445
446
	/**
447
	 * @param EventService $skautisEvent
0 ignored issues
show
Bug introduced by
There is no parameter named $skautisEvent. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
448
	 *
449
	 * @return self
450
	 */
451
	protected function setEventService(EventService $service): self
452
	{
453
		$this->skautisEventService = $service;
454
455
		return $this;
456
	}
457
458
}
459