Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
11 / 11
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractArgon2Hasher
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
11 / 11
14
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 setMemoryCost
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getMemoryCost
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasMemoryCost
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTimeCost
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTimeCost
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasTimeCost
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setThreads
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getThreads
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasThreads
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOptions
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2/**
3 * Pop PHP Framework (https://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@noladev.com>
7 * @copyright  Copyright (c) 2009-2026 NOLA Interactive, LLC.
8 * @license    https://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Crypt\Hashing;
15
16/**
17 * Pop Crypt Abstract Argon2 class
18 *
19 * @category   Pop
20 * @package    Pop\Crypt
21 * @author     Nick Sagona, III <dev@noladev.com>
22 * @copyright  Copyright (c) 2009-2026 NOLA Interactive, LLC.
23 * @license    https://www.popphp.org/license     New BSD License
24 * @version    3.0.0
25 */
26abstract class AbstractArgon2Hasher extends AbstractHasher
27{
28
29    /**
30     * Memory cost
31     * @var int
32     */
33    protected int $memoryCost = PASSWORD_ARGON2_DEFAULT_MEMORY_COST; // 65536
34
35    /**
36     * Time cost
37     * @var int
38     */
39    protected int $timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST; // 4
40
41    /**
42     * Threads
43     * @var int
44     */
45    protected int $threads = PASSWORD_ARGON2_DEFAULT_THREADS; // 1
46
47    /**
48     * Constructor
49     *
50     * Instantiate the Argon2 object
51     *
52     * @param int $memoryCost
53     * @param int $timeCost
54     * @param int $threads
55     */
56    public function __construct(
57        int $memoryCost = PASSWORD_ARGON2_DEFAULT_MEMORY_COST,
58        int $timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST,
59        int $threads = PASSWORD_ARGON2_DEFAULT_THREADS
60    )
61    {
62        $this->setMemoryCost($memoryCost);
63        $this->setTimeCost($timeCost);
64        $this->setThreads($threads);
65    }
66
67    /**
68     * Set memory cost
69     *
70     * @param  int $memoryCost
71     * @return static
72     */
73    public function setMemoryCost(int $memoryCost): static
74    {
75        $this->memoryCost = $memoryCost;
76        return $this;
77    }
78
79    /**
80     * Get memory cost
81     *
82     * @return int
83     */
84    public function getMemoryCost(): int
85    {
86        return $this->memoryCost;
87    }
88
89    /**
90     * Has memory cost
91     *
92     * @return bool
93     */
94    public function hasMemoryCost(): bool
95    {
96        return !empty($this->memoryCost);
97    }
98
99    /**
100     * Set time cost
101     *
102     * @param  int $timeCost
103     * @return static
104     */
105    public function setTimeCost(int $timeCost): static
106    {
107        $this->timeCost = $timeCost;
108        return $this;
109    }
110
111    /**
112     * Get time cost
113     *
114     * @return int
115     */
116    public function getTimeCost(): int
117    {
118        return $this->timeCost;
119    }
120
121    /**
122     * Has time cost
123     *
124     * @return bool
125     */
126    public function hasTimeCost(): bool
127    {
128        return !empty($this->timeCost);
129    }
130
131    /**
132     * Set threads
133     *
134     * @param  int $threads
135     * @return static
136     */
137    public function setThreads(int $threads): static
138    {
139        $this->threads = $threads;
140        return $this;
141    }
142
143    /**
144     * Get threads
145     *
146     * @return int
147     */
148    public function getThreads(): int
149    {
150        return $this->threads;
151    }
152
153    /**
154     * Has threads
155     *
156     * @return bool
157     */
158    public function hasThreads(): bool
159    {
160        return !empty($this->threads);
161    }
162
163    /**
164     * Set hasher options
165     *
166     * @param  array $options
167     * @return static
168     */
169    public function setOptions(array $options): static
170    {
171        if (isset($options['memory_cost'])) {
172            $this->setMemoryCost($options['memory_cost']);
173        }
174        if (isset($options['time_cost'])) {
175            $this->setTimeCost($options['time_cost']);
176        }
177        if (isset($options['threads'])) {
178            $this->setThreads($options['threads']);
179        }
180        return $this;
181    }
182
183}