Skip to content

Commit 252364e

Browse files
committed
Update
PHP ^8.2 | PSR
1 parent 8d7dd40 commit 252364e

34 files changed

+578
-583
lines changed

src/Connection/Config.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct($key = self::KEY, $value = self::VALUE, $id = self::
7474
public function getValue(string $key) : string
7575
{
7676
$this->bind(["{$this->keyColumn}" => $key]);
77-
$sql = "SELECT `{$this->valueColumn}` FROM `{$this->table}` ";
77+
$sql = "SELECT `{$this->valueColumn}` FROM `{$this->table}` ";
7878
$sql .= "WHERE `{$this->keyColumn}` LIKE :{$this->keyColumn};";
7979
return (string)$this->getSingle($sql);
8080
}
@@ -96,7 +96,7 @@ public function setValue(string $key, $value = '') : bool
9696
"{$this->keyColumn}" => $key,
9797
"{$this->valueColumn}" => $value
9898
]);
99-
$sql = "INSERT INTO `{$this->table}` (`$this->keyColumn`, `{$this->valueColumn}`) ";
99+
$sql = "INSERT INTO `{$this->table}` (`$this->keyColumn`, `{$this->valueColumn}`) ";
100100
$sql .= "VALUES(:{$this->keyColumn}, :{$this->valueColumn});";
101101
return (bool)$this->execute($sql);
102102
}
@@ -115,7 +115,7 @@ public function updateValue(string $key, $value = '') : bool
115115
"{$this->keyColumn}" => $key,
116116
"{$this->valueColumn}" => $value
117117
]);
118-
$sql = "UPDATE `{$this->table}` SET `{$this->valueColumn}` = :{$this->valueColumn} ";
118+
$sql = "UPDATE `{$this->table}` SET `{$this->valueColumn}` = :{$this->valueColumn} ";
119119
$sql .= "WHERE `{$this->keyColumn}` LIKE :{$this->keyColumn};";
120120
return (bool)$this->execute($sql);
121121
}
@@ -130,7 +130,7 @@ public function updateValue(string $key, $value = '') : bool
130130
public function deleteValue(string $key) : bool
131131
{
132132
$this->bind(["{$this->keyColumn}" => $key]);
133-
$sql = "DELETE FROM `{$this->table}` ";
133+
$sql = "DELETE FROM `{$this->table}` ";
134134
$sql .= "WHERE `{$this->keyColumn}` LIKE :{$this->keyColumn};";
135135
return (bool)$this->execute($sql);
136136
}
@@ -145,7 +145,7 @@ public function deleteValue(string $key) : bool
145145
public function hasValue(string $key) : bool
146146
{
147147
$this->bind(["{$this->keyColumn}" => $key]);
148-
$sql = "SELECT COUNT('{$this->keyColumn}') FROM `{$this->table}` ";
148+
$sql = "SELECT COUNT('{$this->keyColumn}') FROM `{$this->table}` ";
149149
$sql .= "WHERE `{$this->keyColumn}` LIKE :{$this->keyColumn};";
150150
return (bool)$this->getSingle($sql);
151151
}
@@ -160,7 +160,7 @@ public function hasValue(string $key) : bool
160160
public function getId(string $key) : int
161161
{
162162
$this->bind(["{$this->keyColumn}" => $key]);
163-
$sql = "SELECT `{$this->key}` FROM `{$this->table}` ";
163+
$sql = "SELECT `{$this->key}` FROM `{$this->table}` ";
164164
$sql .= "WHERE `{$this->keyColumn}` LIKE :{$this->keyColumn};";
165165
return (int)$this->getSingle($sql);
166166
}

src/Connection/DataTable.php

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ class DataTable extends Orm
3131
\FloatPHP\Helpers\Framework\inc\TraitTranslatable,
3232
\FloatPHP\Helpers\Framework\inc\TraitLoggable;
3333

34-
/**
35-
* @access protected
36-
* @var array $columns, Table columns
37-
* @var array $request, Table request
38-
* @var array $search, Search binded data
39-
* @var array $match, Custom columns keys
40-
* @var int $total, Table total
41-
* @var int $filtered, Search count
42-
* @var int $chars, Search length
43-
*/
34+
/**
35+
* @access protected
36+
* @var array $columns, Table columns
37+
* @var array $request, Table request
38+
* @var array $search, Search binded data
39+
* @var array $match, Custom columns keys
40+
* @var int $total, Table total
41+
* @var int $filtered, Search count
42+
* @var int $chars, Search length
43+
*/
4444
protected $columns = [];
4545
protected $request = [];
4646
protected $search = [];
@@ -97,12 +97,12 @@ protected function build(?string $table = null, ?string $key = null, array $colu
9797
{
9898
// Init ORM
9999
parent::__construct();
100-
100+
101101
// Set table
102-
$this->table = ($table) ? $table : (new Catcher())->key;
103-
$this->key = ($key) ? $key : "{$this->table}Id";
104-
$this->columns = ($columns) ? $columns : $this->columns();
105-
102+
$this->table = $table ? $table : (new Catcher())->key;
103+
$this->key = $key ?: "{$this->table}Id";
104+
$this->columns = $columns ? $columns : $this->columns();
105+
106106
// Set request
107107
$this->request = $this->getRequest();
108108

@@ -136,7 +136,7 @@ protected function preRender(array $data = []) : array
136136
* @param array $match
137137
* @return void
138138
*/
139-
protected function match(array $match = [])
139+
protected function match(array $match = []) : void
140140
{
141141
$this->match = $match;
142142
}
@@ -164,8 +164,8 @@ protected function getSearchPattern(string $search) : string
164164
*/
165165
protected function getStart() : int
166166
{
167-
return isset($this->request['start'])
168-
? intval($this->request['start']) : 0;
167+
return isset($this->request['start'])
168+
? intval($this->request['start']) : 0;
169169
}
170170

171171
/**
@@ -176,8 +176,8 @@ protected function getStart() : int
176176
*/
177177
protected function getLength() : int
178178
{
179-
return isset($this->request['length'])
180-
? intval($this->request['length']) : 1;
179+
return isset($this->request['length'])
180+
? intval($this->request['length']) : 1;
181181
}
182182

183183
/**
@@ -188,8 +188,8 @@ protected function getLength() : int
188188
*/
189189
protected function getDraw() : int
190190
{
191-
return isset($this->request['draw'])
192-
? intval($this->request['draw']) : 0;
191+
return isset($this->request['draw'])
192+
? intval($this->request['draw']) : 0;
193193
}
194194

195195
/**
@@ -307,29 +307,29 @@ protected function getSearchQuery() : string
307307
$where = '';
308308
$columns = $this->columns;
309309

310-
// Set where clause
310+
// Set where clause
311311
if ( $this->match ) {
312312
$columns = $this->match;
313313
}
314314

315-
foreach ($columns as $key => $column) {
316-
if ( $column !== $this->key ) {
317-
if ( isset($this->request['columns'][$key]) ) {
318-
$option = $this->request['columns'][$key];
315+
foreach ($columns as $key => $column) {
316+
if ( $column !== $this->key ) {
317+
if ( isset($this->request['columns'][$key]) ) {
318+
$option = $this->request['columns'][$key];
319319
if ( isset($option['searchable']) && $option['searchable'] == 'true' ) {
320320
$this->search[$column] = $this->getSearchPattern($search);
321321
$where .= "(`{$column}` LIKE :{$column}) OR ";
322322
}
323-
}
324-
}
325-
}
326-
327-
// Format where clause
328-
if ( !empty($where) ) {
329-
$where = substr(trim($where), 0, -3);
330-
$where = "WHERE {$where}";
331-
$sql .= " {$where} ";
332-
}
323+
}
324+
}
325+
}
326+
327+
// Format where clause
328+
if ( !empty($where) ) {
329+
$where = substr(trim($where), 0, -3);
330+
$where = "WHERE {$where}";
331+
$sql .= " {$where} ";
332+
}
333333
}
334334

335335
return $sql;
@@ -372,7 +372,7 @@ protected function getData() : array
372372
if ( $this->useCache ) {
373373

374374
$cache = new Cache();
375-
$key = $cache->getKey($this->table, [
375+
$key = $cache->getKey($this->table, [
376376
'start' => $this->getStart(),
377377
'length' => $this->getLength(),
378378
'orderby' => $this->getOrderBy(),
@@ -445,7 +445,7 @@ protected function verify(array $data)
445445
protected function hasAction() : bool
446446
{
447447
if ( isset($this->request['action']) ) {
448-
return ($this->request['action'] == 'true');
448+
return $this->request['action'] === 'true';
449449
}
450450
return false;
451451
}
@@ -475,7 +475,7 @@ protected function appendAction(array $data = []) : array
475475
*/
476476
protected function formatData(array $data = []) : array
477477
{
478-
return $this->mapArray('values', $data);
478+
return $this->mapArray(function: 'values', data: $data);
479479
}
480480

481481
/**

src/Connection/Dump.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
};
2222
use \mysqli;
2323

24-
System::setTimeLimit(0);
25-
System::setMemoryLimit('-1');
24+
System::setTimeLimit(seconds: 0);
25+
System::setMemoryLimit(value: '-1');
2626

2727
/**
2828
* MySQLi dump class.
@@ -50,7 +50,7 @@ public function __construct($config = [])
5050
$this->getDbAccess(),
5151
$config
5252
);
53-
53+
5454
// Reset configuration
5555
$this->resetConfig();
5656
}
@@ -66,10 +66,10 @@ public function import(string $file) : bool
6666
{
6767
// Init connection
6868
$connection = @new mysqli(
69-
$this->access['host'],
70-
$this->access['user'],
71-
$this->access['pswd'],
72-
$this->access['db']
69+
hostname: $this->access['host'],
70+
username: $this->access['user'],
71+
password: $this->access['pswd'],
72+
database: $this->access['name']
7373
);
7474

7575
// Check connection
@@ -99,15 +99,13 @@ public function import(string $file) : bool
9999
// End of query
100100
if ( substr(trim($line), -1, 1) == ';' ) {
101101

102-
// Perform query
103-
$i = (int)$connection->query($temp);
104-
$status += $i;
105-
if ( !$i ) {
106-
break;
107-
}
102+
// Perform query
103+
$i = (int)$connection->query($temp);
104+
$status += $i;
105+
if ( !$i ) break;
108106

109-
// Reset temp
110-
$temp = '';
107+
// Reset temp
108+
$temp = '';
111109
}
112110
}
113111

@@ -124,7 +122,7 @@ public function import(string $file) : bool
124122
*/
125123
public function export(string $file = 'dump.sql') : bool
126124
{
127-
$command = 'mysqldump --opt';
125+
$command = 'mysqldump --opt';
128126
$command .= " -u {$this->access['user']}";
129127

130128
if ( $this->access['host'] ) {
@@ -133,10 +131,10 @@ public function export(string $file = 'dump.sql') : bool
133131
if ( $this->access['pswd'] ) {
134132
$command .= " -p {$this->access['pswd']}";
135133
}
136-
137-
$command .= " {$this->access['db']} > {$file}";
134+
135+
$command .= " {$this->access['name']} > {$file}";
138136

139137
exec($command, $output, $status);
140-
return ($status === 0);
138+
return $status === 0;
141139
}
142140
}

src/Connection/Infile.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
namespace FloatPHP\Helpers\Connection;
1717

18+
use FloatPHP\Classes\Filesystem\Arrayify;
1819
use FloatPHP\Classes\Server\System;
1920
use \PDOException;
2021
use \PDO;
2122

22-
System::setTimeLimit(0);
23-
System::setMemoryLimit('-1');
23+
System::setTimeLimit(seconds: 0);
24+
System::setMemoryLimit(value: '-1');
2425

2526
/**
2627
* MySQL infile class.
@@ -40,10 +41,10 @@ class Infile
4041
*/
4142
public function __construct($config = [])
4243
{
43-
$this->config = array_merge([
44-
'db' => '',
44+
$this->config = Arrayify::merge([
4545
'host' => 'localhost',
4646
'port' => 3306,
47+
'name' => '',
4748
'user' => 'root',
4849
'pswd' => '',
4950
'charset' => false,
@@ -65,20 +66,20 @@ public function __construct($config = [])
6566
* @access public
6667
* @return void
6768
*/
68-
public function execute()
69+
public function execute() : void
6970
{
7071
try {
7172

7273
$start = microtime(true);
7374

7475
// Set PDO params
75-
$dsn = "mysql:dbname={$this->config['db']};";
76+
$dsn = "mysql:dbname={$this->config['name']};";
7677
$dsn .= "host={$this->config['host']};";
7778
$dsn .= "port={$this->config['port']}";
7879

7980
// Init PDO INFILE
80-
$pdo = new PDO($dsn,$this->config['user'], $this->config['pswd'], [
81-
PDO::MYSQL_ATTR_LOCAL_INFILE => true
81+
$pdo = new PDO($dsn, $this->config['user'], $this->config['pswd'], [
82+
PDO::MYSQL_ATTR_LOCAL_INFILE => true
8283
]);
8384

8485
// Truncate table
@@ -90,8 +91,8 @@ public function execute()
9091
$pdo->exec($this->buildQuery());
9192

9293
if ( $this->config['debug'] ) {
93-
$end = microtime(true);
94-
$time = ($end - $start);
94+
$end = microtime(true);
95+
$time = $end - $start;
9596
echo "Executed in : {$time} seconds\n";
9697
}
9798

@@ -107,14 +108,14 @@ public function execute()
107108
* @access private
108109
* @return string
109110
*/
110-
private function buildQuery()
111+
private function buildQuery() : string
111112
{
112-
$query = "LOAD DATA INFILE '{$this->config['file']}' ";
113+
$query = "LOAD DATA INFILE '{$this->config['file']}' ";
113114

114115
if ( $this->config['action'] ) {
115116
$query .= "{$this->config['action']} ";
116117
}
117-
118+
118119
$query .= "INTO TABLE `{$this->config['table']}` ";
119120

120121
if ( $this->config['charset'] ) {

src/Connection/Settings.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ final class Settings
3535
/**
3636
* Set settings row group.
3737
*
38+
* @access public
3839
* @param string $row
3940
*/
4041
public function __construct(string $row = self::ROW)
@@ -54,7 +55,7 @@ public function __construct(string $row = self::ROW)
5455
* @param mixed $default
5556
* @return mixed
5657
*/
57-
public function get(?string $key = null, $default = null)
58+
public function get(?string $key = null, $default = null) : mixed
5859
{
5960
$settings = $this->getValues();
6061
if ( !$this->isType('null', $key) ) {

0 commit comments

Comments
 (0)