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

jojo1981 / polling / 20854630870

09 Jan 2026 02:12PM UTC coverage: 80.0%. Remained the same
20854630870

push

github

jojo1981
Upgrade to use dependency: jojo1981/contracts version: ^2.0 instead of ^1.0. Closes #4
https://github.com/jojo1981/polling/issues/4

52 of 65 relevant lines covered (80.0%)

15.51 hits per line

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

55.56
/src/Value/UnsignedInteger.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the jojo1981/polling package
4
 *
5
 * Copyright (c) 2021 Joost Nijhuis <jnijhuis81@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed in the root of the source code
9
 */
10
namespace Jojo1981\Polling\Value;
11

12
use Jojo1981\Contracts\Exception\ValueExceptionInterface;
13
use Jojo1981\Contracts\HashableInterface;
14
use Jojo1981\Contracts\ValueInterface;
15
use Jojo1981\Polling\Exception\ValueException;
16
use function hash;
17
use function is_int;
18
use function sprintf;
19

20
/**
21
 * @package Jojo1981\Polling\Value
22
 * @implements ValueInterface<int>
23
 */
24
final class UnsignedInteger implements ValueInterface, HashableInterface
25
{
26
    /** @var int */
27
    private int $value;
28

29
    /**
30
     * @param int $value
31
     * @throws ValueExceptionInterface
32
     */
33
    public function __construct($value)
34
    {
35
        $this->value = self::assertValue($value);
24✔
36
    }
37

38
    /**
39
     * @param ValueInterface $otherValue
40
     * @return bool
41
     */
42
    public function match(ValueInterface $otherValue): bool
43
    {
44
        return $otherValue instanceof self && $otherValue->getValue() === $this->getValue();
×
45
    }
46

47
    /**
48
     * @return int
49
     */
50
    public function getValue(): int
51
    {
52
        return $this->value;
18✔
53
    }
54

55
    /**
56
     * @return string
57
     */
58
    public function getHash(): string
59
    {
60
        return hash('sha256', (string) $this->value);
×
61
    }
62

63
    /**
64
     * @param mixed $value
65
     * @return int
66
     * @throws ValueExceptionInterface
67
     */
68
    private static function assertValue(mixed $value): int
69
    {
70
        if (!is_int($value)) {
24✔
71
            throw new ValueException('Value for UnsignedInteger should be be of type integer');
×
72
        }
73
        if ($value < 0) {
24✔
74
            throw new ValueException(sprintf('Value for UnsignedInteger should be higher than or equals zero. Given value: `%d`.', $value));
×
75
        }
76

77
        return $value;
24✔
78
    }
79
}
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