diff --git a/composer.json b/composer.json index 5a48cc345..6b67d8097 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/Database/Connection.php b/src/Database/Connection.php index aec7d909f..57a8ab530 100644 --- a/src/Database/Connection.php +++ b/src/Database/Connection.php @@ -9,6 +9,7 @@ namespace Nette\Database; +use JetBrains\PhpStorm\Language; use Nette; use Nette\Utils\Arrays; use PDO; @@ -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 { @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } diff --git a/src/Database/Explorer.php b/src/Database/Explorer.php index 0f8bdb530..8797af2ab 100644 --- a/src/Database/Explorer.php +++ b/src/Database/Explorer.php @@ -9,6 +9,7 @@ namespace Nette\Database; +use JetBrains\PhpStorm\Language; use Nette; use Nette\Database\Conventions\StaticConventions; @@ -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); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); } @@ -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(); }