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

Yoast / whip / 7300735247

22 Dec 2023 02:07PM UTC coverage: 31.683% (+3.0%) from 28.713%
7300735247

push

github

web-flow
Merge pull request #157 from Yoast/move-to-namespace-v2

Move source classes to the `Yoast\WHIPv2` namespace

30 of 114 new or added lines in 18 files covered. (26.32%)

96 of 303 relevant lines covered (31.68%)

2.66 hits per line

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

83.33
/src/MessageDismisser.php
1
<?php
2

3
namespace Yoast\WHIPv2;
4

5
use Yoast\WHIPv2\Interfaces\DismissStorage;
6

7
/**
8
 * A class to dismiss messages.
9
 */
10
class MessageDismisser {
11

12
        /**
13
         * Storage object to manage the dismissal state.
14
         *
15
         * @var DismissStorage
16
         */
17
        protected $storage;
18

19
        /**
20
         * The current time.
21
         *
22
         * @var int
23
         */
24
        protected $currentTime;
25

26
        /**
27
         * The number of seconds the message will be dismissed.
28
         *
29
         * @var int
30
         */
31
        protected $threshold;
32

33
        /**
34
         * MessageDismisser constructor.
35
         *
36
         * @param int            $currentTime The current time.
37
         * @param int            $threshold   The number of seconds the message will be dismissed.
38
         * @param DismissStorage $storage     Storage object to manage the dismissal state.
39
         */
40
        public function __construct( $currentTime, $threshold, DismissStorage $storage ) {
15✔
41
                $this->currentTime = $currentTime;
15✔
42
                $this->threshold   = $threshold;
15✔
43
                $this->storage     = $storage;
15✔
44
        }
10✔
45

46
        /**
47
         * Saves the version number to the storage to indicate the message as being dismissed.
48
         *
49
         * @return void
50
         */
51
        public function dismiss() {
3✔
52
                $this->storage->set( $this->currentTime );
3✔
53
        }
2✔
54

55
        /**
56
         * Checks if the current time is lower than the stored time extended by the threshold.
57
         *
58
         * @return bool True when current time is lower than stored value + threshold.
59
         */
60
        public function isDismissed() {
12✔
61
                return ( $this->currentTime <= ( $this->storage->get() + $this->threshold ) );
12✔
62
        }
63

64
        /**
65
         * Checks the nonce.
66
         *
67
         * @param string $nonce  The nonce to check.
68
         * @param string $action The action to check.
69
         *
70
         * @return bool True when the nonce is valid.
71
         */
72
        public function verifyNonce( $nonce, $action ) {
×
NEW
73
                return (bool) \wp_verify_nonce( $nonce, $action );
×
74
        }
75
}
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