• 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/JwtCryptRepository.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\JWTCryptRepository as Contract;
21
use Valkyrja\Crypt\Contract\Crypt;
22
use Valkyrja\Exception\RuntimeException;
23
use Valkyrja\Jwt\Contract\Jwt as JwtManager;
24
use Valkyrja\Jwt\Driver\Contract\Driver as Jwt;
25
use Valkyrja\Session\Contract\Session;
26

27
use function is_string;
28

29
/**
30
 * Class JwtCryptRepository.
31
 *
32
 * @author Melech Mizrachi
33
 */
34
class JwtCryptRepository extends CryptTokenizedRepository implements Contract
35
{
36
    /**
37
     * The Jwt service.
38
     *
39
     * @var Jwt
40
     */
41
    protected Jwt $jwt;
42

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

58
        $this->jwt = $jwt->use();
×
59
    }
60

61
    /**
62
     * @inheritDoc
63
     */
64
    protected function tokenizeUsers(AuthenticatedUsers $users): string
65
    {
66
        return $this->jwt->encode(['token' => parent::tokenizeUsers($users)]);
×
67
    }
68

69
    /**
70
     * @inheritDoc
71
     */
72
    protected function unTokenizeUsers(string $token): AuthenticatedUsers
73
    {
74
        $decodedJwt = $this->jwt->decode($token);
×
75

76
        $decodedToken = $decodedJwt['token'] ?? null;
×
77

78
        if (! is_string($decodedToken)) {
×
79
            throw new RuntimeException('Token must be a string');
×
80
        }
81

82
        return parent::unTokenizeUsers($decodedToken);
×
83
    }
84
}
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