Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
IncrementTrait
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 next
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Db\Record;
16
17use Pop\Crypt\Hashing\Hasher;
18use Pop\Crypt\Encryption\Encrypter;
19use Pop\Db\Sql\PredicateSet;
20
21/**
22 * Increment trait
23 *
24 * @category   Pop
25 * @package    Pop\Db
26 * @author     Nick Sagona, III <nick@popphp.org>
27 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
28 * @license    https://www.popphp.org/license     New BSD License
29 * @version    7.0.0
30 */
31trait IncrementTrait
32{
33
34    /**
35     * Get next increment value
36     *
37     * @param  mixed  $columns
38     * @param  int    $start
39     * @param  string $field
40     * @return int
41     */
42    public static function next(array|PredicateSet $columns, int $start = 1, string $field = 'row_id'): int
43    {
44        $currentIndex = (int)static::findOne($columns, ['order' => $field . ' DESC'])->{$field};
45        return (!empty($currentIndex) ? ($currentIndex + 1) : $start);
46    }
47
48}