Skip to content

Commit

Permalink
improved phpDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 24, 2021
1 parent 0b3b2f5 commit fb2476b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public function transaction(callable $callback)

/**
* Generates and executes SQL query.
* @param literal-string $sql
*/
public function query(string $sql, ...$params): ResultSet
{
Expand All @@ -240,7 +241,8 @@ public function queryArgs(string $sql, array $params): ResultSet


/**
* @return array [string, array]
* @param literal-string $sql
* @return array{string, array}
*/
public function preprocess(string $sql, ...$params): array
{
Expand All @@ -262,6 +264,7 @@ public function getLastQueryString(): ?string

/**
* Shortcut for query()->fetch()
* @param literal-string $sql
*/
public function fetch(string $sql, ...$params): ?Row
{
Expand All @@ -271,6 +274,7 @@ public function fetch(string $sql, ...$params): ?Row

/**
* Shortcut for query()->fetchField()
* @param literal-string $sql
* @return mixed
*/
public function fetchField(string $sql, ...$params)
Expand All @@ -281,6 +285,7 @@ public function fetchField(string $sql, ...$params)

/**
* Shortcut for query()->fetchFields()
* @param literal-string $sql
*/
public function fetchFields(string $sql, ...$params): ?array
{
Expand All @@ -290,6 +295,7 @@ public function fetchFields(string $sql, ...$params): ?array

/**
* Shortcut for query()->fetchPairs()
* @param literal-string $sql
*/
public function fetchPairs(string $sql, ...$params): array
{
Expand All @@ -299,6 +305,7 @@ public function fetchPairs(string $sql, ...$params): array

/**
* Shortcut for query()->fetchAll()
* @param literal-string $sql
*/
public function fetchAll(string $sql, ...$params): array
{
Expand Down
6 changes: 6 additions & 0 deletions src/Database/Explorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function getInsertId(string $sequence = null): string

/**
* Generates and executes SQL query.
* @param literal-string $sql
*/
public function query(string $sql, ...$params): ResultSet
{
Expand Down Expand Up @@ -126,6 +127,7 @@ public function getConventions(): Conventions

/**
* Shortcut for query()->fetch()
* @param literal-string $sql
*/
public function fetch(string $sql, ...$params): ?Row
{
Expand All @@ -135,6 +137,7 @@ public function fetch(string $sql, ...$params): ?Row

/**
* Shortcut for query()->fetchField()
* @param literal-string $sql
* @return mixed
*/
public function fetchField(string $sql, ...$params)
Expand All @@ -145,6 +148,7 @@ public function fetchField(string $sql, ...$params)

/**
* Shortcut for query()->fetchFields()
* @param literal-string $sql
*/
public function fetchFields(string $sql, ...$params): ?array
{
Expand All @@ -154,6 +158,7 @@ public function fetchFields(string $sql, ...$params): ?array

/**
* Shortcut for query()->fetchPairs()
* @param literal-string $sql
*/
public function fetchPairs(string $sql, ...$params): array
{
Expand All @@ -163,6 +168,7 @@ public function fetchPairs(string $sql, ...$params): array

/**
* Shortcut for query()->fetchAll()
* @param literal-string $sql
*/
public function fetchAll(string $sql, ...$params): array
{
Expand Down

2 comments on commit fb2476b

@podolinek
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi David,

what means literal-string? I didn't found any relevant info.

By phpstan check pass query("select * from table") but not query("select * from $this->table") .

@dg
Copy link
Member Author

@dg dg commented on fb2476b Nov 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the purpose that PHPStan pays attention to second variant. https://phpstan.org/writing-php-code/phpdoc-types#other-advanced-string-types

Use query("select * from ?name", $this->table)

Please sign in to comment.