Skip to content

Commit 7b91ed8

Browse files
committed
Apply PSR-12 styles
1 parent 143391e commit 7b91ed8

File tree

9 files changed

+526
-558
lines changed

9 files changed

+526
-558
lines changed

admin/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ done
2929
if [ "$FILES" != "" ]
3030
then
3131
echo "Running Code Sniffer..."
32-
./vendor/bin/phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 --encoding=utf-8 -n -p $FILES
32+
./vendor/bin/phpcbf --standard=PSR12 --encoding=utf-8 -n -p $FILES
3333
fi
3434

35-
exit $?
35+
exit $?

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
},
2222
"require-dev": {
2323
"codeigniter4/codeigniter4": "dev-develop",
24-
"codeigniter4/codeigniter4-standard": "^1.0",
2524
"fakerphp/faker": "^1.9",
2625
"mockery/mockery": "^1.0",
2726
"nexusphp/tachycardia": "^1.0",
@@ -54,7 +53,7 @@
5453
"prefer-stable": true,
5554
"scripts": {
5655
"post-update-cmd": [
57-
"bash admin/setup.sh"
56+
"bash -c \"if [ -f admin/setup.sh ]; then bash admin/setup.sh; fi\""
5857
],
5958
"analyze": "phpstan analyze",
6059
"inspect": "deptrac analyze --cache-file=build/deptrac.cache",

src/Database/Migrations/2021-07-04-041948_CreateSettingsTable.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,41 @@
77

88
class CreateSettingsTable extends Migration
99
{
10-
public function up()
11-
{
12-
$this->forge->addField('id');
13-
$this->forge->addField([
14-
'class' => [
15-
'type' => 'varchar',
16-
'constraint' => 255,
17-
],
18-
'key' => [
19-
'type' => 'varchar',
20-
'constraint' => 255,
21-
],
22-
'value' => [
23-
'type' => 'text',
24-
'null' => true,
25-
],
26-
'type' => [
27-
'type' => 'varchar',
28-
'constraint' => 31,
29-
'default' => 'string',
30-
],
31-
'created_at' => [
32-
'type' => 'datetime',
33-
'null' => false,
34-
],
35-
'updated_at' => [
36-
'type' => 'datetime',
37-
'null' => false,
38-
],
39-
]);
40-
$this->forge->createTable(config('Settings')->database['table'], true);
41-
}
10+
public function up()
11+
{
12+
$this->forge->addField('id');
13+
$this->forge->addField([
14+
'class' => [
15+
'type' => 'varchar',
16+
'constraint' => 255,
17+
],
18+
'key' => [
19+
'type' => 'varchar',
20+
'constraint' => 255,
21+
],
22+
'value' => [
23+
'type' => 'text',
24+
'null' => true,
25+
],
26+
'type' => [
27+
'type' => 'varchar',
28+
'constraint' => 31,
29+
'default' => 'string',
30+
],
31+
'created_at' => [
32+
'type' => 'datetime',
33+
'null' => false,
34+
],
35+
'updated_at' => [
36+
'type' => 'datetime',
37+
'null' => false,
38+
],
39+
]);
40+
$this->forge->createTable(config('Settings')->database['table'], true);
41+
}
4242

43-
public function down()
44-
{
45-
$this->forge->dropTable(config('Settings')->database['table']);
46-
}
43+
public function down()
44+
{
45+
$this->forge->dropTable(config('Settings')->database['table']);
46+
}
4747
}

src/Handlers/BaseHandler.php

Lines changed: 127 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -4,157 +4,139 @@
44

55
abstract class BaseHandler
66
{
7-
/**
8-
* Returns a single value from the handler, if stored.
9-
*
10-
* @param string $class
11-
* @param string $key
12-
*
13-
* @return mixed
14-
*/
15-
abstract public function get(string $class, string $key);
7+
/**
8+
* Returns a single value from the handler, if stored.
9+
*
10+
* @param string $class
11+
* @param string $key
12+
*
13+
* @return mixed
14+
*/
15+
abstract public function get(string $class, string $key);
1616

17-
/**
18-
* If the Handler supports saving values, it
19-
* MUST override this method to provide that functionality.
20-
* Not all Handlers will support writing values.
21-
*
22-
* @param string $key
23-
* @param mixed $value
24-
*
25-
* @return mixed
26-
*/
27-
public function set(string $class, string $key, $value = null)
28-
{
29-
throw new \RuntimeException('Set method not implemented for current Settings handler.');
30-
}
17+
/**
18+
* If the Handler supports saving values, it
19+
* MUST override this method to provide that functionality.
20+
* Not all Handlers will support writing values.
21+
*
22+
* @param string $key
23+
* @param mixed $value
24+
*
25+
* @return mixed
26+
*/
27+
public function set(string $class, string $key, $value = null)
28+
{
29+
throw new \RuntimeException('Set method not implemented for current Settings handler.');
30+
}
3131

32-
/**
33-
* Takes care of converting some item types so they can be safely
34-
* stored and re-hydrated into the config files.
35-
*
36-
* @param mixed $value
37-
*
38-
* @return string|mixed
39-
*/
40-
protected function prepareValue($value)
41-
{
42-
if (is_bool($value))
43-
{
44-
return (int)$value;
45-
}
32+
/**
33+
* Takes care of converting some item types so they can be safely
34+
* stored and re-hydrated into the config files.
35+
*
36+
* @param mixed $value
37+
*
38+
* @return string|mixed
39+
*/
40+
protected function prepareValue($value)
41+
{
42+
if (is_bool($value)) {
43+
return (int)$value;
44+
}
4645

47-
if (is_array($value) || is_object($value))
48-
{
49-
return serialize($value);
50-
}
46+
if (is_array($value) || is_object($value)) {
47+
return serialize($value);
48+
}
5149

52-
return $value;
53-
}
50+
return $value;
51+
}
5452

55-
/**
56-
* Handles some special case conversions that
57-
* data might have been saved as, such as booleans
58-
* and serialized data.
59-
*
60-
* @param mixed $value
61-
*
62-
* @return boolean|mixed
63-
*/
64-
protected function parseValue($value, string $type)
65-
{
66-
// Serialized?
67-
if ($this->isSerialized($value))
68-
{
69-
$value = unserialize($value);
70-
}
53+
/**
54+
* Handles some special case conversions that
55+
* data might have been saved as, such as booleans
56+
* and serialized data.
57+
*
58+
* @param mixed $value
59+
*
60+
* @return boolean|mixed
61+
*/
62+
protected function parseValue($value, string $type)
63+
{
64+
// Serialized?
65+
if ($this->isSerialized($value)) {
66+
$value = unserialize($value);
67+
}
7168

72-
settype($value, $type);
69+
settype($value, $type);
7370

74-
return $value;
75-
}
71+
return $value;
72+
}
7673

77-
/**
78-
* Checks to see if an object is serialized and correctly formatted.
79-
*
80-
* Taken from Wordpress core functions.
81-
*
82-
* @param mixed $data
83-
* @param boolean $strict Whether to be strict about the end of the string.
84-
*
85-
* @return boolean
86-
*/
87-
protected function isSerialized($data, $strict = true): bool
88-
{
89-
// If it isn't a string, it isn't serialized.
90-
if (! is_string($data))
91-
{
92-
return false;
93-
}
94-
$data = trim($data);
95-
if ('N;' === $data)
96-
{
97-
return true;
98-
}
99-
if (strlen($data) < 4)
100-
{
101-
return false;
102-
}
103-
if (':' !== $data[1])
104-
{
105-
return false;
106-
}
107-
if ($strict)
108-
{
109-
$lastc = substr($data, -1);
110-
if (';' !== $lastc && '}' !== $lastc)
111-
{
112-
return false;
113-
}
114-
}
115-
else
116-
{
117-
$semicolon = strpos($data, ';');
118-
$brace = strpos($data, '}');
119-
// Either ; or } must exist.
120-
if (false === $semicolon && false === $brace)
121-
{
122-
return false;
123-
}
124-
// But neither must be in the first X characters.
125-
if (false !== $semicolon && $semicolon < 3)
126-
{
127-
return false;
128-
}
129-
if (false !== $brace && $brace < 4)
130-
{
131-
return false;
132-
}
133-
}
134-
$token = $data[0];
135-
switch ($token) {
136-
case 's':
137-
if ($strict)
138-
{
139-
if ('"' !== substr($data, -2, 1))
140-
{
141-
return false;
142-
}
143-
}
144-
elseif (false === strpos($data, '"'))
145-
{
146-
return false;
147-
}
148-
// Or else fall through.
149-
case 'a':
150-
case 'O':
151-
return (bool) preg_match("/^{$token}:[0-9]+:/s", $data);
152-
case 'b':
153-
case 'i':
154-
case 'd':
155-
$end = $strict ? '$' : '';
156-
return (bool) preg_match("/^{$token}:[0-9.E+-]+;$end/", $data);
157-
}
158-
return false;
159-
}
74+
/**
75+
* Checks to see if an object is serialized and correctly formatted.
76+
*
77+
* Taken from Wordpress core functions.
78+
*
79+
* @param mixed $data
80+
* @param boolean $strict Whether to be strict about the end of the string.
81+
*
82+
* @return boolean
83+
*/
84+
protected function isSerialized($data, $strict = true): bool
85+
{
86+
// If it isn't a string, it isn't serialized.
87+
if (! is_string($data)) {
88+
return false;
89+
}
90+
$data = trim($data);
91+
if ('N;' === $data) {
92+
return true;
93+
}
94+
if (strlen($data) < 4) {
95+
return false;
96+
}
97+
if (':' !== $data[1]) {
98+
return false;
99+
}
100+
if ($strict) {
101+
$lastc = substr($data, -1);
102+
if (';' !== $lastc && '}' !== $lastc) {
103+
return false;
104+
}
105+
} else {
106+
$semicolon = strpos($data, ';');
107+
$brace = strpos($data, '}');
108+
// Either ; or } must exist.
109+
if (false === $semicolon && false === $brace) {
110+
return false;
111+
}
112+
// But neither must be in the first X characters.
113+
if (false !== $semicolon && $semicolon < 3) {
114+
return false;
115+
}
116+
if (false !== $brace && $brace < 4) {
117+
return false;
118+
}
119+
}
120+
$token = $data[0];
121+
switch ($token) {
122+
case 's':
123+
if ($strict) {
124+
if ('"' !== substr($data, -2, 1)) {
125+
return false;
126+
}
127+
} elseif (false === strpos($data, '"')) {
128+
return false;
129+
}
130+
// Or else fall through.
131+
case 'a':
132+
case 'O':
133+
return (bool) preg_match("/^{$token}:[0-9]+:/s", $data);
134+
case 'b':
135+
case 'i':
136+
case 'd':
137+
$end = $strict ? '$' : '';
138+
return (bool) preg_match("/^{$token}:[0-9.E+-]+;$end/", $data);
139+
}
140+
return false;
141+
}
160142
}

0 commit comments

Comments
 (0)