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

azjezz / psl / 8543260029

03 Apr 2024 05:51PM UTC coverage: 98.865% (-0.04%) from 98.907%
8543260029

Pull #458

github

azjezz
chore: miscellaneous changes

Signed-off-by: azjezz <azjezz@protonmail.com>
Pull Request #458: chore: miscellaneous changes

77 of 78 new or added lines in 18 files covered. (98.72%)

1 existing line in 1 file now uncovered.

4354 of 4404 relevant lines covered (98.86%)

57.91 hits per line

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

90.0
/src/Psl/Network/Address.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Network;
6

7
/**
8
 * @psalm-immutable
9
 */
10
final readonly class Address
11
{
12
    public const DEFAULT_HOST = '127.0.0.1';
13
    public const DEFAULT_PORT = 0;
14

15
    public SocketScheme $scheme;
16

17
    /**
18
     * @var non-empty-string
19
     */
20
    public string $host;
21

22
    /**
23
     * @var int<0, 65535>|null
24
     */
25
    public ?int $port;
26

27
    /**
28
     * @param SocketScheme $scheme
29
     * @param non-empty-string $host
30
     * @param int<0,65535>|null $port
31
     *
32
     * @psalm-mutation-free
33
     */
34
    private function __construct(SocketScheme $scheme, string $host, ?int $port)
35
    {
36
        $this->scheme = $scheme;
5✔
37
        $this->host = $host;
5✔
38
        $this->port = $port;
5✔
39
    }
40

41
    /**
42
     * @param SocketScheme $scheme
43
     * @param non-empty-string $host
44
     * @param int<0,65535>|null $port
45
     *
46
     * @pure
47
     */
48
    public static function create(SocketScheme $scheme, string $host, ?int $port = null): self
49
    {
UNCOV
50
        return new self($scheme, $host, $port);
×
51
    }
52

53
    /**
54
     * @param non-empty-string $host
55
     *
56
     * @pure
57
     */
58
    public static function unix(string $host): self
59
    {
60
        return new self(SocketScheme::Unix, $host, null);
1✔
61
    }
62

63
    /**
64
     * @param non-empty-string $host
65
     * @param int<0,65535> $port
66
     *
67
     * @pure
68
     */
69
    public static function tcp(string $host = self::DEFAULT_HOST, int $port = self::DEFAULT_PORT): self
70
    {
71
        return new self(SocketScheme::Tcp, $host, $port);
4✔
72
    }
73

74
    /**
75
     * @return non-empty-string
76
     *
77
     * @psalm-mutation-free
78
     */
79
    public function toString(): string
80
    {
81
        $address = "{$this->scheme->value}://$this->host";
2✔
82
        if (null === $this->port) {
2✔
83
            return $address;
1✔
84
        }
85

86
        return "$address:$this->port";
1✔
87
    }
88
}
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