Skip to content

Commit

Permalink
phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Cesarano authored and Davide Cesarano committed Oct 24, 2020
1 parent 03491e1 commit 26736c2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Embryo/PDO/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class Connection
{
/**
* @var PDO $pdo
* @var \PDO $pdo
*/
private $pdo;

Expand Down Expand Up @@ -56,9 +56,9 @@ public function query(string $query): Query
/**
* Transaction
*
* @param Closure $callback
* @param \Closure $callback
* @return mixed
* @throws PDOException
* @throws \PDOException
*/
public function transaction(\Closure $callback)
{
Expand Down
4 changes: 2 additions & 2 deletions Embryo/PDO/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function __construct(array $database)
*
* @param string $connectionName
* @return Connection
* @throws InvalidArgumentException
* @throws PDOException
* @throws \InvalidArgumentException
* @throws \PDOException
*/
public function connection(string $connectionName = 'local'): Connection
{
Expand Down
18 changes: 10 additions & 8 deletions Embryo/PDO/QueryBuilder/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Query
private $query;

/**
* @var \PDOStatement|bool $stmt
* @var \PDOStatement $stmt
*/
private $stmt;

Expand All @@ -41,7 +41,7 @@ class Query
/**
* @var int $lastInsertId
*/
private $lastInsertId = [];
private $lastInsertId;

/**
* Set PDO.
Expand Down Expand Up @@ -71,6 +71,7 @@ public function query(string $query): self
*
* @param array $values
* @return self
* @throws \PDOException
*/
public function values(array $values): self
{
Expand All @@ -94,13 +95,13 @@ public function values(array $values): self
* or emit PDO exception.
*
* @return void
* @throws PDOException
* @throws \PDOException
*/
public function execute()
{
try {
$this->execute = $this->stmt->execute();
$this->lastInsertId = $this->pdo->lastInsertId();
$this->lastInsertId = (int) $this->pdo->lastInsertId();
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage());
}
Expand Down Expand Up @@ -138,15 +139,15 @@ public function lastId(): int
public function count(): int
{
$this->execute();
return $this->stmt->rowCount();
return (int) $this->stmt->rowCount();
}

/**
* Execute and return an
* object row or an array of
* objects.
*
* @return object|array
* @return object|array|bool
*/
public function get()
{
Expand All @@ -166,7 +167,8 @@ public function get()
public function all(): array
{
$this->execute();
return $this->stmt->fetchAll(\PDO::FETCH_OBJ);
$data = $this->stmt->fetchAll(\PDO::FETCH_OBJ);
return $data ?: [];
}

/**
Expand All @@ -178,7 +180,7 @@ public function debug(): string
{
ob_start();
$this->stmt->debugDumpParams();
$output = ob_get_contents();
$output = ob_get_contents() ?: '';
ob_end_clean();
return '<pre>'.htmlspecialchars($output).'</pre>';
}
Expand Down
22 changes: 11 additions & 11 deletions Embryo/PDO/QueryBuilder/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class QueryBuilder
use ComposeQueryTrait;

/**
* @var PDO $pdo
* @var \PDO $pdo
*/
private $pdo;

Expand Down Expand Up @@ -51,7 +51,7 @@ class QueryBuilder
private $delete = false;

/**
* @var array $leftJoin
* @var array $join
*/
private $join = [];

Expand Down Expand Up @@ -184,7 +184,7 @@ public function select(...$field): Query
/**
* SELECT statement shortened.
*
* @return object|array
* @return object|array|bool
*/
public function get()
{
Expand Down Expand Up @@ -371,7 +371,7 @@ public function rawJoin(string $join): self
/**
* "WHERE" and "AND" condition.
*
* @param string|callback $field
* @param string|callable $field
* @param mixed $operatorValue
* @param mixed|null $value
* @return self
Expand All @@ -384,7 +384,7 @@ public function where($field, $operatorValue = null, $value = null): self
/**
* "OR" condition.
*
* @param string|callback $field
* @param string|callable $field
* @param mixed $operatorValue
* @param mixed|null $value
* @return self
Expand Down Expand Up @@ -492,7 +492,7 @@ public function orWhereNotIn(string $field, array $values): self
* @param string $field
* @param array $values
* @return self
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public function whereBetween(string $field, array $values): self
{
Expand All @@ -508,7 +508,7 @@ public function whereBetween(string $field, array $values): self
* @param string $field
* @param array $values
* @return self
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public function orWhereBetween(string $field, array $values): self
{
Expand All @@ -524,7 +524,7 @@ public function orWhereBetween(string $field, array $values): self
* @param string $field
* @param array $values
* @return self
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public function whereNotBetween(string $field, array $values): self
{
Expand All @@ -540,7 +540,7 @@ public function whereNotBetween(string $field, array $values): self
* @param string $field
* @param array $values
* @return self
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public function orWhereNotBetween(string $field, array $values): self
{
Expand All @@ -566,11 +566,11 @@ public function rawWhere(string $where, array $values = []): self
* Add WHERE condition.
*
* @param string $clause
* @param string|callback $field
* @param string|callable $field
* @param mixed $operatorValue
* @param mixed $value
* @return self
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
private function addWhere($clause, $field, $operatorValue = null, $value = null): self
{
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"psr-4": {
"Embryo\\": "Embryo/"
}
},
"require-dev": {
"phpstan/phpstan": "^0.12.40"
}
}
}
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
level: max
paths:
- Embryo

0 comments on commit 26736c2

Please sign in to comment.