• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

valkyrjaio / valkyrja / 15659546660

15 Jun 2025 04:39AM UTC coverage: 47.202% (-0.4%) from 47.589%
15659546660

push

github

MelechMizrachi
Update Config.

5331 of 11294 relevant lines covered (47.2%)

16.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Valkyrja/Auth/Repository/CryptTokenizedRepository.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <melechmizrachi@gmail.com>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Valkyrja\Auth\Repository;
15

16
use Valkyrja\Auth\Adapter\Contract\Adapter;
17
use Valkyrja\Auth\Config;
18
use Valkyrja\Auth\Entity\Contract\User;
19
use Valkyrja\Auth\Model\Contract\AuthenticatedUsers;
20
use Valkyrja\Auth\Repository\Contract\CryptTokenizedRepository as Contract;
21
use Valkyrja\Crypt\Contract\Crypt as CryptManager;
22
use Valkyrja\Crypt\Driver\Contract\Driver as Crypt;
23
use Valkyrja\Crypt\Exception\CryptException;
24
use Valkyrja\Exception\InvalidArgumentException;
25
use Valkyrja\Session\Contract\Session;
26

27
/**
28
 * Class CryptTokenizedRepository.
29
 *
30
 * @author Melech Mizrachi
31
 */
32
class CryptTokenizedRepository extends TokenizedRepository implements Contract
33
{
34
    /**
35
     * The crypt.
36
     *
37
     * @var Crypt
38
     */
39
    protected Crypt $crypt;
40

41
    /**
42
     * CryptTokenizedRepository constructor.
43
     *
44
     * @param class-string<User> $user The user class
45
     */
46
    public function __construct(
47
        Adapter $adapter,
48
        CryptManager $crypt,
49
        Session $session,
50
        Config $config,
51
        string $user
52
    ) {
53
        parent::__construct($adapter, $session, $config, $user);
×
54

55
        $this->crypt = $crypt->use();
×
56
    }
57

58
    /**
59
     * @inheritDoc
60
     *
61
     * @throws CryptException
62
     */
63
    protected function tokenizeUsers(AuthenticatedUsers $users): string
64
    {
65
        return $this->crypt->encryptArray($users->asArray());
×
66
    }
67

68
    /**
69
     * @inheritDoc
70
     *
71
     * @throws CryptException
72
     */
73
    protected function unTokenizeUsers(string $token): AuthenticatedUsers
74
    {
75
        $decodedToken = $this->crypt->decryptArray($token);
×
76

77
        if (! is_string(array_key_first($decodedToken))) {
×
78
            throw new InvalidArgumentException('Provided token is invalid');
×
79
        }
80

81
        /** @var array<string, mixed> $decodedToken */
82

83
        return $this->usersModel::fromArray($decodedToken);
×
84
    }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc