1 | <?php namespace SimpleHash\Calculator; |
||
13 | class BcryptCalculator implements HashCalculatorInterface |
||
14 | { |
||
15 | const DEFAULT_COST = '10'; |
||
16 | const DEFAULT_SALT = 'Af13GgKoL503sCvf42dJ18'; |
||
17 | |||
18 | /** |
||
19 | * Costs |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $cost = ''; |
||
24 | |||
25 | /** |
||
26 | * Salt |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $salt = ''; |
||
31 | |||
32 | /** |
||
33 | * Constructor |
||
34 | * |
||
35 | * @param array $params |
||
36 | */ |
||
37 | 4 | public function __construct(array $params = array()) |
|
42 | |||
43 | /** |
||
44 | * Returns the Bcrypt hash |
||
45 | * |
||
46 | * @param string $data |
||
47 | * @return string |
||
48 | */ |
||
49 | 3 | public function getHash($data) |
|
53 | |||
54 | /** |
||
55 | * Builds the final salt string for PHP crypt. |
||
56 | * The blowfish type "$2y$" is used. |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | 3 | private function buildSaltString() |
|
64 | |||
65 | /** |
||
66 | * Sets the salt string from parameter array. |
||
67 | * If no salt is given, the default value will be used! |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | 4 | private function setSaltFromParams(array $params) |
|
76 | |||
77 | /** |
||
78 | * Sets the cost string from parameter array. |
||
79 | * If no cost is given, the default value will be used! |
||
80 | * |
||
81 | * @return void |
||
82 | */ |
||
83 | 4 | private function setCostFromParams(array $params) |
|
88 | |||
89 | /** |
||
90 | * Returns the first match from parameter array |
||
91 | * |
||
92 | * @param array $params |
||
93 | * @param string $regex |
||
94 | * @return string |
||
95 | */ |
||
96 | 4 | private function getMatchingData(array $params, $regex) |
|
106 | } |
||
107 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.