Skip to content

Commit 71f427f

Browse files
committed
Split setConfig() into setConfig(), addConfig() and removeConfig()
1 parent 9afc090 commit 71f427f

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

src/JsonSchema/Constraints/Factory.php

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,46 @@ public function __construct(
8383
/**
8484
* Set config values
8585
*
86-
* @param int $checkMode Set checkMode options
87-
* @param bool $enable Whether to enable or disable the provided options. If null, overwrites checkMode.
86+
* @param int $checkMode Set checkMode options - does not preserve existing flags
8887
*/
89-
public function setConfig($checkMode = Constraint::CHECK_MODE_NORMAL, $enable = null)
88+
public function setConfig($checkMode = Constraint::CHECK_MODE_NORMAL)
9089
{
91-
if ($enable === null) {
92-
$this->checkMode = $checkMode;
93-
} elseif ($enable) {
94-
$this->checkMode |= $checkMode;
95-
} else {
96-
$this->checkMode &= ~$checkMode;
97-
}
90+
$this->checkMode = $checkMode;
91+
}
92+
93+
/**
94+
* Enable checkMode flags
95+
*
96+
* @param int $options
97+
*/
98+
public function addConfig($options)
99+
{
100+
$this->checkMode |= $options;
101+
}
102+
103+
/**
104+
* Disable checkMode flags
105+
*
106+
* @param int $options
107+
*/
108+
public function removeConfig($options)
109+
{
110+
$this->checkMode &= ~$options;
98111
}
99112

100113
/**
101114
* Get checkMode option
102115
*
103-
* @param int $checkMode Mode to get, if null then return entire bitmask
116+
* @param int $options Options to get, if null then return entire bitmask
104117
*
105118
* @return int
106119
*/
107-
public function getConfig($checkMode = null)
120+
public function getConfig($options = null)
108121
{
109-
if ($checkMode === null) {
122+
if ($options === null) {
110123
return $this->checkMode;
111124
}
112-
return ($this->checkMode & $checkMode);
125+
return ($this->checkMode & $options);
113126
}
114127

115128
/**

tests/Constraints/FactoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ public function testCheckMode()
126126
$this->assertEquals(Constraint::CHECK_MODE_COERCE_TYPES, $f->getConfig());
127127

128128
// test adding config
129-
$f->setConfig(Constraint::CHECK_MODE_NORMAL, true);
129+
$f->addConfig(Constraint::CHECK_MODE_NORMAL);
130130
$this->assertEquals(Constraint::CHECK_MODE_NORMAL | Constraint::CHECK_MODE_COERCE_TYPES, $f->getConfig());
131131

132132
// test getting filtered config
133133
$this->assertEquals(Constraint::CHECK_MODE_NORMAL, $f->getConfig(Constraint::CHECK_MODE_NORMAL));
134134

135135
// test removing config
136-
$f->setConfig(Constraint::CHECK_MODE_COERCE_TYPES, false);
136+
$f->removeConfig(Constraint::CHECK_MODE_COERCE_TYPES);
137137
$this->assertEquals(Constraint::CHECK_MODE_NORMAL, $f->getConfig());
138138

139139
// test resetting to defaults

0 commit comments

Comments
 (0)