Completed
Pull Request — master (#102)
by Litera
11:03
created

RegistrationPresenter::actionCreate()   A

Complexity

Conditions 2
Paths 7

Size

Total Lines 18
Code Lines 12

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 7
nop 0
dl 18
loc 18
rs 9.4285
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\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
19
/**
20
 * Registration controller
21
 *
22
 * This file handles the registration of visitors
23
 *
24
 * @author Tomas Litera
25
 * @copyright 2013-06-12 <[email protected]>
26
 * @package srazvs
27
 */
28
class RegistrationPresenter extends VisitorPresenter
29
{
30
31
	/**
32
	 * @var VisitorModel
33
	 */
34
	private $visitorModel;
35
36
	/**
37
	 * @var ProgramModel
38
	 */
39
	private $programModel;
40
41
	/**
42
	 * @var UserService
43
	 */
44
	private $userService;
45
46
	/**
47
	 * @var ProgramService
48
	 */
49
	private $programService;
50
51
	/**
52
	 * @var boolean
53
	 */
54
	private $disabled = false;
55
56
	/**
57
	 * @var IRegistrationFormFactory
58
	 */
59
	private $registrationFormFactory;
60
61
	/**
62
	 * @param MeetingModel   $meetingModel
63
	 * @param UserService    $userService
64
	 * @param VisitorModel   $visitorModel
65
	 * @param MealModel      $mealModel
66
	 * @param ProgramModel   $programModel
67
	 * @param VisitorService $visitorService
68
	 */
69
	public function __construct(
70
		MeetingModel $meetingModel,
71
		UserService $userService,
72
		VisitorModel $visitorModel,
73
		MealModel $mealModel,
74
		ProgramModel $programModel,
75
		Emailer $emailer,
76
		VisitorService $visitorService,
77
		ProgramService $programService
78
	) {
79
		$this->setMeetingModel($meetingModel);
80
		$this->setUserService($userService);
81
		$this->setVisitorModel($visitorModel);
82
		$this->setMealModel($mealModel);
83
		$this->setProgramModel($programModel);
84
		$this->setEmailer($emailer);
85
		$this->setVisitorService($visitorService);
86
		$this->setProgramService($programService);
87
	}
88
89
	/**
90
	 * @return IRegistrationFormFactory
91
	 */
92
	public function getRegistrationFormFactory(): IRegistrationFormFactory
93
	{
94
		return $this->registrationFormFactory;
95
	}
96
97
	/**
98
	 * Injector
99
	 *
100
	 * @param  IRegistrationFormFactory $factory
101
	 */
102
	public function injectRegistrationFormFactory(IRegistrationFormFactory $factory)
103
	{
104
		$this->registrationFormFactory = $factory;
105
	}
106
107
	/**
108
	 * @return void
109
	 */
110
	public function startup()
111
	{
112
		parent::startup();
113
114
		$this->getMeetingModel()->setMeetingId($this->getMeetingId());
115
116
		if($this->getDebugMode()) {
117
			$this->getMeetingModel()->setRegistrationHandlers(1);
118
			$this->setMeetingId(1);
119
		} else {
120
			$this->getMeetingModel()->setRegistrationHandlers($this->getMeetingId());
121
		}
122
123
		$template = $this->getTemplate();
124
125
		$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...
126
		$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...
127
		$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...
128
	}
129
130
	/**
131
	 * Process data from form
132
	 *
133
	 * @return void
134
	 */
135 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...
136
	{
137
		try {
138
			$postData = $this->getHttpRequest()->getPost();
139
			$postData['meeting'] = $this->getMeetingId();
140
141
			$guid = $this->getVisitorService()->create($postData);
142
			$result = $this->sendRegistrationSummary($postData, $guid);
143
144
			Debugger::log('Creation of registration('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO);
145
			$this->flashMessage('Registrace(' . $guid . ') byla úspěšně založena.', self::FLASH_TYPE_OK);
146
		} 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...
147
			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...
148
			$this->flashMessage('Creation of registration failed, result: ' . $e->getMessage(), self::FLASH_TYPE_ERROR);
149
		}
150
151
		$this->redirect('Registration:check', $guid);
152
	}
153
154
	/**
155
	 * @param  string  $guid
156
	 * @return void
157
	 */
158 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...
159
	{
160
		try {
161
			$postData = $this->getHttpRequest()->getPost();
162
163
			$result = $this->getVisitorService()->update($guid, $postData);
164
			$result = $this->sendRegistrationSummary($postData, $guid);
165
166
			Debugger::log('Modification of registration('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO);
167
			$this->flashMessage('Registrace(' . $guid . ') byla úspěšně upravena.', self::FLASH_TYPE_OK);
168
		} 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...
169
			Debugger::log('Modification of registration('. $guid .') failed, result: ' .  $e->getMessage(), Debugger::ERROR);
170
			$this->flashMessage('Modification of registration(' . $guid . ') failed, result: ' . $e->getMessage(), self::FLASH_TYPE_ERROR);
171
		}
172
173
		$this->redirect('Registration:check', $guid);
174
	}
175
176
	/**
177
	 * @return void
178
	 */
179
	public function renderDefault()
180
	{
181
		$template = $this->getTemplate();
182
183
		////otevirani a uzavirani prihlasovani
184
		$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...
185
		$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...
186
		$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...
187
188
		if($this->getUserService()->isLoggedIn()) {
189
			$this['registrationForm']->setDefaults(($this->useLoggedVisitor())->toArray());
190
		}
191
	}
192
193
	/**
194
	 * @param  string  $guid
195
	 * @return void
196
	 */
197
	public function renderCheck($guid)
198
	{
199
		$visitor = $this->getVisitorModel()->findByGuid($guid);
200
201
		$this->getMeetingModel()->setRegistrationHandlers($visitor->meeting);
202
203
		$template = $this->getTemplate();
204
		$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...
205
		$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...
206
		$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...
207
		$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...
208
		$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...
209
		$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...
210
	}
211
212
	/**
213
	 * @param  string $guid
214
	 * @return void
215
	 */
216
	public function renderEdit($guid)
217
	{
218
		$visitor = $this->getVisitorService()->findByGuid($guid);
219
		$meetingId = $visitor['meeting'];
220
221
		$this->getMeetingModel()->setRegistrationHandlers($meetingId);
222
223
		$template = $this->getTemplate();
224
		$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...
225
		$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...
226
		$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...
227
		$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...
228
229
		$this['registrationForm']->setDefaults($visitor);
230
	}
231
232
	/**
233
	 * @return RegistrationFormControl
234
	 */
235
	protected function createComponentRegistrationForm(): RegistrationForm
236
	{
237
		$control = $this->registrationFormFactory->create();
238
		$control->setMeetingId($this->getMeetingId());
239
		$control->onRegistrationSave[] = function(RegistrationForm $control, $newVisitor) {
240
			try {
241
				$guid = $this->getVisitorService()->create((array) $newVisitor);
242
				$result = $this->sendRegistrationSummary((array) $newVisitor, $guid);
243
244
				Debugger::log('Storage of visitor('. $guid .') successfull, result: ' . json_encode($result), Debugger::INFO);
245
				$this->flashMessage('Účastník(' . $guid . ') byl úspěšně uložen.', self::FLASH_TYPE_OK);
246
			} 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...
247
				Debugger::log('Storage of visitor('. $guid .') failed, result: ' .  $e->getMessage(), Debugger::ERROR);
248
				$this->flashMessage('Uložení účastníka selhalo, chyba: ' . $e->getMessage(), self::FLASH_TYPE_ERROR);
249
			}
250
251
			$this->redirect('Registration:check', $guid);
252
		};
253
254
		return $control;
255
	}
256
257
	/**
258
	 * @return VisitorEntity
259
	 */
260
	protected function useLoggedVisitor(): VisitorEntity
261
	{
262
		$userDetail = $this->getUserService()->getUserDetail();
263
		$skautisUser = $this->getUserService()->getPersonalDetail($userDetail->ID_Person);
264
		$membership = $this->getUserService()->getPersonUnitDetail($userDetail->ID_Person);
265
266
		if(!preg_match('/^[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}$/', $membership->RegistrationNumber)) {
267
			$skautisUserUnit = $this->getUserService()->getParentUnitDetail($membership->ID_Unit)[0];
268
		} else {
269
			$skautisUserUnit = $this->getUserService()->getUnitDetail($membership->ID_Unit);
270
		}
271
272
		$visitor = new VisitorEntity;
273
		$visitor->name = $skautisUser->FirstName;
274
		$visitor->surname = $skautisUser->LastName;
275
		$visitor->nick = $skautisUser->NickName;
276
		$visitor->email = $skautisUser->Email;
277
		$visitor->street = $skautisUser->Street;
278
		$visitor->city = $skautisUser->City;
279
		$visitor->postal_code = preg_replace('/\s+/', '', $skautisUser->Postcode);
280
		$visitor->birthday = (new DateTime($skautisUser->Birthday))->format('d. m. Y');
281
		$visitor->group_name = $skautisUserUnit->DisplayName;
282
		$visitor->group_num = $skautisUserUnit->RegistrationNumber;
283
		if(isset($membership->Unit)) {
284
			$visitor->troop_name = $membership->Unit;
285
		}
286
287
		return $visitor;
288
	}
289
290
	/**
291
	 * @return MealModel
292
	 */
293
	protected function getMealModel()
294
	{
295
		return $this->mealModel;
296
	}
297
298
	/**
299
	 * @param  MealModel $model
300
	 * @return $this
301
	 */
302
	protected function setMealModel(MealModel $model)
303
	{
304
		$this->mealModel = $model;
305
306
		return $this;
307
	}
308
309
	/**
310
	 * @return MeetingModel
311
	 */
312
	protected function getMeetingModel()
313
	{
314
		return $this->meetingModel;
315
	}
316
317
	/**
318
	 * @param  MeetingModel $model
319
	 * @return $this
320
	 */
321
	protected function setMeetingModel(MeetingModel $model)
322
	{
323
		$this->meetingModel = $model;
324
325
		return $this;
326
	}
327
328
	/**
329
	 * @return VisitorModel
330
	 */
331
	protected function getVisitorModel()
332
	{
333
		return $this->visitorModel;
334
	}
335
336
	/**
337
	 * @param  VisitorModel $model
338
	 * @return $this
339
	 */
340
	protected function setVisitorModel(VisitorModel $model)
341
	{
342
		$this->visitorModel = $model;
343
344
		return $this;
345
	}
346
347
	/**
348
	 * @return ProgramModel
349
	 */
350
	protected function getProgramModel()
351
	{
352
		return $this->programModel;
353
	}
354
355
	/**
356
	 * @param  ProgramModel $model
357
	 * @return $this
358
	 */
359
	protected function setProgramModel(ProgramModel $model)
360
	{
361
		$this->programModel = $model;
362
363
		return $this;
364
	}
365
366
	/**
367
	 * @return UserService
368
	 */
369
	protected function getUserService()
370
	{
371
		return $this->userService;
372
	}
373
374
	/**
375
	 * @param  UserService $service
376
	 * @return $this
377
	 */
378
	protected function setUserService(UserService $service)
379
	{
380
		$this->userService = $service;
381
382
		return $this;
383
	}
384
385
	/**
386
	 * @return ProgramService
387
	 */
388
	protected function getProgramService()
389
	{
390
		return $this->programService;
391
	}
392
393
	/**
394
	 * @param  ProgramService $service
395
	 * @return $this
396
	 */
397
	protected function setProgramService(ProgramService $service)
398
	{
399
		$this->programService = $service;
400
401
		return $this;
402
	}
403
404
}
405