Skip to content

Commit

Permalink
fix: PER2.0 coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
tbreuss committed Jun 2, 2024
1 parent 37bc0e8 commit 4755656
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
17 changes: 8 additions & 9 deletions src/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Represents a connection between PHP and a database server.
*
*
* @method bool beginTransaction() Initiates a transaction
* @method bool commit() Commits a transaction
* @method string|null errorCode() Fetch the SQLSTATE associated with the last operation on the database handle
Expand Down Expand Up @@ -101,15 +101,15 @@ class PDO
/**
* Creates a PDO instance representing a connection to a database
*/
public function __construct(string $dsn, ?string $username = NULL, ?string $password = NULL, array $options = [])
public function __construct(string $dsn, ?string $username = null, ?string $password = null, array $options = [])
{
$options = array_replace(
[
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
],
$options
$options,
);
$this->pdo = new \PDO($dsn, $username, $password, $options);
}
Expand Down Expand Up @@ -140,7 +140,6 @@ public function __call(string $name, array $arguments): mixed
}

/**
*
* Calls the static method of the underlying PDO instance
*/
public static function __callStatic(string $name, array $arguments): mixed
Expand All @@ -166,7 +165,7 @@ public function getWrappedPdo(): \PDO

/**
* Prepares a statement for execution and returns a statement object
*
*
* This differs from `PDO::prepare` in that it will return a `tebe\PDOStatement` object.
*/
public function prepare(string $query, array $options = []): PDOStatement|false
Expand All @@ -177,7 +176,7 @@ public function prepare(string $query, array $options = []): PDOStatement|false

/**
* Prepares and executes an SQL statement without placeholders and returns a statement object
*
*
* This differs from `PDO::query` in that it will return a `tebe\PDOStatement` object.
*/
public function query(string $query, mixed ...$fetchModeArgs): PDOStatement|false
Expand All @@ -188,8 +187,8 @@ public function query(string $query, mixed ...$fetchModeArgs): PDOStatement|fals

/**
* Quotes a value for use in a query
*
* This differs from `PDO::quote()` in that it will convert an array into
*
* This differs from `PDO::quote()` in that it will convert an array into
* a string of comma-separated quoted values.
*/
public function quote(array|string|int|float|null $value, int $type = self::PARAM_STR): string|false
Expand All @@ -208,7 +207,7 @@ public function quote(array|string|int|float|null $value, int $type = self::PARA
}

/**
* Runs a query with bound values and returns the resulting PDOStatement;
* Runs a query with bound values and returns the resulting PDOStatement;
* array values will be processed by the parser instance and placeholders are replaced.
*/
public function run(string $sql, ?array $args = null): PDOStatement|false
Expand Down
10 changes: 5 additions & 5 deletions src/PDOParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Parsing/rebuilding functionality for all drivers.
*
* Note that this does not validate the syntax; it only replaces/rebuilds placeholders in the query.
*
*
* @link https://github.com/auraphp/Aura.Sql Copied from aura/sql and simplified according to our needs
*/
class PDOParser
Expand Down Expand Up @@ -76,7 +76,7 @@ protected function rebuildPart(string $part): string
"/(?<!:)(:[a-zA-Z_][a-zA-Z0-9_]*)|(\?)/um",
$part,
-1,
PREG_SPLIT_DELIM_CAPTURE
PREG_SPLIT_DELIM_CAPTURE,
);

// check subparts to expand placeholders for bound arrays
Expand Down Expand Up @@ -172,7 +172,7 @@ protected function getParts(string $statement): array
"/($split)/um",
$statement,
-1,
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY
PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY,
);
}

Expand Down Expand Up @@ -211,7 +211,7 @@ protected function determineSplitRegex($driver): array
"'(?:[^'\\\\]|\\\\'?)*'",
// double-quoted string
'"(?:[^"\\\\]|\\\\"?)*"',
]
],
};
}

Expand All @@ -221,7 +221,7 @@ protected function determineSkipRegex($driver): string
'mysql' => '/^(\'|\"|\`)/um',
'pgsql' => '/^(\'|\"|\$|\:[^a-zA-Z_])/um',
'sqlite' => '/^(\'|"|`|\:[^a-zA-Z_])/um',
default => '/^(\'|\"|\:[^a-zA-Z_])/um'
default => '/^(\'|\"|\:[^a-zA-Z_])/um',
};
}
}
6 changes: 3 additions & 3 deletions src/PDOStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Represents a prepared statement and, after the statement is executed, an associated result set.
*
*
* @method bool bindValue(string|int $param, mixed $value, int $type = PDO::PARAM_STR) Binds a value to a parameter
* @method bool closeCursor() Closes the cursor, enabling the statement to be executed again
* @method int columnCount() Returns the number of columns in the result set
Expand Down Expand Up @@ -98,7 +98,7 @@ public function bindParam(string|int $param, mixed &$var, int $type = PDO::PARAM

/**
* Executes a prepared statement
*
*
* This differs from `PDOStatement::execute` in that it will return a PDOStatement object.
*/
public function execute(?array $params = null): PDOStatement|false
Expand Down Expand Up @@ -223,7 +223,7 @@ public function fetchAllNumeric(): array
}

/**
* Fetches all rows from the result set as an array of objects of the requested class,
* Fetches all rows from the result set as an array of objects of the requested class,
* mapping the columns to named properties in the class
*/
public function fetchAllObject(string $class = 'stdClass', ?array $constructorArgs = null, int $style = 0): array
Expand Down

0 comments on commit 4755656

Please sign in to comment.