Issues (3877)

SequenceCustomerPasswordPolicy.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Spryker\Zed\Customer\Business\CustomerPasswordPolicy;
9
10
use Generated\Shared\Transfer\CustomerErrorTransfer;
11
use Generated\Shared\Transfer\CustomerResponseTransfer;
12
use Spryker\Zed\Customer\CustomerConfig;
13
14
class SequenceCustomerPasswordPolicy implements CustomerPasswordPolicyInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    protected const GLOSSARY_KEY_PASSWORD_POLICY_ERROR_SEQUENCE = 'customer.password.error.sequence';
20
21
    /**
22
     * @var int|null
23
     */
24
    protected $customerPasswordSequenceLimit;
25
26
    /**
27
     * @param \Spryker\Zed\Customer\CustomerConfig $customerConfig
28
     */
29
    public function __construct(CustomerConfig $customerConfig)
30
    {
31
        $this->customerPasswordSequenceLimit = $customerConfig->getCustomerPasswordSequenceLimit();
0 ignored issues
show
Are you sure the assignment to $this->customerPasswordSequenceLimit is correct as $customerConfig->getCust...PasswordSequenceLimit() targeting Spryker\Zed\Customer\Cus...PasswordSequenceLimit() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
32
    }
33
34
    /**
35
     * @param string $password
36
     * @param \Generated\Shared\Transfer\CustomerResponseTransfer $customerResponseTransfer
37
     *
38
     * @return \Generated\Shared\Transfer\CustomerResponseTransfer
39
     */
40
    public function validatePassword(
41
        string $password,
42
        CustomerResponseTransfer $customerResponseTransfer
43
    ): CustomerResponseTransfer {
44
        if (!$this->customerPasswordSequenceLimit || $this->customerPasswordSequenceLimit <= 1) {
45
            return $customerResponseTransfer;
46
        }
47
48
        $regularExpression = '(.)' . str_repeat('\1', $this->customerPasswordSequenceLimit - 1);
49
        if (!preg_match('/' . $regularExpression . '/', $password)) {
50
            return $customerResponseTransfer;
51
        }
52
53
        $customerErrorTransfer = (new CustomerErrorTransfer())
54
            ->setMessage(static::GLOSSARY_KEY_PASSWORD_POLICY_ERROR_SEQUENCE);
55
        $customerResponseTransfer->setIsSuccess(false)
56
            ->addError($customerErrorTransfer);
57
58
        return $customerResponseTransfer;
59
    }
60
}
61