Skip to content

Commit c377302

Browse files
committed
style: cs-fix
1 parent 5372c7e commit c377302

6 files changed

Lines changed: 29 additions & 38 deletions

File tree

src/Constants/schemas/hashing.config.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
use Nette\Schema\Expect;
1313

1414
return Expect::structure([
15-
'driver' => Expect::anyOf('bcrypt', 'argon', 'argon2id')->default('bcrypt'),
16-
'bcrypt' => Expect::structure([
17-
'rounds' => Expect::int()->default(12),
18-
'verify' => Expect::bool()->default(true),
19-
]),
20-
'argon' => Expect::structure([
21-
'memory' => Expect::int()->default(65536),
22-
'threads' => Expect::int()->default(1),
23-
'time' => Expect::int()->default(4),
24-
'verify' => Expect::bool()->default(true),
25-
]),
15+
'driver' => Expect::anyOf('bcrypt', 'argon', 'argon2id')->default('bcrypt'),
16+
'bcrypt' => Expect::structure([
17+
'rounds' => Expect::int()->default(12),
18+
'verify' => Expect::bool()->default(true),
19+
]),
20+
'argon' => Expect::structure([
21+
'memory' => Expect::int()->default(65536),
22+
'threads' => Expect::int()->default(1),
23+
'time' => Expect::int()->default(4),
24+
'verify' => Expect::bool()->default(true),
25+
]),
2626
])->otherItems();

src/Exceptions/HashingException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace BlitzPHP\Exceptions;
1313

14-
use RuntimeException;
15-
1614
/**
1715
* Hashing exception
1816
*/

src/Security/Encryption/Handlers/BaseHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function __construct(?object $config = null)
3636
if (property_exists($this, $key)) {
3737
$this->{$key} = $value;
3838
} elseif (property_exists($this, $key = Text::camel($key))) {
39-
$this->{$key} = $value;
40-
}
39+
$this->{$key} = $value;
40+
}
4141
}
4242
}
4343

src/Security/Hashing/Handlers/ArgonHandler.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(array $options = [])
5353
$this->verifyAlgorithm = $options['verify'] ?? $this->verifyAlgorithm;
5454
}
5555

56-
/**
56+
/**
5757
* {@inheritDoc}
5858
*
5959
* @throws RuntimeException
@@ -124,7 +124,7 @@ public function verifyConfiguration(string $value): bool
124124
/**
125125
* Vérifie l'algorithme de la valeur hachée.
126126
*/
127-
protected function isUsingCorrectAlgorithm(string $hashedValue): bool
127+
protected function isUsingCorrectAlgorithm(string $hashedValue): bool
128128
{
129129
return $this->info($hashedValue)['algoName'] === 'argon2i';
130130
}
@@ -137,22 +137,18 @@ protected function isUsingValidOptions(string $hashedValue): bool
137137
['options' => $options] = $this->info($hashedValue);
138138

139139
if (
140-
! is_int($options['memory_cost'] ?? null) ||
141-
! is_int($options['time_cost'] ?? null) ||
142-
! is_int($options['threads'] ?? null)
143-
) {
144-
return false;
145-
}
146-
147-
if (
148-
$options['memory_cost'] > $this->memory ||
149-
$options['time_cost'] > $this->time ||
150-
$options['threads'] > $this->threads
140+
! is_int($options['memory_cost'] ?? null)
141+
|| ! is_int($options['time_cost'] ?? null)
142+
|| ! is_int($options['threads'] ?? null)
151143
) {
152144
return false;
153145
}
154146

155-
return true;
147+
return ! (
148+
$options['memory_cost'] > $this->memory
149+
|| $options['time_cost'] > $this->time
150+
|| $options['threads'] > $this->threads
151+
);
156152
}
157153

158154
/**

src/Security/Hashing/Handlers/BcryptHandler.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ protected function isUsingValidOptions(string $hashedValue): bool
116116
return false;
117117
}
118118

119-
if ($options['cost'] > $this->rounds) {
120-
return false;
121-
}
122-
123-
return true;
119+
return ! ($options['cost'] > $this->rounds);
124120
}
125121

126122
/**

src/Security/Hashing/Hasher.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ class Hasher implements HasherInterface
2929
*/
3030
protected string $driver = '';
3131

32-
/**
32+
/**
3333
* Pilotes aux classes de gestionnaires, par ordre de préférence
3434
*/
3535
protected array $drivers = [
3636
'bcrypt',
3737
'argon',
3838
'argon2id',
3939
];
40+
4041
/**
4142
* Constructeur
4243
*/
@@ -45,7 +46,7 @@ public function __construct(protected ?object $config = null)
4546
$config ??= (object) config('hashing');
4647

4748
$this->config = $config;
48-
$this->driver = $config->driver;
49+
$this->driver = $config->driver;
4950
}
5051

5152
/**
@@ -118,8 +119,8 @@ public function initialize(?object $config = null): HasherInterface
118119
}
119120

120121
$handlerName = 'BlitzPHP\\Security\\Hashing\\Handlers\\' . ucfirst($this->driver) . 'Handler';
121-
$params = (array) $config;
122-
$this->hasher = new $handlerName($params[$this->driver]);
122+
$params = (array) $config;
123+
$this->hasher = new $handlerName($params[$this->driver]);
123124

124125
return $this->hasher;
125126
}

0 commit comments

Comments
 (0)