Skip to content

Commit 7235bc1

Browse files
committed
Upgrade to PHP 8.1 and higher.
1 parent 4a4d64f commit 7235bc1

File tree

6 files changed

+117
-82
lines changed

6 files changed

+117
-82
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/.idea/
2+
/.phpunit.result.cache
23
/bin/
34
/composer.lock
45
/custom.task.properties
56
/custom.type.properties
6-
/vendor/
7+
/phpunit.xml
8+
/test/coverage.xml
9+
/test/report/
10+
/vendor/

.travis.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

build.xml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project name="php-erd-concepts" default="build" basedir=".">
3-
<target name="build">
4-
<echo message="noting to do."/>
5-
</target>
6-
73
<!-- Run composer update and executes various other updates -->
84
<target name="update">
9-
<exec command="composer update --prefer-source" checkreturn="true" passthru="true"/>
5+
<exec executable="composer" checkreturn="true" passthru="true">
6+
<arg value="--ansi"/>
7+
<arg value="update"/>
8+
</exec>
9+
<exec executable="npm" checkreturn="true" passthru="true">
10+
<arg value="--ansi"/>
11+
<arg value="update"/>
12+
</exec>
13+
14+
<phing phingfile="build.xml" target="outdated" haltonfailure="true"/>
15+
</target>
16+
17+
<!-- Show outdated dependencies -->
18+
<target name="outdated">
19+
<exec executable="composer" checkreturn="true" passthru="true">
20+
<arg value="--ansi"/>
21+
<arg value="outdated"/>
22+
<arg value="--direct"/>
23+
</exec>
1024
</target>
1125

1226
<!-- Runs all unit tests -->
1327
<target name="unit">
14-
<exec command="bin/phpunit --bootstrap=test/bootstrap.php test" passthru="true" checkreturn="true"/>
28+
<exec executable="bin/phpunit" passthru="true" checkreturn="true"/>
1529
</target>
30+
31+
<target name="build"/>
1632
</project>

composer.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@
99
"fix"
1010
],
1111
"require": {
12-
"php": ">=7.3"
12+
"php": ">=8.1",
13+
"ext-mbstring": "*"
1314
},
15+
"minimum-stability": "dev",
16+
"prefer-stable": true,
1417
"require-dev": {
15-
"phpunit/phpunit": "^6.0.0",
16-
"phing/phing": "^2.0"
18+
"phing/phing": "^3.0.0-RC4",
19+
"phpunit/phpunit": "^9.6.3"
1720
},
1821
"autoload": {
1922
"psr-4": {
20-
"SetBased\\ErdConcepts\\": "src"
23+
"SetBased\\ErdConcepts\\": "src/"
2124
}
2225
},
2326
"autoload-dev": {
2427
"psr-4": {
25-
"SetBased\\ErdConcepts\\": "src"
28+
"SetBased\\ErdConcepts\\": "test/"
2629
}
2730
},
2831
"config": {
29-
"bin-dir": "bin"
32+
"bin-dir": "bin",
33+
"sort-packages": true,
34+
"allow-plugins": {
35+
"phing/phing-composer-configurator": true
36+
}
3037
}
3138
}

phpunit.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">src</directory>
6+
</include>
7+
<exclude>
8+
<directory suffix=".php">vendor/setbased</directory>
9+
</exclude>
10+
<report>
11+
<clover outputFile="test/coverage.xml"/>
12+
<html outputDirectory="test/report"/>
13+
</report>
14+
</coverage>
15+
<testsuites>
16+
<testsuite name="Tests">
17+
<directory>test</directory>
18+
</testsuite>
19+
</testsuites>
20+
<logging/>
21+
</phpunit>

src/MySqlFix.php

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//----------------------------------------------------------------------------------------------------------------------
33
namespace SetBased\ErdConcepts;
44

5-
//----------------------------------------------------------------------------------------------------------------------
65
/**
76
* Class for fixing issues in SQL code generated by ERD Concepts with MySQL as target database.
87
*/
@@ -18,24 +17,24 @@ class MySqlFix
1817
/**
1918
* Add comments to column definitions based on commented comments.
2019
*
21-
* @param string $theSourceCode The SQL code generated by ERD concepts.
20+
* @param string $source The SQL code generated by ERD concepts.
2221
*
2322
* @return string
2423
*/
25-
public static function fixColumnComments($theSourceCode)
24+
public static function fixColumnComments(string $source): string
2625
{
27-
$source_lines = explode("\n", $theSourceCode);
26+
$lines = explode(PHP_EOL, $source);
2827

2928
// Map from (table_name,column_name) to line number
3029
$map = [];
3130

3231
// Scan the source for column definitions.
3332
$table_name = null;
34-
foreach ($source_lines as $i => $line)
33+
foreach ($lines as $i => $line)
3534
{
3635
if (isset($table_name))
3736
{
38-
if (preg_match('/^ (`?\w+`?)/', $source_lines[$i], $matches))
37+
if (preg_match('/^ (`?\w+`?)/', $line, $matches))
3938
{
4039
$map[$table_name][$matches[1]] = $i;
4140
}
@@ -53,32 +52,32 @@ public static function fixColumnComments($theSourceCode)
5352

5453
// Scan the source for comments.
5554
$comments = [];
56-
foreach ($source_lines as $i => $line)
55+
foreach ($lines as $i => $line)
5756
{
5857
if (preg_match('/^COMMENT ON COLUMN (`?\w+`?).(`?\w+`?)/', $line, $matches))
5958
{
60-
$comments[$matches[1]][$matches[2]] = trim($source_lines[$i + 1]);
59+
$comments[$matches[1]][$matches[2]] = trim($lines[$i + 1]);
6160
}
6261
}
6362

6463
// Enhance the column definitions with comments.
65-
foreach ($comments as $table_name => $columns)
64+
foreach ($comments as $tableName => $columns)
6665
{
67-
if (!isset($map[$table_name]))
66+
if (!isset($map[$tableName]))
6867
{
69-
throw new \RuntimeException(sprintf("Table '%s' is not defined.", $table_name));
68+
throw new \RuntimeException(sprintf("Table '%s' is not defined.", $tableName));
7069
}
7170

72-
foreach ($columns as $column_name => $comment)
71+
foreach ($columns as $columnName => $comment)
7372
{
74-
if (!isset($map[$table_name][$column_name]))
73+
if (!isset($map[$tableName][$columnName]))
7574
{
7675
throw new \RuntimeException(sprintf("Column '%s' is not defined in '%s' table statements.",
77-
$column_name,
78-
$table_name));
76+
$columnName,
77+
$tableName));
7978
}
8079

81-
$line_number = $map[$table_name][$column_name];
80+
$line_number = $map[$tableName][$columnName];
8281

8382
// Truncate comments longer than 60 characters.
8483
if (strlen($comment)>self::MAX_COLUMN_COMMENT_LENGTH)
@@ -87,35 +86,33 @@ public static function fixColumnComments($theSourceCode)
8786
}
8887

8988
// Enhance the column definition with comment.
90-
$source_lines[$line_number] = mb_substr(rtrim($source_lines[$line_number]), 0, -1);
91-
$source_lines[$line_number] .= " COMMENT '".self::escapeMysqlString($comment)."',";
89+
$lines[$line_number] = mb_substr(rtrim($lines[$line_number]), 0, -1);
90+
$lines[$line_number] .= " COMMENT '".self::escapeMysqlString($comment)."',";
9291
}
9392
}
9493

95-
$new_source_code = implode("\n", $source_lines);
96-
97-
return $new_source_code;
94+
return implode(PHP_EOL, $lines);
9895
}
9996

10097

10198
//--------------------------------------------------------------------------------------------------------------------
10299
/**
103100
* Add comments to index definitions based on commented comments.
104101
*
105-
* @param string $theSourceCode The SQL code generated by ERD concepts.
102+
* @param string $source The SQL code generated by ERD concepts.
106103
*
107104
* @return string
108105
*/
109-
public static function fixIndexComments($theSourceCode)
106+
public static function fixIndexComments(string $source): string
110107
{
111-
$source_lines = explode("\n", $theSourceCode);
108+
$lines = explode(PHP_EOL, $source);
112109

113110
// Map from (table_name,column_name) to line number
114111
$map = [];
115112

116113
// Scan the source for column definitions.
117114
$index_name = null;
118-
foreach ($source_lines as $i => $line)
115+
foreach ($lines as $i => $line)
119116
{
120117
if (preg_match('/^CREATE INDEX (`?\w+`?)(\s*\()?/', $line, $matches))
121118
{
@@ -125,23 +122,23 @@ public static function fixIndexComments($theSourceCode)
125122

126123
// Scan the source for comments.
127124
$comments = [];
128-
foreach ($source_lines as $i => $line)
125+
foreach ($lines as $i => $line)
129126
{
130127
if (preg_match('/^COMMENT ON INDEX (`?\w+`?)/', $line, $matches))
131128
{
132-
$comments[$matches[1]] = trim($source_lines[$i + 1]);
129+
$comments[$matches[1]] = trim($lines[$i + 1]);
133130
}
134131
}
135132

136133
// Enhance the column definitions with comments.
137-
foreach ($comments as $index_name => $comment)
134+
foreach ($comments as $indexName => $comment)
138135
{
139-
if (!isset($map[$index_name]))
136+
if (!isset($map[$indexName]))
140137
{
141-
throw new \RuntimeException(sprintf("Table '%s' is not defined.", $index_name));
138+
throw new \RuntimeException(sprintf("Table '%s' is not defined.", $indexName));
142139
}
143140

144-
$line_number = $map[$index_name];
141+
$lineNumber = $map[$indexName];
145142

146143
// Truncate comments longer than 60 characters.
147144
if (strlen($comment)>self::MAX_COLUMN_COMMENT_LENGTH)
@@ -150,42 +147,45 @@ public static function fixIndexComments($theSourceCode)
150147
}
151148

152149
// Enhance the column definition with comment.
153-
$source_lines[$line_number] = mb_substr(rtrim($source_lines[$line_number]), 0, -1);
154-
$source_lines[$line_number] .= " COMMENT '".self::escapeMysqlString($comment)."';";
150+
$lines[$lineNumber] = mb_substr(rtrim($lines[$lineNumber]), 0, -1);
151+
$lines[$lineNumber] .= " COMMENT '".self::escapeMysqlString($comment)."';";
155152
}
156153

157-
$new_source_code = implode("\n", $source_lines);
158-
159-
160-
return $new_source_code;
154+
return implode(PHP_EOL, $lines);
161155
}
162156

163157
//--------------------------------------------------------------------------------------------------------------------
164158
/**
165159
* Add comments to table definitions based on commented comments.
166160
*
167-
* @param string $theSourceCode The SQL code generated by ERD concepts.
161+
* @param string $source The SQL code generated by ERD concepts.
168162
*
169163
* @return string
170164
*/
171-
public static function fixTableComments($theSourceCode)
165+
public static function fixTableComments(string $source): string
172166
{
173-
$source_lines = explode("\n", $theSourceCode);
167+
$lines = explode(PHP_EOL, $source);
174168

175169
// Map from (table_name,column_name) to line number
176170
$map = [];
177171

178172
// Scan the source for column definitions.
179173
$table_name = null;
180174
$level = 0;
181-
foreach ($source_lines as $i => $line)
175+
foreach ($lines as $i => $line)
182176
{
183177
if (isset($table_name))
184178
{
185-
if (preg_match('/\)|\(/', $source_lines[$i], $matches))
179+
if (preg_match('/\)|\(/', $line, $matches))
186180
{
187-
if ($matches[0]=='(') $level = +1;
188-
if ($matches[0]==')') $level = -1;
181+
if ($matches[0]=='(')
182+
{
183+
$level = +1;
184+
}
185+
if ($matches[0]==')')
186+
{
187+
$level = -1;
188+
}
189189

190190
if ($level<0)
191191
{
@@ -198,17 +198,20 @@ public static function fixTableComments($theSourceCode)
198198
if ($table_name===null && preg_match('/^CREATE TABLE (`?\w+`?)(\s*\()?/', $line, $matches))
199199
{
200200
$table_name = $matches[1];
201-
if ($matches[2]) $level = 1;
201+
if ($matches[2])
202+
{
203+
$level = 1;
204+
}
202205
}
203206
}
204207

205208
// Scan the source for comments.
206209
$comments = [];
207-
foreach ($source_lines as $i => $line)
210+
foreach ($lines as $i => $line)
208211
{
209212
if (preg_match('/^COMMENT ON TABLE (`?\w+`?)/', $line, $matches))
210213
{
211-
$comments[$matches[1]] = trim($source_lines[$i + 1]);
214+
$comments[$matches[1]] = trim($lines[$i + 1]);
212215
}
213216
}
214217

@@ -229,29 +232,26 @@ public static function fixTableComments($theSourceCode)
229232
}
230233

231234
// Enhance the column definition with comment.
232-
$source_lines[$line_number] = mb_substr(rtrim($source_lines[$line_number]), 0, -1);
233-
$source_lines[$line_number] .= " COMMENT '".self::escapeMysqlString($comment)."';";
235+
$lines[$line_number] = mb_substr(rtrim($lines[$line_number]), 0, -1);
236+
$lines[$line_number] .= " COMMENT '".self::escapeMysqlString($comment)."';";
234237
}
235238

236-
$new_source_code = implode("\n", $source_lines);
237-
238-
239-
return $new_source_code;
239+
return implode(PHP_EOL, $lines);
240240
}
241241

242242
//--------------------------------------------------------------------------------------------------------------------
243243
/**
244244
* Escapes special characters in a string for use in an SQL statement.
245245
*
246-
* @param string $unescaped_string The string that is to be escaped.
246+
* @param string $string The string that is to be escaped.
247247
*
248248
* @return string
249249
*/
250-
protected static function escapeMysqlString($unescaped_string)
250+
protected static function escapeMysqlString(string $string): string
251251
{
252252
// We prefer to use mysqli::escape_string but this method requires a connection. Since ERD Concepts generates
253253
// SQL code in UTF-8 and $unescaped_string is not user input (from the evil internet) we can safely use addslashes.
254-
return addslashes($unescaped_string);
254+
return addslashes($string);
255255
}
256256

257257
//--------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)