Skip to content

Commit bbe82cf

Browse files
committed
More style updates.
1 parent 8b3f254 commit bbe82cf

23 files changed

+147
-150
lines changed

src/Context.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ public function offsetExists($name): bool
9191
public function offsetGet($name)
9292
{
9393
if (!$this->offsetExists($name)) {
94-
throw new \InvalidArgumentException(sprintf('Fact "%s" is not defined.', $name));
94+
throw new \InvalidArgumentException(\sprintf('Fact "%s" is not defined.', $name));
9595
}
9696

9797
$value = $this->values[$name];
9898

9999
// If the value is already frozen, or if it's not callable, or if it's protected, return the raw value
100-
if (isset($this->frozen[$name]) || !is_object($value) || $this->protected->contains($value) || !$this->isCallable($value)) {
100+
if (isset($this->frozen[$name]) || !\is_object($value) || $this->protected->contains($value) || !$this->isCallable($value)) {
101101
return $value;
102102
}
103103

@@ -127,7 +127,7 @@ public function offsetGet($name)
127127
public function offsetSet($name, $value): void
128128
{
129129
if (isset($this->frozen[$name])) {
130-
throw new \RuntimeException(sprintf('Cannot override frozen fact "%s".', $name));
130+
throw new \RuntimeException(\sprintf('Cannot override frozen fact "%s".', $name));
131131
}
132132

133133
$this->keys[$name] = true;
@@ -144,7 +144,7 @@ public function offsetUnset($name): void
144144
if ($this->offsetExists($name)) {
145145
$value = $this->values[$name];
146146

147-
if (is_object($value)) {
147+
if (\is_object($value)) {
148148
$this->shared->detach($value);
149149
$this->protected->detach($value);
150150
}
@@ -209,7 +209,7 @@ public function protect($callable)
209209
public function raw($name)
210210
{
211211
if (!$this->offsetExists($name)) {
212-
throw new \InvalidArgumentException(sprintf('Fact "%s" is not defined.', $name));
212+
throw new \InvalidArgumentException(\sprintf('Fact "%s" is not defined.', $name));
213213
}
214214

215215
if (isset($this->frozen[$name])) {
@@ -226,7 +226,7 @@ public function raw($name)
226226
*/
227227
public function keys()
228228
{
229-
return array_keys($this->keys);
229+
return \array_keys($this->keys);
230230
}
231231

232232
/**
@@ -238,6 +238,6 @@ public function keys()
238238
*/
239239
protected function isCallable($callable)
240240
{
241-
return is_object($callable) && is_callable($callable);
241+
return \is_object($callable) && \is_callable($callable);
242242
}
243243
}

src/Operator.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ public function getOperands()
3636
{
3737
switch ($this->getOperandCardinality()) {
3838
case self::UNARY:
39-
if (1 != count($this->operands)) {
40-
throw new \LogicException(get_class($this).' takes only 1 operand');
39+
if (1 !== \count($this->operands)) {
40+
throw new \LogicException(static::class.' takes only 1 operand');
4141
}
4242
break;
4343
case self::BINARY:
44-
if (2 != count($this->operands)) {
45-
throw new \LogicException(get_class($this).' takes 2 operands');
44+
if (2 !== \count($this->operands)) {
45+
throw new \LogicException(static::class.' takes 2 operands');
4646
}
4747
break;
4848
case self::MULTIPLE:
49-
if (0 == count($this->operands)) {
50-
throw new \LogicException(get_class($this).' takes at least 1 operand');
49+
if (0 === \count($this->operands)) {
50+
throw new \LogicException(static::class.' takes at least 1 operand');
5151
}
5252
break;
5353
}

src/Operator/PropositionOperator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public function addOperand($operand)
2626

2727
public function addProposition(Proposition $operand)
2828
{
29-
if (static::UNARY == $this->getOperandCardinality()
30-
&& 0 < count($this->operands)
29+
if (static::UNARY === $this->getOperandCardinality()
30+
&& 0 < \count($this->operands)
3131
) {
32-
throw new \LogicException(get_class($this).' can only have 1 operand');
32+
throw new \LogicException(static::class.' can only have 1 operand');
3333
}
3434
$this->operands[] = $operand;
3535
}

src/Operator/VariableOperator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public function addOperand($operand)
2626

2727
public function addVariable(VariableOperand $operand)
2828
{
29-
if (static::UNARY == $this->getOperandCardinality()
30-
&& 0 < count($this->operands)
29+
if (static::UNARY === $this->getOperandCardinality()
30+
&& 0 < \count($this->operands)
3131
) {
32-
throw new \LogicException(get_class($this).' can only have 1 operand');
32+
throw new \LogicException(static::class.' can only have 1 operand');
3333
}
3434
$this->operands[] = $operand;
3535
}

src/Rule.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public function evaluate(Context $context)
6161
public function execute(Context $context)
6262
{
6363
if ($this->evaluate($context) && isset($this->action)) {
64-
if (!is_callable($this->action)) {
64+
if (!\is_callable($this->action)) {
6565
throw new \LogicException('Rule actions must be callable.');
6666
}
6767

68-
call_user_func($this->action);
68+
\call_user_func($this->action);
6969
}
7070
}
7171
}

src/RuleBuilder.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function create(Proposition $condition, $action = null)
4242
*
4343
* Note that, depending on your filesystem, operator namespaces are most likely case sensitive.
4444
*
45-
*
4645
* @param string $namespace Operator namespace
4746
*
4847
* @throws \InvalidArgumentException
@@ -51,7 +50,7 @@ public function create(Proposition $condition, $action = null)
5150
*/
5251
public function registerOperatorNamespace($namespace)
5352
{
54-
if (!is_string($namespace)) {
53+
if (!\is_string($namespace)) {
5554
throw new \InvalidArgumentException('Namespace argument must be a string');
5655
}
5756

@@ -70,7 +69,7 @@ public function registerOperatorNamespace($namespace)
7069
*/
7170
public function logicalAnd(Proposition $prop, Proposition $prop2 = null)
7271
{
73-
return new Operator\LogicalAnd(func_get_args());
72+
return new Operator\LogicalAnd(\func_get_args());
7473
}
7574

7675
/**
@@ -83,7 +82,7 @@ public function logicalAnd(Proposition $prop, Proposition $prop2 = null)
8382
*/
8483
public function logicalOr(Proposition $prop, Proposition $prop2 = null)
8584
{
86-
return new Operator\LogicalOr(func_get_args());
85+
return new Operator\LogicalOr(\func_get_args());
8786
}
8887

8988
/**
@@ -108,7 +107,7 @@ public function logicalNot(Proposition $prop)
108107
*/
109108
public function logicalXor(Proposition $prop, Proposition $prop2 = null)
110109
{
111-
return new Operator\LogicalXor(func_get_args());
110+
return new Operator\LogicalXor(\func_get_args());
112111
}
113112

114113
/**
@@ -163,23 +162,22 @@ public function offsetUnset($name): void
163162
/**
164163
* Find an operator in the registered operator namespaces.
165164
*
166-
*
167165
* @param string $name
168166
*
169-
* @throws \LogicException If a matching operator is not found.
167+
* @throws \LogicException if a matching operator is not found
170168
*
171169
* @return string
172170
*/
173171
public function findOperator($name)
174172
{
175-
$operator = ucfirst($name);
176-
foreach (array_keys($this->operatorNamespaces) as $namespace) {
173+
$operator = \ucfirst($name);
174+
foreach (\array_keys($this->operatorNamespaces) as $namespace) {
177175
$class = $namespace.'\\'.$operator;
178-
if (class_exists($class)) {
176+
if (\class_exists($class)) {
179177
return $class;
180178
}
181179
}
182180

183-
throw new \LogicException(sprintf('Unknown operator: "%s"', $name));
181+
throw new \LogicException(\sprintf('Unknown operator: "%s"', $name));
184182
}
185183
}

src/RuleBuilder/Variable.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function notSameAs($variable)
264264
*/
265265
public function union($variable)
266266
{
267-
return $this->applySetOperator('Union', func_get_args());
267+
return $this->applySetOperator('Union', \func_get_args());
268268
}
269269

270270
/**
@@ -274,7 +274,7 @@ public function union($variable)
274274
*/
275275
public function intersect($variable)
276276
{
277-
return $this->applySetOperator('Intersect', func_get_args());
277+
return $this->applySetOperator('Intersect', \func_get_args());
278278
}
279279

280280
/**
@@ -284,7 +284,7 @@ public function intersect($variable)
284284
*/
285285
public function complement($variable)
286286
{
287-
return $this->applySetOperator('Complement', func_get_args());
287+
return $this->applySetOperator('Complement', \func_get_args());
288288
}
289289

290290
/**
@@ -294,7 +294,7 @@ public function complement($variable)
294294
*/
295295
public function symmetricDifference($variable)
296296
{
297-
return $this->applySetOperator('SymmetricDifference', func_get_args());
297+
return $this->applySetOperator('SymmetricDifference', \func_get_args());
298298
}
299299

300300
/**
@@ -464,7 +464,7 @@ private function asVariable($variable)
464464
private function applySetOperator($name, array $args)
465465
{
466466
$reflection = new \ReflectionClass('\\Ruler\\Operator\\'.$name);
467-
array_unshift($args, $this);
467+
\array_unshift($args, $this);
468468

469469
return $this->wrap($reflection->newInstanceArgs($args));
470470
}
@@ -537,15 +537,15 @@ public function startsWithInsensitive($variable)
537537
* @param string $name
538538
* @param array $args
539539
*
540-
* @throws \LogicException if operator is not registered.
540+
* @throws \LogicException if operator is not registered
541541
*
542542
* @return Operator|self
543543
*/
544544
public function __call($name, array $args)
545545
{
546546
$reflection = new \ReflectionClass($this->ruleBuilder->findOperator($name));
547-
$args = array_map([$this, 'asVariable'], $args);
548-
array_unshift($args, $this);
547+
$args = \array_map([$this, 'asVariable'], $args);
548+
\array_unshift($args, $this);
549549

550550
$op = $reflection->newInstanceArgs($args);
551551

src/RuleBuilder/VariableProperty.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ public function prepareValue(Context $context)
8080
$name = $this->getName();
8181
$value = $this->parent->prepareValue($context)->getValue();
8282

83-
if (is_object($value) && !$value instanceof \Closure) {
84-
if (method_exists($value, $name)) {
85-
return $this->asValue(call_user_func([$value, $name]));
83+
if (\is_object($value) && !$value instanceof \Closure) {
84+
if (\method_exists($value, $name)) {
85+
return $this->asValue(\call_user_func([$value, $name]));
8686
} elseif (isset($value->$name)) {
8787
return $this->asValue($value->$name);
8888
} elseif ($value instanceof \ArrayAccess && $value->offsetExists($name)) {
8989
return $this->asValue($value->offsetGet($name));
9090
}
91-
} elseif (is_array($value) && array_key_exists($name, $value)) {
91+
} elseif (\is_array($value) && \array_key_exists($name, $value)) {
9292
return $this->asValue($value[$name]);
9393
}
9494

src/RuleBuilder/VariablePropertyTrait.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ public function prepareValue(Context $context)
7676
$name = $this->getName();
7777
$value = $this->parent->prepareValue($context)->getValue();
7878

79-
if (is_object($value) && !$value instanceof \Closure) {
80-
if (method_exists($value, $name)) {
81-
return $this->asValue(call_user_func([$value, $name]));
79+
if (\is_object($value) && !$value instanceof \Closure) {
80+
if (\method_exists($value, $name)) {
81+
return $this->asValue(\call_user_func([$value, $name]));
8282
} elseif (isset($value->$name)) {
8383
return $this->asValue($value->$name);
8484
} elseif ($value instanceof \ArrayAccess && $value->offsetExists($name)) {
8585
return $this->asValue($value->offsetGet($name));
8686
}
87-
} elseif (is_array($value) && array_key_exists($name, $value)) {
87+
} elseif (\is_array($value) && \array_key_exists($name, $value)) {
8888
return $this->asValue($value[$name]);
8989
}
9090

src/RuleSet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(array $rules = [])
4141
*/
4242
public function addRule(Rule $rule)
4343
{
44-
$this->rules[spl_object_hash($rule)] = $rule;
44+
$this->rules[\spl_object_hash($rule)] = $rule;
4545
}
4646

4747
/**

0 commit comments

Comments
 (0)