Skip to content

Commit

Permalink
used PhpStorm Language attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 5, 2023
1 parent 0da02bc commit 4a21417
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"nette/di": "^v3.0",
"mockery/mockery": "^1.3.4",
"tracy/tracy": "^2.4",
"phpstan/phpstan-nette": "^0.12"
"phpstan/phpstan-nette": "^0.12",
"jetbrains/phpstorm-attributes": "^1.0"
},
"conflict": {
"nette/di": "<3.0-stable"
Expand Down
44 changes: 37 additions & 7 deletions src/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Nette\Database;

use JetBrains\PhpStorm\Language;
use Nette;
use Nette\Utils\Arrays;
use PDO;
Expand Down Expand Up @@ -226,7 +227,12 @@ public function transaction(callable $callback)
* Generates and executes SQL query.
* @param literal-string $sql
*/
public function query(string $sql, ...$params): ResultSet
public function query(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): ResultSet
{
[$this->sql, $params] = $this->preprocess($sql, ...$params);
try {
Expand Down Expand Up @@ -274,7 +280,12 @@ public function getLastQueryString(): ?string
* Shortcut for query()->fetch()
* @param literal-string $sql
*/
public function fetch(string $sql, ...$params): ?Row
public function fetch(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): ?Row
{
return $this->query($sql, ...$params)->fetch();
}
Expand All @@ -285,8 +296,12 @@ public function fetch(string $sql, ...$params): ?Row
* @param literal-string $sql
* @return mixed
*/
public function fetchField(string $sql, ...$params)
{
public function fetchField(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
) {
return $this->query($sql, ...$params)->fetchField();
}

Expand All @@ -295,7 +310,12 @@ public function fetchField(string $sql, ...$params)
* Shortcut for query()->fetchFields()
* @param literal-string $sql
*/
public function fetchFields(string $sql, ...$params): ?array
public function fetchFields(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): ?array
{
return $this->query($sql, ...$params)->fetchFields();
}
Expand All @@ -305,7 +325,12 @@ public function fetchFields(string $sql, ...$params): ?array
* Shortcut for query()->fetchPairs()
* @param literal-string $sql
*/
public function fetchPairs(string $sql, ...$params): array
public function fetchPairs(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): array
{
return $this->query($sql, ...$params)->fetchPairs();
}
Expand All @@ -315,7 +340,12 @@ public function fetchPairs(string $sql, ...$params): array
* Shortcut for query()->fetchAll()
* @param literal-string $sql
*/
public function fetchAll(string $sql, ...$params): array
public function fetchAll(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): array
{
return $this->query($sql, ...$params)->fetchAll();
}
Expand Down
44 changes: 37 additions & 7 deletions src/Database/Explorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Nette\Database;

use JetBrains\PhpStorm\Language;
use Nette;
use Nette\Database\Conventions\StaticConventions;

Expand Down Expand Up @@ -85,7 +86,12 @@ public function getInsertId(?string $sequence = null): string
* Generates and executes SQL query.
* @param literal-string $sql
*/
public function query(string $sql, ...$params): ResultSet
public function query(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): ResultSet
{
return $this->connection->query($sql, ...$params);
}
Expand Down Expand Up @@ -129,7 +135,12 @@ public function getConventions(): Conventions
* Shortcut for query()->fetch()
* @param literal-string $sql
*/
public function fetch(string $sql, ...$params): ?Row
public function fetch(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): ?Row
{
return $this->connection->query($sql, ...$params)->fetch();
}
Expand All @@ -140,8 +151,12 @@ public function fetch(string $sql, ...$params): ?Row
* @param literal-string $sql
* @return mixed
*/
public function fetchField(string $sql, ...$params)
{
public function fetchField(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
) {
return $this->connection->query($sql, ...$params)->fetchField();
}

Expand All @@ -150,7 +165,12 @@ public function fetchField(string $sql, ...$params)
* Shortcut for query()->fetchFields()
* @param literal-string $sql
*/
public function fetchFields(string $sql, ...$params): ?array
public function fetchFields(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): ?array
{
return $this->connection->query($sql, ...$params)->fetchFields();
}
Expand All @@ -160,7 +180,12 @@ public function fetchFields(string $sql, ...$params): ?array
* Shortcut for query()->fetchPairs()
* @param literal-string $sql
*/
public function fetchPairs(string $sql, ...$params): array
public function fetchPairs(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): array
{
return $this->connection->query($sql, ...$params)->fetchPairs();
}
Expand All @@ -170,7 +195,12 @@ public function fetchPairs(string $sql, ...$params): array
* Shortcut for query()->fetchAll()
* @param literal-string $sql
*/
public function fetchAll(string $sql, ...$params): array
public function fetchAll(
#[Language('SQL')]
string $sql,
#[Language('GenericSQL')]
...$params
): array
{
return $this->connection->query($sql, ...$params)->fetchAll();
}
Expand Down

0 comments on commit 4a21417

Please sign in to comment.