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

lmc-eu / matej-client-php / 7527331519

15 Jan 2024 10:11AM UTC coverage: 100.0%. Remained the same
7527331519

Pull #135

github

web-flow
Merge 117257645 into 9666a6254
Pull Request #135: Update to new coding standard

20 of 21 new or added lines in 5 files covered. (95.24%)

400 existing lines in 23 files now uncovered.

758 of 758 relevant lines covered (100.0%)

18.54 hits per line

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

100.0
/src/Model/Command/AbstractUserRecommendation.php
1
<?php declare(strict_types=1);
2

3
namespace Lmc\Matej\Model\Command;
4

5
use Lmc\Matej\Model\Assertion;
6

7
/**
8
 * Deliver recommendations for given user.
9
 */
10
abstract class AbstractUserRecommendation extends AbstractRecommendation implements UserAwareInterface
11
{
12
    /** @var string */
13
    private $userId;
14
    /** @var float */
15
    private $rotationRate;
16
    /** @var int */
17
    private $rotationTime;
18
    /** @var bool */
19
    private $hardRotation;
20

21
    protected function __construct(string $userId, string $scenario)
22
    {
UNCOV
23
        parent::__construct($scenario);
36✔
UNCOV
24
        $this->setUserId($userId);
36✔
25
    }
9✔
26

27
    /**
28
     * Even with rotation rate 1.0 user could still obtain the same recommendations in some edge cases.
29
     * To prevent this, enable hard rotation - recommended items are then excluded until rotation time is expired.
30
     * By default hard rotation is not enabled.
31
     * @return $this
32
     */
33
    public function enableHardRotation(): self
34
    {
UNCOV
35
        $this->hardRotation = true;
8✔
36

UNCOV
37
        return $this;
8✔
38
    }
39

40
    /**
41
     * Get id of user requesting recommendation.
42
     */
43
    public function getUserId(): string
44
    {
UNCOV
45
        return $this->userId;
8✔
46
    }
47

48
    /**
49
     * Set how much should the item be penalized for being recommended again in the near future.
50
     *
51
     * @return $this
52
     */
53
    public function setRotationRate(float $rotationRate): self
54
    {
UNCOV
55
        Assertion::between($rotationRate, 0, 1);
8✔
56

UNCOV
57
        $this->rotationRate = $rotationRate;
8✔
58

UNCOV
59
        return $this;
8✔
60
    }
61

62
    /**
63
     * Specify for how long will the item's rotationRate be taken in account and so the item is penalized for
64
     * recommendations.
65
     *
66
     * @return $this
67
     */
68
    public function setRotationTime(int $rotationTime): self
69
    {
UNCOV
70
        Assertion::greaterOrEqualThan($rotationTime, 0);
12✔
71

UNCOV
72
        $this->rotationTime = $rotationTime;
12✔
73

UNCOV
74
        return $this;
12✔
75
    }
76

77
    protected function setUserId(string $userId): void
78
    {
UNCOV
79
        Assertion::typeIdentifier($userId);
36✔
80

UNCOV
81
        $this->userId = $userId;
36✔
82
    }
9✔
83

84
    protected function getCommandParameters(): array
85
    {
UNCOV
86
        $parameters = parent::getCommandParameters();
36✔
87

UNCOV
88
        $parameters['user_id'] = $this->userId;
36✔
89

UNCOV
90
        if ($this->rotationRate !== null) {
36✔
UNCOV
91
            $parameters['rotation_rate'] = $this->rotationRate;
8✔
92
        }
93

UNCOV
94
        if ($this->rotationTime !== null) {
36✔
UNCOV
95
            $parameters['rotation_time'] = $this->rotationTime;
12✔
96
        }
97

UNCOV
98
        if ($this->hardRotation !== null) {
36✔
UNCOV
99
            $parameters['hard_rotation'] = $this->hardRotation;
8✔
100
        }
101

UNCOV
102
        return $parameters;
36✔
103
    }
104
}
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