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

valkyrjaio / valkyrja / 16039388639

03 Jul 2025 01:23AM UTC coverage: 39.501% (+0.5%) from 38.991%
16039388639

push

github

MelechMizrachi
PHP CS Fixer: Fixing styling issues.

4052 of 10258 relevant lines covered (39.5%)

4.96 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\Session\Contract\Session;
25

26
use function is_string;
27

28
/**
29
 * Class JwtCryptRepository.
30
 *
31
 * @author Melech Mizrachi
32
 */
33
class JwtCryptRepository extends CryptTokenizedRepository implements Contract
34
{
35
    /**
36
     * JWTCryptRepository constructor.
37
     *
38
     * @param class-string<User> $user The user class
39
     */
40
    public function __construct(
41
        Adapter $adapter,
42
        protected JwtManager $jwt,
43
        Crypt $crypt,
44
        Session $session,
45
        Config $config,
46
        string $user
47
    ) {
48
        parent::__construct($adapter, $crypt, $session, $config, $user);
×
49
    }
50

51
    /**
52
     * @inheritDoc
53
     */
54
    protected function tokenizeUsers(AuthenticatedUsers $users): string
55
    {
56
        return $this->jwt->encode(['token' => parent::tokenizeUsers($users)]);
×
57
    }
58

59
    /**
60
     * @inheritDoc
61
     */
62
    protected function unTokenizeUsers(string $token): AuthenticatedUsers
63
    {
64
        $decodedJwt = $this->jwt->decode($token);
×
65

66
        $decodedToken = $decodedJwt['token'] ?? null;
×
67

68
        if (! is_string($decodedToken)) {
×
69
            throw new RuntimeException('Token must be a string');
×
70
        }
71

72
        return parent::unTokenizeUsers($decodedToken);
×
73
    }
74
}
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