Skip to content

Commit 63741eb

Browse files
committed
refactor(core): rename sqls to queries for clarity and consistency
- Rename parameter names from `sqls` to `queries` in method signatures and docblocks in `Soar.php` and `ConcreteScores.php` - Update variable names in `README.md` and test files to use `queries` instead of `sqls` - Improve code readability and semantic clarity by using a more descriptive term for SQL statements - Ensure consistent naming across codebase and documentation to reduce confusion Signed-off-by: guanguans <ityaozm@gmail.com>
1 parent a1f761e commit 63741eb

File tree

7 files changed

+81
-83
lines changed

7 files changed

+81
-83
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ require __DIR__.'/vendor/autoload.php';
4949

5050
use Guanguans\SoarPHP\Soar;
5151

52-
$sqls = [
53-
<<<'SQL'
52+
$queries = [
53+
<<<'QUERY'
5454
SELECT
5555
DATE_FORMAT (t.last_update, '%Y-%m-%d'),
5656
COUNT(DISTINCT (t.city))
@@ -64,14 +64,14 @@ $sqls = [
6464
DATE_FORMAT(t.last_update, '%Y-%m-%d')
6565
ORDER BY
6666
DATE_FORMAT(t.last_update, '%Y-%m-%d');
67-
SQL,
67+
QUERY,
6868
'SELECT * FROM `foo`;',
6969
];
7070

7171
/**
7272
* Examples of scoring.
7373
*/
74-
$scores = Soar::make()->arrayScores($sqls); // Basic scoring
74+
$scores = Soar::make()->arrayScores($queries); // Basic scoring
7575

7676
$scores = Soar::make() // Advanced scoring
7777
->withTestDsn([
@@ -94,16 +94,16 @@ $scores = Soar::make() // Advanced scoring
9494
])
9595
->withExplain(true) // Enable EXPLAIN
9696
->withAllowOnlineAsTest(true) // Enable index suggestions
97-
->arrayScores($sqls);
97+
->arrayScores($queries);
9898

9999
/**
100100
* Examples of running any soar command.
101101
*/
102102
// Final run: '/.../bin/soar.darwin-arm64' '-report-type=fingerprint' '-query=SELECT * FROM `foo`;'
103-
$fingerprint = Soar::make()->withReportType('fingerprint')->withQuery($sqls[1])->dump()->run();
103+
$fingerprint = Soar::make()->withReportType('fingerprint')->withQuery($queries[1])->dump()->run();
104104

105105
// Final run: '/.../bin/soar.darwin-arm64' '-report-type=pretty' '-query=SELECT * FROM `foo`;'
106-
$pretty = Soar::make()->withReportType('pretty')->withQuery($sqls[1])->dump()->run();
106+
$pretty = Soar::make()->withReportType('pretty')->withQuery($queries[1])->dump()->run();
107107

108108
// Final run: '/.../bin/soar.darwin-arm64' '-version=true'
109109
$version = Soar::make()->withHelp(true)->setVersion(true)->dump()->run();
@@ -117,7 +117,7 @@ $syntaxCheck = Soar::make()->withOnlySyntaxCheck(true)->withQuery('SELECT * FRO
117117
<summary><b>SQL Scores(Fingerprint、Score、Explain、Heuristic suggestions、Index suggestions)</b></summary>
118118

119119
```php
120-
$sqls = <<<'sql'
120+
$queries = <<<'QUERIES'
121121
SELECT * FROM users;
122122
SELECT DATE_FORMAT (t.last_update,'%Y-%m-%d'),COUNT (DISTINCT (t.city)) FROM city t WHERE t.last_update> '2018-10-22 00:00:00' AND t.city LIKE '%Chrome%' AND t.city='eip' GROUP BY DATE_FORMAT(t.last_update,'%Y-%m-%d') ORDER BY DATE_FORMAT(t.last_update,'%Y-%m-%d');
123123
DELETE city FROM city LEFT JOIN country ON city.country_id=country.country_id WHERE country.country IS NULL;
@@ -138,13 +138,13 @@ CREATE TABLE `users` (
138138
PRIMARY KEY (`id`),
139139
UNIQUE KEY `users_email_unique` (`email`)
140140
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
141-
sql;
141+
QUERIES;
142142

143-
$soar->scores($sqls);
144-
$soar->htmlScores($sqls);
145-
$soar->markdownScores($sqls);
146-
$soar->arrayScores($sqls);
147-
$soar->jsonScores($sqls);
143+
$soar->scores($queries);
144+
$soar->htmlScores($queries);
145+
$soar->markdownScores($queries);
146+
$soar->arrayScores($queries);
147+
$soar->jsonScores($queries);
148148
```
149149

150150
```php

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
{
2424
"name": "guanguans",
2525
"email": "ityaozm@gmail.com",
26-
"homepage": "https://www.guanguans.cn",
26+
"homepage": "https://github.com/guanguans",
2727
"role": "developer"
2828
}
2929
],
30-
"homepage": "https://github.com/guanguans/laravel-exception-notify",
30+
"homepage": "https://github.com/guanguans/soar-php",
3131
"support": {
3232
"issues": "https://github.com/guanguans/soar-php/issues",
33-
"source": "https://github.com/guanguans/soar-php"
33+
"discussions": "https://github.com/guanguans/soar-php/discussions"
3434
},
3535
"funding": [
3636
{
3737
"type": "sponsors",
38-
"url": "https://www.guanguans.cn/sponsors"
38+
"url": "https://guanguans.github.io/sponsors"
3939
}
4040
],
4141
"require": {

src/Concerns/ConcreteScores.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
trait ConcreteScores
2020
{
2121
/**
22-
* @param list<string>|string $sqls
22+
* @param list<string>|string $queries
2323
* @param int<1, 512> $depth
2424
* @param int<0, 4194304> $options
2525
*
@@ -28,54 +28,52 @@ trait ConcreteScores
2828
*
2929
* @return list<array<string, mixed>>
3030
*/
31-
public function arrayScores(array|string $sqls, int $depth = 512, int $options = 0): array
31+
public function arrayScores(array|string $queries, int $depth = 512, int $options = 0): array
3232
{
33-
return json_decode($this->jsonScores($sqls), true, $depth, $options | \JSON_THROW_ON_ERROR);
33+
return json_decode($this->jsonScores($queries), true, $depth, $options | \JSON_THROW_ON_ERROR);
3434
}
3535

3636
/**
37-
* @param list<string>|string $sqls
37+
* @param list<string>|string $queries
3838
*
3939
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
4040
*/
41-
public function jsonScores(array|string $sqls): string
41+
public function jsonScores(array|string $queries): string
4242
{
43-
return $this->withReportType('json')->scores($sqls);
43+
return $this->withReportType('json')->scores($queries);
4444
}
4545

4646
/**
47-
* @param list<string>|string $sqls
47+
* @param list<string>|string $queries
4848
*
4949
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
5050
*/
51-
public function htmlScores(array|string $sqls): string
51+
public function htmlScores(array|string $queries): string
5252
{
53-
return $this->withReportType('html')->scores($sqls);
53+
return $this->withReportType('html')->scores($queries);
5454
}
5555

5656
/**
57-
* @param list<string>|string $sqls
57+
* @param list<string>|string $queries
5858
*
5959
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
6060
*/
61-
public function markdownScores(array|string $sqls): string
61+
public function markdownScores(array|string $queries): string
6262
{
63-
return $this->withReportType('markdown')->scores($sqls);
63+
return $this->withReportType('markdown')->scores($queries);
6464
}
6565

6666
/**
67-
* @todo $sqls -> $queries
68-
*
69-
* @param list<string>|string $sqls
67+
* @param list<string>|string $queries
7068
*
7169
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
7270
*/
73-
public function scores(array|string $sqls, ?callable $callback = null): string
71+
public function scores(array|string $queries, ?callable $callback = null): string
7472
{
75-
if (\is_array($sqls)) {
76-
$sqls = implode($this->getDelimiter(';'), $sqls);
73+
if (\is_array($queries)) {
74+
$queries = implode($this->getDelimiter(';'), $queries);
7775
}
7876

79-
return $this->clone()->withQuery($sqls)->run($callback);
77+
return $this->clone()->withQuery($queries)->run($callback);
8078
}
8179
}

src/Contracts/Soar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ interface Soar
2121
public function run(?callable $callback = null): string;
2222

2323
/**
24-
* @param list<string>|string $sqls
24+
* @param list<string>|string $queries
2525
* @param null|callable(string, string): void $callback
2626
*/
27-
public function scores(array|string $sqls, ?callable $callback = null): string;
27+
public function scores(array|string $queries, ?callable $callback = null): string;
2828

2929
/**
3030
* @param null|callable(string, string): void $callback

tests/Concerns/ConcreteScoresTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@
2929
use function Spatie\Snapshots\assertMatchesTextSnapshot;
3030

3131
it('can get array scores', function (): void {
32-
$sqls = [
33-
<<<'SQLS'
32+
$queries = [
33+
<<<'QUERY'
3434
SELECT * FROM `post` WHERE `name`='so"a`r';
35-
SQLS,
36-
<<<'SQLS'
35+
QUERY,
36+
<<<'QUERY'
3737
SELECT DATE_FORMAT(t.last_update,'%Y-%m-%d'), COUNT(DISTINCT(t.city)) FROM city t WHERE t.last_update> '2018-10-22 00:00:00' AND t.city LIKE '%Chrome%' AND t.city='eip' GROUP BY DATE_FORMAT(t.last_update,'%Y-%m-%d') ORDER BY DATE_FORMAT(t.last_update,'%Y-%m-%d');
38-
SQLS,
39-
<<<'SQLS'
38+
QUERY,
39+
<<<'QUERY'
4040
DELETE city FROM city LEFT JOIN country ON city.country_id=country.country_id WHERE country.country IS NULL;
41-
SQLS,
42-
<<<'SQLS'
41+
QUERY,
42+
<<<'QUERY'
4343
UPDATE city INNER JOIN country ON city.country_id=country.country_id INNER JOIN address ON city.city_id=address.city_id SET city.city='Abha',city.last_update='2006-02-15 04:45:25',country.country='Afghanistan' WHERE city.city_id=10;
44-
SQLS,
45-
<<<'SQLS'
44+
QUERY,
45+
<<<'QUERY'
4646
INSERT INTO city (country_id) SELECT country_id FROM country;
47-
SQLS,
48-
<<<'SQLS'
47+
QUERY,
48+
<<<'QUERY'
4949
REPLACE INTO city (country_id) SELECT country_id FROM country;
50-
SQLS,
51-
<<<'SQLS'
50+
QUERY,
51+
<<<'QUERY'
5252
ALTER TABLE inventory ADD INDEX `idx_store_film` (`store_id`,`film_id`),ADD INDEX `idx_store_film` (`store_id`,`film_id`),ADD INDEX `idx_store_film` (`store_id`,`film_id`);
53-
SQLS,
54-
<<<'SQLS'
53+
QUERY,
54+
<<<'QUERY'
5555
DROP TABLE `users`;
56-
SQLS,
57-
<<<'SQLS'
56+
QUERY,
57+
<<<'QUERY'
5858
CREATE TABLE `users` (
5959
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
6060
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -67,13 +67,13 @@
6767
PRIMARY KEY (`id`),
6868
UNIQUE KEY `users_email_unique` (`email`)
6969
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
70-
SQLS,
70+
QUERY,
7171
];
7272

7373
expect(Soar::make())
7474
// ->withOptions(soar_options())
7575
->withOptions(soar_options_example())
76-
->arrayScores($sqls)
76+
->arrayScores($queries)
7777
->toBeArray()
7878
->toBeTruthy()
7979
->when(OS::isWindows(), function (Expectation $expectation): void {

tests/Concerns/WithRunableTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
use Symfony\Component\Process\Exception\ProcessFailedException;
2626
use Symfony\Component\Process\Process;
2727

28-
it('will throw ProcessFailedException when is a invalid sql', function (): void {
29-
Soar::make()->withOnlySyntaxCheck(true)->withQuery('invalid sql')->run();
30-
})->group(__DIR__, __FILE__)->throws(ProcessFailedException::class, 'invalid sql');
28+
it('will throw ProcessFailedException when is a invalid query', function (): void {
29+
Soar::make()->withOnlySyntaxCheck(true)->withQuery('invalid query')->run();
30+
})->group(__DIR__, __FILE__)->throws(ProcessFailedException::class, 'invalid query');
3131

3232
it('will throw ProcessFailedException when sudo password is error', function (): void {
3333
foreach (
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
namespace Guanguans\PackageSkeletonTests\Datasets;
2323

24-
dataset('SQL statements', [
24+
dataset('queries', [
2525
[
26-
<<<'SQLS'
26+
<<<'QUERIES'
2727
SELECT * FROM `post` WHERE `name`='so"a`r';
2828
SELECT DATE_FORMAT(t.last_update,'%Y-%m-%d'), COUNT(DISTINCT(t.city)) FROM city t WHERE t.last_update> '2018-10-22 00:00:00' AND t.city LIKE '%Chrome%' AND t.city='eip' GROUP BY DATE_FORMAT(t.last_update,'%Y-%m-%d') ORDER BY DATE_FORMAT(t.last_update,'%Y-%m-%d');
2929
@@ -51,35 +51,35 @@
5151
PRIMARY KEY (`id`),
5252
UNIQUE KEY `users_email_unique` (`email`)
5353
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
54-
SQLS,
54+
QUERIES,
5555
],
5656
[
5757
[
58-
// <<<'SQLS'
58+
// <<<'QUERY'
5959
// SELECT * FROM `post` WHERE `name`='so"a`r';
60-
// SQLS,
61-
// <<<'SQLS'
60+
// QUERY,
61+
// <<<'QUERY'
6262
// SELECT DATE_FORMAT(t.last_update,'%Y-%m-%d'), COUNT(DISTINCT(t.city)) FROM city t WHERE t.last_update> '2018-10-22 00:00:00' AND t.city LIKE '%Chrome%' AND t.city='eip' GROUP BY DATE_FORMAT(t.last_update,'%Y-%m-%d') ORDER BY DATE_FORMAT(t.last_update,'%Y-%m-%d');
63-
// SQLS,
64-
// <<<'SQLS'
63+
// QUERY,
64+
// <<<'QUERY'
6565
// DELETE city FROM city LEFT JOIN country ON city.country_id=country.country_id WHERE country.country IS NULL;
66-
// SQLS,
67-
// <<<'SQLS'
66+
// QUERY,
67+
// <<<'QUERY'
6868
// UPDATE city INNER JOIN country ON city.country_id=country.country_id INNER JOIN address ON city.city_id=address.city_id SET city.city='Abha',city.last_update='2006-02-15 04:45:25',country.country='Afghanistan' WHERE city.city_id=10;
69-
// SQLS,
70-
<<<'SQLS'
69+
// QUERY,
70+
<<<'QUERY'
7171
INSERT INTO city (country_id) SELECT country_id FROM country;
72-
SQLS,
73-
<<<'SQLS'
72+
QUERY,
73+
<<<'QUERY'
7474
REPLACE INTO city (country_id) SELECT country_id FROM country;
75-
SQLS,
76-
<<<'SQLS'
75+
QUERY,
76+
<<<'QUERY'
7777
ALTER TABLE inventory ADD INDEX `idx_store_film` (`store_id`,`film_id`),ADD INDEX `idx_store_film` (`store_id`,`film_id`),ADD INDEX `idx_store_film` (`store_id`,`film_id`);
78-
SQLS,
79-
<<<'SQLS'
78+
QUERY,
79+
<<<'QUERY'
8080
DROP TABLE `users`;
81-
SQLS,
82-
<<<'SQLS'
81+
QUERY,
82+
<<<'QUERY'
8383
CREATE TABLE `users` (
8484
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
8585
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
@@ -92,7 +92,7 @@
9292
PRIMARY KEY (`id`),
9393
UNIQUE KEY `users_email_unique` (`email`)
9494
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
95-
SQLS,
95+
QUERY,
9696
],
9797
],
9898
]);

0 commit comments

Comments
 (0)