Skip to content

Commit fc16382

Browse files
committed
Replace {ArrayHasKeyWith,ArrayHasItemWith}::evaluate() by self::matches()
1 parent eaa3206 commit fc16382

2 files changed

Lines changed: 14 additions & 22 deletions

File tree

‎src/Constraint/ArrayHasItemWith.php‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,22 @@ public function toString(): string
6868
/**
6969
* {@inheritDoc}
7070
*/
71-
public function evaluate($other, string $description = '', bool $returnResult = false)
71+
protected function matches($other): bool
7272
{
73-
$success = false;
73+
$valueExists = false;
7474
if (is_array($other)) {
7575
$other = array_values($other);
76-
$success = isset($other[$this->index]);
76+
$valueExists = isset($other[$this->index]);
7777
} elseif ($other instanceof Traversable) {
7878
$other = iterator_to_array($other, false);
79-
$success = isset($other[$this->index]);
79+
$valueExists = isset($other[$this->index]);
8080
}
8181

82-
if (!$success) {
83-
if ($returnResult) {
84-
return false;
85-
}
86-
87-
$this->fail($other, $description);
82+
if (!$valueExists) {
83+
return false;
8884
}
8985

90-
return $this->constraint->evaluate($other[$this->index], $description, $returnResult);
86+
return $this->constraint->evaluate($other[$this->index], '', true);
9187
}
9288

9389
/**

‎src/Constraint/ArrayHasKeyWith.php‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,20 @@ public function toString(): string
6464
/**
6565
* {@inheritDoc}
6666
*/
67-
public function evaluate($other, string $description = '', bool $returnResult = false)
67+
protected function matches($other): bool
6868
{
69-
$success = false;
69+
$valueExists = false;
7070
if (is_array($other)) {
71-
$success = array_key_exists($this->key, $other);
71+
$valueExists = array_key_exists($this->key, $other);
7272
} elseif ($other instanceof ArrayAccess) {
73-
$success = $other->offsetExists($this->key);
73+
$valueExists = $other->offsetExists($this->key);
7474
}
7575

76-
if (!$success) {
77-
if ($returnResult) {
78-
return false;
79-
}
80-
81-
$this->fail($other, $description);
76+
if (!$valueExists) {
77+
return false;
8278
}
8379

84-
return $this->constraint->evaluate($other[$this->key], $description, $returnResult);
80+
return $this->constraint->evaluate($other[$this->key], '', true);
8581
}
8682

8783
/**

0 commit comments

Comments
 (0)