Completed
Push — master ( 32d63a...60b053 )
by Marcus
02:03
created

Helper::sendVerificationMail()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 24
rs 8.9713
cc 3
eloc 16
nc 3
nop 4
1
<?php
2
3
/*
4
    HCSF - A multilingual CMS and Shopsystem
5
    Copyright (C) 2014  Marcus Haase - [email protected]
6
7
    This program is free software: you can redistribute it and/or modify
8
    it under the terms of the GNU General Public License as published by
9
    the Free Software Foundation, either version 3 of the License, or
10
    (at your option) any later version.
11
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16
17
    You should have received a copy of the GNU General Public License
18
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
namespace HaaseIT\HCSF\Customer;
22
23
use HaaseIT\HCSF\HelperConfig;
24
use HaaseIT\Toolbox\Tools;
25
use Zend\ServiceManager\ServiceManager;
26
27
/**
28
 * Class Helper
29
 * @package HaaseIT\HCSF\Customer
30
 */
31
class Helper
32
{
33
    /**
34
     * @param string $sLang
35
     * @param array $aErr
36
     * @param bool $bEdit
37
     * @return array
38
     */
39
    public static function validateCustomerForm($sLang, $aErr = [], $bEdit = false)
40
    {
41
        if (empty(filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL))) {
42
            $aErr['email'] = true;
43
        }
44
        $postcorpname = filter_input(INPUT_POST, 'corpname', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
45 View Code Duplication
        if (HelperConfig::$customer['validate_corpname'] && (empty($postcorpname) || strlen(trim($postcorpname)) < 3)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
46
            $aErr['corpname'] = true;
47
        }
48
        $postname = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
49 View Code Duplication
        if (HelperConfig::$customer['validate_name'] && (empty($postname) || strlen(trim($postname)) < 3)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
50
            $aErr['name'] = true;
51
        }
52
        $poststreet = filter_input(INPUT_POST, 'street', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
53 View Code Duplication
        if (HelperConfig::$customer['validate_street'] && (empty($poststreet) || strlen(trim($poststreet)) < 3)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
54
            $aErr['street'] = true;
55
        }
56
        $postzip = filter_input(INPUT_POST, 'zip', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
57 View Code Duplication
        if (HelperConfig::$customer['validate_zip'] && (empty($postzip) || strlen(trim($postzip)) < 4)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
58
            $aErr['zip'] = true;
59
        }
60
        $posttown = filter_input(INPUT_POST, 'town', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
61 View Code Duplication
        if (HelperConfig::$customer['validate_town'] && (empty($posttown) || strlen(trim($posttown)) < 3)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
62
            $aErr['town'] = true;
63
        }
64
        $postphone = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
65 View Code Duplication
        if (HelperConfig::$customer['validate_phone'] && (empty($postphone) || strlen(trim($postphone)) < 6)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
66
            $aErr['phone'] = true;
67
        }
68
        $postcellphone = filter_input(INPUT_POST, 'cellphone', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
69 View Code Duplication
        if (HelperConfig::$customer['validate_cellphone'] && (empty($postcellphone) || strlen(trim($postcellphone)) < 11)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
70
            $aErr['cellphone'] = true;
71
        }
72
        $postfax = filter_input(INPUT_POST, 'fax', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
73 View Code Duplication
        if (HelperConfig::$customer['validate_fax'] && (empty($postfax) || strlen(trim($postfax)) < 6)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
74
            $aErr['fax'] = true;
75
        }
76
        $postcountry = filter_input(INPUT_POST, 'country', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
77
        if (HelperConfig::$customer['validate_country'] && (empty($postcountry) || !isset(HelperConfig::$countries['countries_' .$sLang][$postcountry]))) {
78
            $aErr['country'] = true;
79
        }
80
        $posttos = filter_input(INPUT_POST, 'tos');
81
        if (!$bEdit && $posttos !== 'y') {
82
            $aErr['tos'] = true;
83
        }
84
        $postcancellationdisclaimer = filter_input(INPUT_POST, 'cancellationdisclaimer');
85
        if (!$bEdit && $postcancellationdisclaimer !== 'y') {
86
            $aErr['cancellationdisclaimer'] = true;
87
        }
88
89
        $postpwd = filter_input(INPUT_POST, 'pwd');
90
        $postpwdc = filter_input(INPUT_POST, 'pwdc');
91
        if (!$bEdit || !empty($postpwd)) {
92
            if (strlen($postpwd) < HelperConfig::$customer['minimum_length_password']) {
93
                $aErr['passwordlength'] = true;
94
            }
95
            if ($postpwd !== $postpwdc) {
96
                $aErr['passwordmatch'] = true;
97
            }
98
        }
99
100
        return $aErr;
101
    }
102
103
    /**
104
     * @param string $sLang
105
     * @return string
106
     */
107
    public static function getDefaultCountryByConfig($sLang) {
108
        if (isset(HelperConfig::$core['defaultcountrybylang'][$sLang])) {
109
            return HelperConfig::$core['defaultcountrybylang'][$sLang];
110
        }
111
        return '';
112
    }
113
114
    /**
115
     * @param string $sKeyConfig
116
     * @param string $sKeyForm
117
     * @param array|bool $aUserData
118
     * @return bool
119
     */
120
    public static function getCustomerFormDefaultValue($sKeyConfig, $sKeyForm, $aUserData) {
0 ignored issues
show
Coding Style introduced by
getCustomerFormDefaultValue uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
121
        $sDefaultValue = self::getUserData($sKeyConfig, $aUserData);
0 ignored issues
show
Bug introduced by
It seems like $aUserData defined by parameter $aUserData on line 120 can also be of type array; however, HaaseIT\HCSF\Customer\Helper::getUserData() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
122
        if (!$sDefaultValue && isset($_SESSION['formsave_addrform'][$sKeyForm])) {
123
            $sDefaultValue = $_SESSION['formsave_addrform'][$sKeyForm];
124
        }
125
126
        return $sDefaultValue;
127
    }
128
129
    /**
130
     * @param string $sLang
131
     * @param string $sPurpose
132
     * @param array $aErr
133
     * @param bool $aUserData
134
     * @return array
135
     */
136
    public static function buildCustomerForm($sLang, $sPurpose = 'none', $aErr = [], $aUserData = false)
0 ignored issues
show
Coding Style introduced by
buildCustomerForm uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
137
    {
138
        $sDefaultCountry = self::getCustomerFormDefaultValue('cust_country', 'country', $aUserData);
139
140
        // Purposes: shoppingcart, userhome, shopadmin, editprofile, register
141
        // fv = field_value, fr = field_required
142
        $aData = [
143
            'purpose' => $sPurpose,
144
            'errormessage' => $aErr,
145
            'readonlycustno' => $sPurpose === 'shopadmin' ? true : false,
146
            'readonly' =>
147
                $sPurpose === 'shopadmin'
148
                || $sPurpose === 'userhome'
149
                || ($sPurpose === 'editprofile' && !HelperConfig::$customer['allow_edituserprofile'])
150
                || ($sPurpose === 'shoppingcart' && self::getUserData())
151
            ,
152
            'fv_custno' => Tools::getFormfield(
153
                'custno',
154
                self::getCustomerFormDefaultValue('cust_no', 'custno', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef..., 'custno', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
155
                true
156
            ),
157
            'fv_email' => Tools::getFormfield(
158
                'email',
159
                self::getCustomerFormDefaultValue('cust_email', 'email', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef...', 'email', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
160
                true
161
            ),
162
            'fv_corpname' => Tools::getFormfield(
163
                'corpname',
164
                self::getCustomerFormDefaultValue('cust_corp', 'corpname', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef...'corpname', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
165
                true
166
            ),
167
            'fr_corpname' => HelperConfig::$customer['validate_corpname'],
168
            'fv_name' => Tools::getFormfield(
169
                'name',
170
                self::getCustomerFormDefaultValue('cust_name', 'name', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef...e', 'name', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
171
                true
172
            ),
173
            'fr_name' => HelperConfig::$customer['validate_name'],
174
            'fv_street' => Tools::getFormfield(
175
                'street',
176
                self::getCustomerFormDefaultValue('cust_street', 'street', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef..., 'street', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
                true
178
            ),
179
            'fr_street' => HelperConfig::$customer['validate_street'],
180
            'fv_zip' => Tools::getFormfield(
181
                'zip',
182
                self::getCustomerFormDefaultValue('cust_zip', 'zip', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef...ip', 'zip', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
183
                true
184
            ),
185
            'fr_zip' => HelperConfig::$customer['validate_zip'],
186
            'fv_town' => Tools::getFormfield(
187
                'town',
188
                self::getCustomerFormDefaultValue('cust_town', 'town', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef...n', 'town', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
189
                true
190
            ),
191
            'fr_town' => HelperConfig::$customer['validate_town'],
192
            'fv_phone' => Tools::getFormfield(
193
                'phone',
194
                self::getCustomerFormDefaultValue('cust_phone', 'phone', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef...', 'phone', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
195
                true
196
            ),
197
            'fr_phone' => HelperConfig::$customer['validate_phone'],
198
            'fv_cellphone' => Tools::getFormfield(
199
                'cellphone',
200
                self::getCustomerFormDefaultValue('cust_cellphone', 'cellphone', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef...cellphone', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
201
                true
202
            ),
203
            'fr_cellphone' => HelperConfig::$customer['validate_cellphone'],
204
            'fv_fax' => Tools::getFormfield(
205
                'fax',
206
                self::getCustomerFormDefaultValue('cust_fax', 'fax', $aUserData),
0 ignored issues
show
Documentation introduced by
self::getCustomerFormDef...ax', 'fax', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
207
                true
208
            ),
209
            'fr_fax' => HelperConfig::$customer['validate_fax'],
210
            'fv_country' => Tools::getFormfield(
211
                'country',
212
                ($sDefaultCountry ? $sDefaultCountry : self::getDefaultCountryByConfig($sLang)),
0 ignored issues
show
Bug introduced by
It seems like $sDefaultCountry ? $sDef...CountryByConfig($sLang) can also be of type boolean; however, HaaseIT\Toolbox\Tools::getFormfield() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
213
                true
214
            ),
215
            'fr_country' => HelperConfig::$customer['validate_country'],
216
        ];
217
218
        if ($sPurpose === 'admin') {
219
            $aData['fv_custgroups'] = HelperConfig::$customer['customer_groups'];
220
            $aData['fv_custgroup_selected'] = Tools::getFormfield('custgroup', self::getUserData('cust_group', $aUserData), true);
0 ignored issues
show
Documentation introduced by
self::getUserData('cust_group', $aUserData) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
221
        } elseif ($sPurpose === 'shopadmin') {
222
            $aData['fv_custgroup'] = '';
223
            if (isset(HelperConfig::$customer['customer_groups'][self::getUserData('cust_group', $aUserData)])) {
224
                $aData['fv_custgroup'] = HelperConfig::$customer['customer_groups'][self::getUserData('cust_group', $aUserData)];
225
            }
226
        }
227
228
        if ($sPurpose === 'admin' || $sPurpose === 'register' || $sPurpose === 'editprofile') {
229
            $aData['fv_pwd'] = (($sPurpose === 'admin' || $sPurpose === 'editprofile') ? '' : Tools::getFormfield('pwd', ''));
230
            $aData['fv_pwdc'] = (($sPurpose === 'admin' || $sPurpose === 'editprofile') ? '' : Tools::getFormfield('pwdc', ''));
231
        }
232
233
        if ($sPurpose === 'shoppingcart') {
234
            $sRememberedRemarks = '';
235
            if (isset($_SESSION['formsave_addrform']['remarks'])) {
236
                $sRememberedRemarks = $_SESSION['formsave_addrform']['remarks'];
237
            }
238
            $aData['fv_remarks'] = Tools::getFormfield('remarks', $sRememberedRemarks, true);
239
        }
240
241
        if ($sPurpose === 'shoppingcart' || $sPurpose === 'register') {
242
            if (!self::getUserData()) {
243
                $aData['fv_tos'] = Tools::getCheckbox('tos', 'y');
244
                $aData['fv_cancellationdisclaimer'] = Tools::getCheckbox('cancellationdisclaimer', 'y');
245
            }
246
        }
247
248
        if ($sPurpose === 'shoppingcart') {
249
            $aData['fv_paymentmethods'] = HelperConfig::$shop['paymentmethods'];
250
            $aData['fv_paymentmethod'] = Tools::getFormfield('paymentmethod', '');
251
        }
252
253
        if ($sPurpose === 'admin') {
254
            $aData['fv_active'] = self::getUserData('cust_active', $aUserData) === 'y';
255
            $aData['fv_emailverified'] = self::getUserData('cust_emailverified', $aUserData) === 'y';
256
        }
257
        return $aData;
258
    }
259
260
    /**
261
     * @param $sEmailVerificationcode
262
     * @param $sTargetAddress
263
     * @param ServiceManager $serviceManager
264
     * @param bool $bCust
265
     */
266
    public static function sendVerificationMail($sEmailVerificationcode, $sTargetAddress, ServiceManager $serviceManager, $bCust = false)
267
    {
268
        if ($bCust) {
269
            $sSubject = $serviceManager->get('textcats')->T('register_mail_emailverification_subject');
270
271
            $serverhttps = filter_input(INPUT_SERVER, 'HTTPS');
272
            $servername = filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_URL);
273
            $aP['link'] = 'http'.($serverhttps === 'on' ? 's' : '').'://';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$aP was never initialized. Although not strictly required by PHP, it is generally a good practice to add $aP = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
274
            $aP['link'] .= $servername.'/_misc/verifyemail.html?key='.$sEmailVerificationcode;
275
276
            $sMessage = $serviceManager->get('twig')->render('customer/sendverificationmail.twig', $aP);
277
        } else {
278
            $hardcodedtextcats = $serviceManager->get('hardcodedtextcats');
279
280
            $sSubject = $hardcodedtextcats->get('newcustomerregistration_mail_subject');
281
            $sMessage = $hardcodedtextcats->get('newcustomerregistration_mail_text1').' ';
282
            $sMessage .= $sTargetAddress.$hardcodedtextcats->get(
283
                'newcustomerregistration_mail_text2').' '.date(HelperConfig::$core['locale_format_date_time']
284
                );
285
            $sTargetAddress = HelperConfig::$core['email_sender'];
286
        }
287
288
        \HaaseIT\HCSF\Helper::mailWrapper($sTargetAddress, $sSubject, $sMessage);
289
    }
290
291
    /**
292
     * @param string $sField
293
     * @param bool $aUserdata
294
     * @return bool
295
     */
296
    public static function getUserData($sField = '', $aUserdata = false)
0 ignored issues
show
Coding Style introduced by
getUserData uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
297
    {
298
        if (!$aUserdata) {
299
            if (!isset($_SESSION['user']) || !is_array($_SESSION['user'])) {
300
                return false;
301
            } elseif ($sField == '') {
302
                return true;
303
            }
304
305
            if ($sField != '' && isset($_SESSION['user'][$sField]) && $_SESSION['user'][$sField] != '') {
306
                return $_SESSION['user'][$sField];
307
            }
308
        } else {
309
            if (isset($aUserdata[$sField])) {
310
                return $aUserdata[$sField];
311
            } elseif ($sField = '') {
0 ignored issues
show
Unused Code introduced by
$sField 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...
312
                return false;
313
            }
314
        }
315
    }
316
}
317