• 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/PollCount.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 get_class;
17
use function hash;
18
use function is_int;
19
use function sprintf;
20

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

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

39
    /**
40
     * @param mixed $value
41
     * @return int
42
     * @throws ValueExceptionInterface
43
     */
44
    private function assertValue(mixed $value): int
45
    {
46
        if (!is_int($value)) {
24✔
47
            throw new ValueException('Value for PollCount should be be of type integer');
×
48
        }
49
        if ($value < 1) {
24✔
50
            throw new ValueException(sprintf('Value for PollCount should be higher than or equals 1. Given value: `%d`.', $value));
×
51
        }
52

53
        return $value;
24✔
54
    }
55

56
    /**
57
     * @param ValueInterface $otherValue
58
     * @return bool
59
     */
60
    public function match(ValueInterface $otherValue): bool
61
    {
62
        return get_class($this) === get_class($otherValue) && $otherValue->getValue() === $this->getValue();
×
63
    }
64

65
    /**
66
     * @return int
67
     */
68
    public function getValue(): int
69
    {
70
        return $this->value;
18✔
71
    }
72

73
    /**
74
     * @return string
75
     */
76
    public function getHash(): string
77
    {
78
        return hash('sha256', (string) $this->value);
×
79
    }
80
}
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