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

IlyasDeckers / ody-core / 13589380408

28 Feb 2025 01:41PM UTC coverage: 13.422% (-19.7%) from 33.151%
13589380408

push

github

IlyasDeckers
add support classes/methods (wip)

0 of 2412 new or added lines in 16 files covered. (0.0%)

544 of 4053 relevant lines covered (13.42%)

4.04 hits per line

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

0.0
/src/Support/Conditionable/HigherOrderWhenProxy.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Ody\Core\Support\Conditionable;
5

6
class HigherOrderWhenProxy
7
{
8
    /**
9
     * The target being conditionally operated on.
10
     *
11
     * @var mixed
12
     */
13
    protected $target;
14

15
    /**
16
     * The condition for proxying.
17
     *
18
     * @var bool
19
     */
20
    protected $condition;
21

22
    /**
23
     * Indicates whether the proxy has a condition.
24
     *
25
     * @var bool
26
     */
27
    protected $hasCondition = false;
28

29
    /**
30
     * Determine whether the condition should be negated.
31
     *
32
     * @var bool
33
     */
34
    protected $negateConditionOnCapture;
35

36
    /**
37
     * Create a new proxy instance.
38
     *
39
     * @param mixed $target
40
     */
NEW
41
    public function __construct($target)
×
42
    {
NEW
43
        $this->target = $target;
×
44
    }
45

46
    /**
47
     * Proxy accessing an attribute onto the target.
48
     *
49
     * @param string $key
50
     * @return mixed
51
     */
NEW
52
    public function __get($key)
×
53
    {
NEW
54
        if (! $this->hasCondition) {
×
NEW
55
            $condition = $this->target->{$key};
×
56

NEW
57
            return $this->condition($this->negateConditionOnCapture ? ! $condition : $condition);
×
58
        }
59

NEW
60
        return $this->condition
×
NEW
61
            ? $this->target->{$key}
×
NEW
62
            : $this->target;
×
63
    }
64

65
    /**
66
     * Proxy a method call on the target.
67
     *
68
     * @param string $method
69
     * @param array $parameters
70
     * @return mixed
71
     */
NEW
72
    public function __call($method, $parameters)
×
73
    {
NEW
74
        if (! $this->hasCondition) {
×
NEW
75
            $condition = $this->target->{$method}(...$parameters);
×
76

NEW
77
            return $this->condition($this->negateConditionOnCapture ? ! $condition : $condition);
×
78
        }
79

NEW
80
        return $this->condition
×
NEW
81
            ? $this->target->{$method}(...$parameters)
×
NEW
82
            : $this->target;
×
83
    }
84

85
    /**
86
     * Set the condition on the proxy.
87
     *
88
     * @param bool $condition
89
     * @return $this
90
     */
NEW
91
    public function condition($condition)
×
92
    {
NEW
93
        [$this->condition, $this->hasCondition] = [$condition, true];
×
94

NEW
95
        return $this;
×
96
    }
97

98
    /**
99
     * Indicate that the condition should be negated.
100
     *
101
     * @return $this
102
     */
NEW
103
    public function negateConditionOnCapture()
×
104
    {
NEW
105
        $this->negateConditionOnCapture = true;
×
106

NEW
107
        return $this;
×
108
    }
109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc