Completed
Pull Request — devel (#146)
by Litera
24:35 queued 19:02
created

RegistrationPresenter::setUserService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Presenters;
4
5
use DateTime;
6
use Exception;
7
use App\Entities\VisitorEntity;
8
use App\Models\MeetingModel;
9
use App\Models\MealModel;
10
use App\Services\SkautIS\UserService;
11
use App\Services\Emailer;
12
use App\Repositories\VisitorRepository;
13
use App\Repositories\ProgramRepository;
14
use App\Components\Forms\RegistrationForm;
15
use App\Components\Forms\Factories\IRegistrationFormFactory;
16
use App\Services\SkautIS\EventService;
17
use Nette\Utils\ArrayHash;
18
use App\Models\SettingsModel;
19
use Skautis\Wsdl\AuthenticationException;
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 UserService
35
	 */
36
	private $userService;
37
38
	/**
39
	 * @var SettingsModel
40
	 */
41
	protected $settingsModel;
42
43
	/**
44
	 * @var boolean
45
	 */
46
	private $disabled = false;
47
48
	/**
49
	 * @var IRegistrationFormFactory
50
	 */
51
	private $registrationFormFactory;
52
53
	/**
54
	 * @var EventService
55
	 */
56
	protected $skautisEventService;
57
58
	/**
59
	 * @var MealModel
60
	 */
61
	private $mealModel;
62
63
	/**
64
	 * @var ProgramRepository
65
	 */
66
	private $programRepository;
67
68
	protected $error = FALSE;
69
	protected $hash = NULL;
70
	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...
71
72
	/**
73
	 * @param MeetingModel       $meetingModel
74
	 * @param UserService        $userService
75
	 * @param MealModel          $mealModel
76
	 * @param ProgramRepository  $programRepository
77
	 * @param VisitorRepository  $visitorRepository
78
	 * @param SettingsModel      $settingsModel
79
	 */
80
	public function __construct(
81
		MeetingModel $meetingModel,
82
		UserService $userService,
83
		MealModel $mealModel,
84
		Emailer $emailer,
85
		VisitorRepository $visitorRepository,
86
		ProgramRepository $programRepository,
87
		EventService $skautisEvent,
88
		SettingsModel $settingsModel
89
	) {
90
		$this->setMeetingModel($meetingModel);
91
		$this->setUserService($userService);
92
		$this->setMealModel($mealModel);
93
		$this->setEmailer($emailer);
94
		$this->setVisitorRepository($visitorRepository);
95
		$this->setProgramRepository($programRepository);
96
		$this->setEventService($skautisEvent);
97
		$this->setSettingsModel($settingsModel);
98
	}
99
100
	/**
101
	 * @return IRegistrationFormFactory
102
	 */
103
	public function getRegistrationFormFactory(): IRegistrationFormFactory
104
	{
105
		return $this->registrationFormFactory;
106
	}
107
108
	/**
109
	 * Injector
110
	 *
111
	 * @param  IRegistrationFormFactory $factory
112
	 */
113
	public function injectRegistrationFormFactory(IRegistrationFormFactory $factory)
114
	{
115
		$this->registrationFormFactory = $factory;
116
	}
117
118
	/**
119
	 * @return void
120
	 */
121
	public function startup()
122
	{
123
		parent::startup();
124
125
		$this->getMeetingModel()->setMeetingId($this->getMeetingId());
126
127
		if($this->getDebugMode() || $this->getSettingsModel()->findDebugRegime()) {
128
			$this->getMeetingModel()->setRegistrationHandlers(1);
129
			$this->setMeetingId(1);
130
		} else {
131
			$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId());
132
		}
133
134
		//$this->user = $this->container->getService('userService');
135
		//$this->event = $this->container->getService('eventService');
136
137
		$template = $this->getTemplate();
138
139
		$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...
140
		$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...
141
		$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...
142
	}
143
144
	/**
145
	 * Process data from form
146
	 *
147
	 * @return void
148
	 */
149
	public function actionCreate($visitor)
150
	{
151
		try {
152
			$guid = $this->getVisitorRepository()->create($visitor);
153
			$result = $this->sendRegistrationSummary($visitor, $guid);
154
155
			$this->logInfo('Creation of registration(%s) successfull, result: %s', [
156
				$guid,
157
				json_encode($result),
158
			]);
159
			$this->flashSuccess("Registrace({$guid}) byla úspěšně založena.");
160
		} catch(Exception $e) {
161
			$this->logError('Creation of registration failed, result: %s', [
162
				$e->getMessage(),
163
			]);
164
			$this->flashError('Uložení účastníka selhalo, chyba: ' . $e->getMessage());
165
		}
166
167
		return $guid;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $guid; (string) is incompatible with the return type of the parent method App\Presenters\VisitorPresenter::actionCreate of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
168
	}
169
170
	/**
171
	 * @param  string  $guid
172
	 * @return void
173
	 */
174
	public function actionUpdate($guid, $visitor)
175
	{
176
		try {
177
			$result = $this->getVisitorRepository()->updateByGuid($guid, $visitor);
178
			$result = $this->sendRegistrationSummary($visitor, $guid);
179
180
			$this->logInfo('Modification of registration(%s) successfull, result: %s', [
181
				$guid,
182
				json_encode($result),
183
			]);
184
			$this->flashSuccess("Registrace({$guid}) byla úspěšně upravena.");
185
		} catch(Exception $e) {
186
			$this->logError('Modification of registration(%s) failed, result: %s', [
187
				$guid,
188
				$e->getMessage(),
189
			]);
190
			$this->flashError('Uložení účastníka selhalo, chyba: ' . $e->getMessage());
191
			$result = false;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
192
		}
193
194
		return $guid;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $guid; (string) is incompatible with the return type of the parent method App\Presenters\VisitorPresenter::actionUpdate of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
195
	}
196
197
	public function beforeRender()
198
	{
199
		parent::beforeRender();
200
	}
201
202
	/**
203
	 * Renders default template
204
	 */
205
	public function renderDefault()
206
	{
207
		$template = $this->getTemplate();
208
		$disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled";
209
		$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...
210
		$template->user = $this->getUser();
0 ignored issues
show
Bug introduced by
Accessing user 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...
211
		$template->backlink = $this->getHttpRequest()->getUrl()->getAbsoluteUrl();
0 ignored issues
show
Bug introduced by
Accessing backlink 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...
212
213
		try {
214
			if ($this->getUser()->isLoggedIn()) {
215
				$this['registrationForm']->setDefaults(($this->useLoggedVisitor())->toArray());
216
			}
217
		} catch (AuthenticationException $e) {
218
			$this->flashFailure('Uživatel byl odhlášen! Přihlaste se prosím znovu.');
219
			$this->getUser()->logout();
220
		}
221
	}
222
223
	/**
224
	 * Renders new template
225
	 */
226
	public function renderNew()
227
	{
228
		$template = $this->getTemplate();
229
		$disabled = $this->getMeetingModel()->isRegOpen($this->getDebugMode()) ? "" : "disabled";
230
		$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...
231
		$template->loggedIn = false;
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...
232
	}
233
234
	/**
235
	 * @param  string  $guid
236
	 * @return void
237
	 */
238
	public function renderCheck($guid)
239
	{
240
		$visitor = $this->getVisitorRepository()->findByGuid($guid);
241
242
		$this->getMeetingModel()->setRegistrationHandlers($visitor->meeting);
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->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...
247
		$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...
248
		$template->meals = ArrayHash::from($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...
249
		$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...
250
		$template->programs = $this->getProgramRepository()->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...
251
	}
252
253
	/**
254
	 * @param  string $guid
255
	 * @return void
256
	 */
257
	public function renderEdit($guid)
258
	{
259
		$visitor = $this->getVisitorRepository()->findExpandedByGuid($guid);
260
		$meetingId = $visitor['meeting'];
261
262
		$this->getMeetingModel()->setRegistrationHandlers($meetingId);
263
264
		$template = $this->getTemplate();
265
		$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...
266
		$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...
267
		$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...
268
		$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...
269
270
		$this['registrationForm']->setDefaults($visitor);
271
	}
272
273
	/**
274
	 * @return RegistrationFormControl
275
	 */
276
	protected function createComponentRegistrationForm(): RegistrationForm
277
	{
278
		$control = $this->registrationFormFactory->create();
279
		$control->setMeetingId($this->getMeetingId());
280
		$control->onRegistrationSave[] = function(RegistrationForm $control, $visitor) {
281
			$guid = $this->getParameter('guid');
282
283
			if($guid) {
284
				$guid = $this->actionUpdate($guid, $visitor);
285
			} else {
286
				$guid = $this->actionCreate($visitor);
287
			}
288
/*
289
				if($this->getUserService()->isLoggedIn() && $this->getMeetingModel()->findCourseId()) {
290
					$this->getEventService()->insertEnroll(
291
						$this->getUserService()->getSkautis()->getUser()->getLoginId(),
292
						$this->getMeetingModel()->findCourseId(),
293
						// TODO: get real phone number
294
						'123456789'
295
					);
296
				}
297
*/
298
			$this->redirect('Registration:check', $guid);
299
		};
300
301
		return $control;
302
	}
303
304
	/**
305
	 * @return VisitorEntity
306
	 */
307
	protected function useLoggedVisitor(): VisitorEntity
308
	{
309
		$userDetail = $this->getUserService()->getUserDetail();
310
		$skautisUser = $this->getUserService()->getPersonalDetail($userDetail->ID_Person);
311
		$membership = $this->getUserService()->getPersonUnitDetail($userDetail->ID_Person);
312
313
		if(!preg_match('/^[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}$/', $membership->RegistrationNumber)) {
314
			$skautisUserUnit = $this->getUserService()->getParentUnitDetail($membership->ID_Unit)[0];
315
		} else {
316
			$skautisUserUnit = $this->getUserService()->getUnitDetail($membership->ID_Unit);
317
		}
318
319
		$visitor = new VisitorEntity;
320
		$visitor->name = $skautisUser->FirstName;
321
		$visitor->surname = $skautisUser->LastName;
322
		$visitor->nick = $skautisUser->NickName;
323
		$visitor->email = $skautisUser->Email;
324
		$visitor->street = $skautisUser->Street;
325
		$visitor->city = $skautisUser->City;
326
		$visitor->postal_code = preg_replace('/\s+/', '', $skautisUser->Postcode);
327
		$visitor->birthday = (new DateTime($skautisUser->Birthday))->format('d. m. Y');
328
		$visitor->group_name = $skautisUserUnit->DisplayName;
329
		$visitor->group_num = $skautisUserUnit->RegistrationNumber;
330
		if(isset($membership->Unit)) {
331
			$visitor->troop_name = $membership->Unit;
332
		}
333
334
		return $visitor;
335
	}
336
337
	/**
338
	 * @return MealModel
339
	 */
340
	protected function getMealModel()
341
	{
342
		return $this->mealModel;
343
	}
344
345
	/**
346
	 * @param  MealModel $model
347
	 * @return $this
348
	 */
349
	protected function setMealModel(MealModel $model)
350
	{
351
		$this->mealModel = $model;
352
353
		return $this;
354
	}
355
356
	/**
357
	 * @return MeetingModel
358
	 */
359
	protected function getMeetingModel()
360
	{
361
		return $this->meetingModel;
362
	}
363
364
	/**
365
	 * @param  MeetingModel $model
366
	 * @return $this
367
	 */
368
	protected function setMeetingModel(MeetingModel $model)
369
	{
370
		$this->meetingModel = $model;
371
372
		return $this;
373
	}
374
375
	/**
376
	 * @return UserService
377
	 */
378
	protected function getUserService()
379
	{
380
		return $this->userService;
381
	}
382
383
	/**
384
	 * @param  UserService $service
385
	 * @return $this
386
	 */
387
	protected function setUserService(UserService $service)
388
	{
389
		$this->userService = $service;
390
391
		return $this;
392
	}
393
394
	/**
395
	 * @return EventService
396
	 */
397
	protected function getEventService(): EventService
398
	{
399
		return $this->skautisEventService;
400
	}
401
402
	/**
403
	 * @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...
404
	 *
405
	 * @return self
406
	 */
407
	protected function setEventService(EventService $service): self
408
	{
409
		$this->skautisEventService = $service;
410
411
		return $this;
412
	}
413
414
415
	/**
416
	 * @return SettingsModel
417
	 */
418
	protected function getSettingsModel(): SettingsModel
419
	{
420
		return $this->settingsModel;
421
	}
422
423
	/**
424
	 * @param SettingsModel $model
425
	 *
426
	 * @return self
427
	 */
428
	protected function setSettingsModel(SettingsModel $model): self
429
	{
430
		$this->settingsModel = $model;
431
432
		return $this;
433
	}
434
435
	/**
436
	 * @return ProgramRepository
437
	 */
438
	protected function getProgramRepository(): ProgramRepository
439
	{
440
		return $this->programRepository;
441
	}
442
443
	/**
444
	 * @param  ProgramRepository $repository
445
	 * @return RegistrationPresenter
446
	 */
447
	protected function setProgramRepository(ProgramRepository $repository): self
448
	{
449
		$this->programRepository = $repository;
450
451
		return $this;
452
	}
453
454
}
455