Skip to content

Commit

Permalink
Merge pull request #1 from WeareJH/bugfix/password-repository
Browse files Browse the repository at this point in the history
Update the Password Repository
  • Loading branch information
Loxzibit committed Apr 14, 2021
2 parents 82e9cdc + b121bb9 commit 2f3ef49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 30 deletions.
16 changes: 8 additions & 8 deletions Api/Data/PasswordInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ interface PasswordInterface extends ExtensibleDataInterface
public const CALCULATION_TIME = 'calc_time';

/**
* @return string
* @return string|null
*/
public function getPassword(): ?string;

/**
* @return int
* @return int|null
*/
public function getGuesses(): int;
public function getGuesses(): ?int;

/**
* @return array
* @return array|null
*/
public function getSequence(): ?array;

/**
* @return array
* @return array|null
*/
public function getCrackTimesSeconds(): ?array;

/**
* @return array
* @return array|null
*/
public function getCrackTimesDisplay(): ?array;

Expand All @@ -50,12 +50,12 @@ public function getCrackTimesDisplay(): ?array;
public function getScore(): int;

/**
* @return array
* @return array|null
*/
public function getFeedback(): ?array;

/**
* @return float
* @return float|null
*/
public function getCalculationTime(): ?float;

Expand Down
6 changes: 3 additions & 3 deletions Model/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public function getPassword(): ?string
return $this->_get(self::PASSWORD);
}

public function getGuesses(): int
public function getGuesses(): ?int
{
return (int) $this->_get(self::GUESSES);
}

public function getSequence(): ?array
{
return $this->_get(self::SEQUENCE);
Expand All @@ -44,7 +44,7 @@ public function getFeedback(): ?array
{
return $this->_get(self::FEEDBACK);
}

public function getCalculationTime(): ?float
{
return $this->_get(self::CALCULATION_TIME);
Expand Down
20 changes: 2 additions & 18 deletions Model/PasswordRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Jh\PasswordPolicy\Api\Data\PasswordInterface;
use Jh\PasswordPolicy\Api\PasswordRepositoryInterface;
use Jh\PasswordPolicy\Model\PasswordFactory;
use Magento\Framework\Api\DataObjectHelper;
use ZxcvbnPhp\Zxcvbn as StrengthEstimator;

class PasswordRepository implements PasswordRepositoryInterface
Expand All @@ -22,31 +21,16 @@ class PasswordRepository implements PasswordRepositoryInterface
*/
private $passwordFactory;

/**
* @var DataObjectHelper
*/
private $dataObjectHelper;

public function __construct(
StrengthEstimator $strengthEstimator,
PasswordFactory $passwordFactory,
DataObjectHelper $dataObjectHelper
PasswordFactory $passwordFactory
) {
$this->strengthEstimator = $strengthEstimator;
$this->passwordFactory = $passwordFactory;
$this->dataObjectHelper = $dataObjectHelper;
}

public function get(string $password): PasswordInterface
{
$passwordStrengthDataObject = $this->passwordFactory->create();

$this->dataObjectHelper->populateWithArray(
$passwordStrengthDataObject,
$this->strengthEstimator->passwordStrength($password),
PasswordInterface::class
);

return $passwordStrengthDataObject;
return $this->passwordFactory->create(['data' => $this->strengthEstimator->passwordStrength($password)]);
}
}
3 changes: 2 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Jh\PasswordPolicy\Api\PasswordRepositoryInterface" type="Jh\PasswordPolicy\Model\Password"/>
<preference for="Jh\PasswordPolicy\Api\Data\PasswordInterface" type="Jh\PasswordPolicy\Model\Password"/>
<preference for="Jh\PasswordPolicy\Api\PasswordRepositoryInterface" type="Jh\PasswordPolicy\Model\PasswordRepository"/>
</config>

0 comments on commit 2f3ef49

Please sign in to comment.