Skip to content

Commit

Permalink
Merge pull request #30 from rmunate/analysis-W6yp6j
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
rmunate authored Jan 6, 2024
2 parents 40165c0 + f60ec39 commit 8faf9ee
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/Response/SQLServerRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class SQLServerRow
/**
* @param array $values
*/
public function __construct(array $values) {
public function __construct(array $values)
{
foreach ($values as $key => $value) {
$this->{$key} = $value;
}
}

}
38 changes: 0 additions & 38 deletions src/Traits/Execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private function execGeneral()
private function execSelect()
{
try {

$PDO = $this->connection->prepare($this->statement);

StatementsValidator::isValidParams($this->params);
Expand All @@ -52,9 +51,7 @@ private function execSelect()
$rows = $PDO->fetchAll(PDO::FETCH_ASSOC);

$this->response = $rows;

} catch (\Exception $e) {

throw SQLServerException::create('Error executing SQL Select Query: '.$e->getMessage());
}
}
Expand All @@ -67,7 +64,6 @@ private function execSelect()
private function execUpdate()
{
try {

$this->inactivateCheckConstraint();

$PDO = $this->connection->prepare($this->statement);
Expand All @@ -87,9 +83,7 @@ private function execUpdate()
$this->response = $response && $PDO->rowCount() > 0;

$this->activateCheckConstraint();

} catch (\Exception $e) {

throw SQLServerException::create('Error executing SQL Update Query: '.$e->getMessage());
}
}
Expand All @@ -102,11 +96,9 @@ private function execUpdate()
private function execInsert()
{
try {

$this->inactivateCheckConstraint();

if (!empty($this->params)) {

$PDO = $this->connection->prepare($this->statement);

if (Utilities::hasSubArrays($this->params)) {
Expand All @@ -131,18 +123,14 @@ private function execInsert()

/** @phpstan-ignore-next-line */
$this->response = $response && $PDO->rowCount() > 0;

} else {

$response = $this->connection->exec($this->statement);

$this->response = $response > 0;
}

$this->activateCheckConstraint();

} catch (\Exception $e) {

throw SQLServerException::create('Error executing SQL Insert Query: '.$e->getMessage());
}
}
Expand All @@ -155,15 +143,12 @@ private function execInsert()
private function execInsertGetId()
{
try {

$this->inactivateCheckConstraint();

if (!empty($this->params)) {

$PDO = $this->connection->prepare($this->statement);

if (Utilities::hasSubArrays($this->params)) {

$ids = [];

foreach ($this->params as $key => $param) {
Expand All @@ -179,9 +164,7 @@ private function execInsertGetId()
}

$this->response = $ids;

} else {

foreach ($this->params as $key => $value) {
if (strpos($this->statement, ":$key") !== false) {
$PDO->bindParam($key, $this->params[$key]);
Expand All @@ -192,18 +175,14 @@ private function execInsertGetId()

$this->response = ($response && $PDO->rowCount() > 0) ? $this->connection->lastInsertId() : null;
}

} else {

$response = $this->connection->exec($this->statement);

$this->response = $response > 0;
}

$this->activateCheckConstraint();

} catch (\Exception $e) {

throw SQLServerException::create('Error executing SQL Insert Query: '.$e->getMessage());
}
}
Expand All @@ -216,7 +195,6 @@ private function execInsertGetId()
private function execDelete()
{
try {

$this->inactivateCheckConstraint();

if (!empty($this->params)) {
Expand All @@ -231,18 +209,14 @@ private function execDelete()
$PDO->execute();

$this->response = $PDO->rowCount() > 0;

} else {

$PDO = $this->connection->exec($this->statement);

$this->response = $PDO !== false;
}

$this->activateCheckConstraint();

} catch (\Exception $e) {

throw SQLServerException::create('Error executing SQL Delete Query: '.$e->getMessage());
}
}
Expand All @@ -255,13 +229,11 @@ private function execDelete()
private function execProcedure()
{
try {

$PDO = $this->connection->prepare($this->statement);

StatementsValidator::isValidParams($this->params);

if (!empty($this->params)) {

foreach ($this->params as $key => $value) {
if (strpos($this->statement, ":$key") !== false) {
$PDO->bindParam($key, $this->params[$key]);
Expand All @@ -273,9 +245,7 @@ private function execProcedure()
$rows = $PDO->fetchAll(PDO::FETCH_ASSOC);

$this->response = $rows;

} catch (\Exception $e) {

throw SQLServerException::create('Error executing SQL Store Procedure Query: '.$e->getMessage());
}
}
Expand All @@ -288,7 +258,6 @@ private function execProcedure()
private function execTransactionalProcedure()
{
try {

$PDO = $this->connection->prepare($this->statement);

StatementsValidator::isValidParams($this->params);
Expand All @@ -305,9 +274,7 @@ private function execTransactionalProcedure()
$PDO->closeCursor();

$this->response = $result;

} catch (\Exception $e) {

throw SQLServerException::create('Error executing SQL Transactional Store Procedure Query: '.$e->getMessage());
}
}
Expand Down Expand Up @@ -344,23 +311,18 @@ private function inactivateCheckConstraint()
private function activateCheckConstraint()
{
if ($this->constraints) {

if (!empty($this->constraintsTables)) {

foreach ($this->constraintsTables as $key => $table) {
$stmt = "ALTER TABLE {$table} CHECK CONSTRAINT ALL;";
$this->connection->exec($stmt);
}

} else {

$nameTable = Utilities::getNameTable($this->statement);

if (!empty($nameTable)) {
$stmt = "ALTER TABLE {$nameTable} CHECK CONSTRAINT ALL;";
$this->connection->exec($stmt);
}

}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Traits/Methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Rmunate\SqlServerLite\Traits;

use Closure;
use Rmunate\SqlServerLite\Response\SQLServerRow;
use Rmunate\SqlServerLite\Response\SQLServerResponse;
use Rmunate\SqlServerLite\Response\SQLServerRow;

trait Methods
{
Expand Down Expand Up @@ -55,6 +55,7 @@ public function first()

if (!empty($this->response)) {
$first = reset($this->response);

return new SQLServerRow($first);
}

Expand All @@ -72,6 +73,7 @@ public function last()

if (!empty($this->response)) {
$first = end($this->response);

return new SQLServerRow($first);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Validator/StatementsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function withoutComments(string $statement)
$statement = preg_replace('/\/\*.*?\*\//s', '', $statement);

// Check for forbidden comment strings
$forbiddenCommentPatterns = ["/*", "*/", "//", "--", "<-", "->"];
$forbiddenCommentPatterns = ['/*', '*/', '//', '--', '<-', '->'];
foreach ($forbiddenCommentPatterns as $commentPattern) {
if (stripos($statement, $commentPattern)) {
throw SQLServerException::create("The statement contains comments ($commentPattern); please remove them to proceed.");
Expand Down

0 comments on commit 8faf9ee

Please sign in to comment.