Skip to content

Commit 7fd55a4

Browse files
authored
simplify count (#110)
1 parent d135bd1 commit 7fd55a4

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"keywords": ["activerecord", "orm"],
66
"homepage": "http://www.phpactiverecord.org/",
77
"license": "MIT",
8-
"version": "2.0.0-rc.7",
8+
"version": "2.0.0-rc.8",
99
"require": {
1010
"php": ">=8.1.0",
1111
"ext-bcmath": "*"

lib/WhereClause.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ public function to_s(Connection $connection, string $prependTableName = '', arra
8888
}
8989

9090
$ret = '';
91-
if (1 == count($values) && is_array($values[0])) {
92-
$num_values = count($values[0]);
93-
} else {
94-
$num_values = count($values);
95-
}
91+
$num_values = count($values);
9692
$quotes = 0;
9793

94+
if (1 == $num_values && is_array($values[0]) && 0 == count($values[0])) {
95+
return '1=0';
96+
}
97+
9898
for ($i = 0, $j = 0; $i < strlen($expression); ++$i) {
9999
$ch = $expression[$i];
100100

test/ActiveRecordFindTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
use ActiveRecord\Exception\DatabaseException;
43
use ActiveRecord\Exception\RecordNotFound;
54
use ActiveRecord\Exception\ValidationsArgumentError;
65
use ActiveRecord\Model;
@@ -17,6 +16,12 @@ public function testFindWithNoParams()
1716
Author::find();
1817
}
1918

19+
public function testWhereWithEmptyArray()
20+
{
21+
$authors = Author::where(['author_id' => []])->to_a();
22+
$this->assertEquals(0, count($authors));
23+
}
24+
2025
public function testFindWithEmptyArray()
2126
{
2227
$this->expectException(RecordNotFound::class);
@@ -166,13 +171,6 @@ public function testFindAllWithNoBindValues()
166171
$this->assertEquals(1, $authors[0]->author_id);
167172
}
168173

169-
public function testFindAllWithEmptyArrayBindValueThrowsException()
170-
{
171-
$this->expectException(DatabaseException::class);
172-
$this->expectExceptionMessage('No bound parameter for index 0');
173-
Author::where(['author_id IN(?)', []])->to_a();
174-
}
175-
176174
public function testFindHashUsingAlias()
177175
{
178176
$venues = Venue::where(['marquee' => 'Warner Theatre', 'city' => [

test/WhereClauseTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use ActiveRecord\ConnectionManager;
44
use ActiveRecord\Exception\DatabaseException;
55
use ActiveRecord\WhereClause;
6-
use test\models\Author;
76

87
class WhereClauseTest extends DatabaseTestCase
98
{
@@ -135,12 +134,6 @@ public function testSubstituteEscapeQuotesWithConnectionsEscapeMethod(): void
135134
$this->assertEquals("name=$escaped", $a->to_s(ConnectionManager::get_connection(), substitute: true));
136135
}
137136

138-
public function testBindInvalidParameterNumberArrayWithIn()
139-
{
140-
$this->expectException(DatabaseException::class);
141-
Author::where(['author_id IN(?)', []])->to_a();
142-
}
143-
144137
public function testSubstituteUsingAlternateValues(): void
145138
{
146139
$a = new WhereClause('name=?', ['Tito']);

0 commit comments

Comments
 (0)