Skip to content

Commit

Permalink
Merge pull request rmunate#26 from rmunate/analysis-54lEMY
Browse files Browse the repository at this point in the history
Apply StyleCI
  • Loading branch information
rmunate authored Dec 10, 2023
2 parents c1df6d8 + efdae14 commit 477b717
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 105 deletions.
4 changes: 2 additions & 2 deletions src/Bases/BaseSQLServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public static function connection(string $connection)
/**
* Return the connection status.
*
* @param string $connection The name of the connection.
* @param string $connection The name of the connection.
* @param int $loginTimeout The login timeout duration.
*
*
* @return SQLServerStatus The connection status.
*/
public static function status(string $connection, int $loginTimeout = 3)
Expand Down
4 changes: 1 addition & 3 deletions src/Response/SQLServerStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace Rmunate\SqlServerLite\Response;

/**
* Class SQLServerStatus
*
* @package Rmunate\SqlServerLite\Response
* Class SQLServerStatus.
*/
class SQLServerStatus
{
Expand Down
33 changes: 21 additions & 12 deletions src/SQLServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Rmunate\SqlServerLite;

use Rmunate\SqlServerLite\Bases\BaseSQLServer;
use Rmunate\SqlServerLite\Singleton\SQLServerSingleton;
use Rmunate\SqlServerLite\Traits\Attributes;
use Rmunate\SqlServerLite\Traits\Execute;
use Rmunate\SqlServerLite\Traits\Methods;
use Rmunate\SqlServerLite\Traits\Attributes;
use Rmunate\SqlServerLite\Bases\BaseSQLServer;
use Rmunate\SqlServerLite\Traits\Transactions;
use Rmunate\SqlServerLite\Utilities\Utilities;
use Rmunate\SqlServerLite\Singleton\SQLServerSingleton;
use Rmunate\SqlServerLite\Validator\StatementsValidator;

class SQLServer extends BaseSQLServer
Expand All @@ -33,9 +33,9 @@ class SQLServer extends BaseSQLServer
/**
* Constructor to establish the initial connection.
*
* @param mixed $credentials
* @param mixed $credentials
* @param string $connection
* @param int $loginTimeout
* @param int $loginTimeout
*/
public function __construct($credentials, string $connection, int $loginTimeout = 0)
{
Expand All @@ -46,7 +46,8 @@ public function __construct($credentials, string $connection, int $loginTimeout
* Prepare the SELECT query and return it.
*
* @param string $statement
* @param array $params
* @param array $params
*
* @return static
*/
public function select(string $statement, array $params = [])
Expand All @@ -65,7 +66,8 @@ public function select(string $statement, array $params = [])
* Prepare the Update query and return the result set.
*
* @param string $statement
* @param array $params
* @param array $params
*
* @return object
*/
public function update(string $statement, array $params = [])
Expand All @@ -90,7 +92,8 @@ public function update(string $statement, array $params = [])
* Prepare the Insert query and return the result set.
*
* @param string $statement
* @param array $params
* @param array $params
*
* @return object
*/
public function insert(string $statement, array $params = [])
Expand All @@ -115,7 +118,8 @@ public function insert(string $statement, array $params = [])
* Prepare the Insert with query and return the result set.
*
* @param string $statement
* @param array $params
* @param array $params
*
* @return object
*/
public function insertGetId(string $statement, array $params = [])
Expand All @@ -140,7 +144,8 @@ public function insertGetId(string $statement, array $params = [])
* Prepare the Delete query and return the result set.
*
* @param string $statement
* @param array $params
* @param array $params
*
* @return mixed
*/
public function delete(string $statement, array $params = [])
Expand All @@ -165,7 +170,8 @@ public function delete(string $statement, array $params = [])
* Prepare the store procedure query and return the result set.
*
* @param string $statement
* @param array $params
* @param array $params
*
* @return object
*/
public function executeProcedure(string $statement, array $params = [])
Expand All @@ -184,7 +190,8 @@ public function executeProcedure(string $statement, array $params = [])
* Prepare the transaction store procedure query and return the result set.
*
* @param string $statement
* @param array $params
* @param array $params
*
* @return mixed
*/
public function executeTransactionalProcedure(string $statement, array $params = [])
Expand All @@ -209,6 +216,7 @@ public function executeTransactionalProcedure(string $statement, array $params =
* Receive the params from the query.
*
* @param array $params
*
* @return mixed
*/
public function params(array $params)
Expand All @@ -228,6 +236,7 @@ public function params(array $params)
* Set the property to disable constraints.
*
* @param mixed ...$tables Tables for which constraints should be disabled.
*
* @return $this Returns the current instance of the object.
*/
public function noCheckConstraint(...$tables)
Expand Down
11 changes: 0 additions & 11 deletions src/Singleton/SQLServerSingleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class SQLServerSingleton
public static function mount($credentials, string $connection, int $loginTimeout)
{
if (empty(self::$instance[$connection])) {

try {

// Create the DSN:
$dsn = "sqlsrv:Server={$credentials->host}";
$dsn .= (isset($credentials->port) && !empty($credentials->port)) ? ",{$credentials->port}" : ',1433';
Expand All @@ -53,7 +51,6 @@ public static function mount($credentials, string $connection, int $loginTimeout
}

self::$instance[$connection] = $conection;

} catch (PDOException $e) {
throw SQLServerException::create($e->getMessage());
}
Expand Down Expand Up @@ -86,17 +83,13 @@ public static function beginTransaction()
public static function commit()
{
if (!empty(self::$instance)) {

foreach (self::$instance as $key => $instance) {
$instance->commit();
}

self::$beginTransaction = false;

} else {

throw SQLServerException::create('The connection to the database is not initialized.');

}
}

Expand All @@ -108,17 +101,13 @@ public static function commit()
public static function rollback()
{
if (!empty(self::$instance)) {

foreach (self::$instance as $key => $instance) {
$instance->rollBack();
}

self::$beginTransaction = false;

} else {

throw SQLServerException::create('The connection to the database is not initialized.');

}
}
}
16 changes: 0 additions & 16 deletions src/Traits/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ trait Attributes
public function setTimeOut(int $seconds = 0)
{
try {

$this->connection->setAttribute(PDO::SQLSRV_ATTR_QUERY_TIMEOUT, $seconds);

} catch (\Throwable $th) {

throw SQLServerException::create($th->getMessage());

}

return $this;
Expand All @@ -45,13 +41,9 @@ public function setErrorMode(string $mode = 'exception')
}

try {

$this->connection->setAttribute(PDO::ATTR_ERRMODE, constant('PDO::ERRMODE_'.mb_strtoupper($mode)));

} catch (\Throwable $th) {

throw SQLServerException::create($th->getMessage());

}

return $this;
Expand All @@ -73,13 +65,9 @@ public function setEncoding(string $case = 'utf8')
}

try {

$this->connection->setAttribute(PDO::SQLSRV_ATTR_ENCODING, constant('PDO::SQLSRV_ENCODING_'.mb_strtoupper($case)));

} catch (\Throwable $th) {

throw SQLServerException::create($th->getMessage());

}

return $this;
Expand All @@ -93,13 +81,9 @@ public function setEncoding(string $case = 'utf8')
public function setDirectQuery()
{
try {

$this->connection->setAttribute(PDO::SQLSRV_ATTR_DIRECT_QUERY, true);

} catch (\Throwable $th) {

throw SQLServerException::create($th->getMessage());

}

return $this;
Expand Down
Loading

0 comments on commit 477b717

Please sign in to comment.