Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Argon2idPasswordHasher
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hash
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 verify
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3// ╔════════════════════════════════════════════════════════════╗
4// ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║
5// ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com>     ║
6// ╚════════════════════════════════════════════════════════════╝
7
8declare(strict_types=1);
9
10namespace Phexium\Plugin\PasswordHasher\Adapter;
11
12use Override;
13use Phexium\Plugin\PasswordHasher\Port\PasswordHasherInterface;
14
15final readonly class Argon2idPasswordHasher implements PasswordHasherInterface
16{
17    public function __construct(
18        private ?int $memoryCost = null,
19        private ?int $timeCost = null,
20        private ?int $threads = null,
21    ) {}
22
23    #[Override]
24    public function hash(string $plainPassword): string
25    {
26        $options = [];
27
28        if ($this->memoryCost !== null) {
29            $options['memory_cost'] = $this->memoryCost;
30        }
31
32        if ($this->timeCost !== null) {
33            $options['time_cost'] = $this->timeCost;
34        }
35
36        if ($this->threads !== null) {
37            $options['threads'] = $this->threads;
38        }
39
40        return password_hash($plainPassword, PASSWORD_ARGON2ID, $options);
41    }
42
43    #[Override]
44    public function verify(string $plainPassword, string $hash): bool
45    {
46        return password_verify($plainPassword, $hash);
47    }
48}