Skip to content

Commit d1ac84a

Browse files
authored
Modernize codebase for PHP 8 (#100)
1 parent 1f85545 commit d1ac84a

17 files changed

+173
-327
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "Coding Standards"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*.x"
7+
push:
8+
branches:
9+
- "*.x"
10+
11+
jobs:
12+
coding-standards:
13+
name: "Coding Standards"
14+
uses: "doctrine/.github/.github/workflows/[email protected]"
Lines changed: 7 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: "Continuous Integration"
32

43
on:
@@ -9,125 +8,11 @@ on:
98
branches:
109
- "*.x"
1110

12-
env:
13-
fail-fast: true
14-
1511
jobs:
16-
17-
unit-tests:
18-
name: "Unit tests"
19-
runs-on: "ubuntu-20.04"
20-
21-
strategy:
22-
matrix:
23-
php-version:
24-
- "7.2"
25-
- "7.3"
26-
- "7.4"
27-
- "8.0"
28-
- "8.1"
29-
30-
steps:
31-
- name: "Checkout code"
32-
uses: "actions/checkout@v4"
33-
34-
- name: "Install PHP"
35-
uses: "shivammathur/setup-php@v2"
36-
with:
37-
coverage: "none"
38-
php-version: "${{ matrix.php-version }}"
39-
tools: "cs2pr"
40-
41-
- name: "Install dependencies with Composer"
42-
uses: "ramsey/composer-install@v3"
43-
with:
44-
dependency-versions: "highest"
45-
46-
- name: "Test fixes"
47-
run: "vendor/bin/phpunit --coverage-text"
48-
49-
static-analysis-phpstan:
50-
name: "Static Analysis with PHPStan"
51-
runs-on: "ubuntu-20.04"
52-
53-
strategy:
54-
matrix:
55-
php-version:
56-
- "7.4"
57-
58-
steps:
59-
- name: "Checkout code"
60-
uses: "actions/checkout@v4"
61-
62-
- name: "Install PHP"
63-
uses: "shivammathur/setup-php@v2"
64-
with:
65-
coverage: "none"
66-
php-version: "${{ matrix.php-version }}"
67-
extensions: "mbstring"
68-
tools: "cs2pr"
69-
70-
- name: "Install dependencies with Composer"
71-
uses: "ramsey/composer-install@v3"
72-
with:
73-
dependency-versions: "highest"
74-
75-
- name: "Run a static analysis with phpstan/phpstan"
76-
run: "vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr"
77-
78-
79-
static-analysis-psalm:
80-
name: "Static Analysis with Psalm"
81-
runs-on: "ubuntu-20.04"
82-
83-
strategy:
84-
matrix:
85-
php-version:
86-
- "7.4"
87-
88-
steps:
89-
- name: "Checkout code"
90-
uses: "actions/checkout@v4"
91-
92-
- name: "Install PHP"
93-
uses: "shivammathur/setup-php@v2"
94-
with:
95-
coverage: "none"
96-
php-version: "${{ matrix.php-version }}"
97-
98-
- name: "Install dependencies with Composer"
99-
uses: "ramsey/composer-install@v3"
100-
with:
101-
dependency-versions: "highest"
102-
103-
- name: "Run a static analysis with vimeo/psalm"
104-
run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=4"
105-
106-
coding-standards:
107-
name: "Coding Standards"
108-
runs-on: "ubuntu-20.04"
109-
110-
strategy:
111-
matrix:
112-
php-version:
113-
- "7.4"
114-
115-
steps:
116-
- name: "Checkout"
117-
uses: "actions/checkout@v4"
118-
119-
- name: "Install PHP"
120-
uses: "shivammathur/setup-php@v2"
121-
with:
122-
coverage: "none"
123-
php-version: "${{ matrix.php-version }}"
124-
tools: "cs2pr"
125-
126-
- name: "Install dependencies with Composer"
127-
uses: "ramsey/composer-install@v3"
128-
with:
129-
dependency-versions: "highest"
130-
131-
# Remove -q when updating to phpcs v4
132-
- name: "Run squizlabs/php_codesniffer"
133-
run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr"
12+
phpunit:
13+
name: "PHPUnit"
14+
uses: "doctrine/.github/.github/workflows/[email protected]"
15+
with:
16+
php-versions: '["8.1", "8.2", "8.3"]'
17+
secrets:
18+
CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: "Static Analysis"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*.x"
7+
push:
8+
branches:
9+
- "*.x"
10+
11+
jobs:
12+
static-analysis:
13+
name: "Static Analysis"
14+
uses: "doctrine/.github/.github/workflows/[email protected]"

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/.phpunit.result.cache
1+
/.phpunit.cache
22
/.phpcs-cache
3-
vendor/
3+
/vendor
44
/composer.lock

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"license": "MIT",
77
"type": "library",
88
"require": {
9-
"php": "^7.2 || ^8.0"
9+
"php": "^8.1"
1010
},
1111
"require-dev": {
12-
"doctrine/coding-standard": "^9.0",
13-
"phpstan/phpstan": "^1.0",
14-
"phpunit/phpunit": "^8.5 || ^9.6",
15-
"vimeo/psalm": "^4.11"
12+
"doctrine/coding-standard": "^12",
13+
"phpstan/phpstan": "^1.10",
14+
"phpunit/phpunit": "^10.5",
15+
"vimeo/psalm": "^5.24"
1616
},
1717
"authors": [
1818
{

examples/examples.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
Usage:
155155
<pre>
156156
<?php highlight_string(
157-
'<?php' . "\n" . '$formatted = (new SqlFormatter())->format($sql);' . "\n" . '?>'
157+
'<?php' . "\n" . '$formatted = (new SqlFormatter())->format($sql);' . "\n" . '?>',
158158
); ?>
159159
</pre>
160160
</div>
@@ -195,7 +195,7 @@
195195
<pre><?= $sql; ?></pre>
196196
</td>
197197
<td><pre><?= htmlentities((new SqlFormatter(
198-
new NullHighlighter()
198+
new NullHighlighter(),
199199
))->format($sql)); ?></pre></td>
200200
</tr>
201201
<?php endforeach ?>
@@ -208,7 +208,7 @@
208208
Usage:
209209
<pre>
210210
<?php highlight_string(
211-
'<?php' . "\n" . '$highlighted = (new SqlFormatter())->highlight($sql);' . "\n" . '?>'
211+
'<?php' . "\n" . '$highlighted = (new SqlFormatter())->highlight($sql);' . "\n" . '?>',
212212
); ?>
213213
</pre>
214214
</div>
@@ -234,7 +234,7 @@
234234
Usage:
235235
<pre>
236236
<?php highlight_string(
237-
'<?php' . "\n" . '$compressed = (new SqlFormatter())->compress($sql);' . "\n" . '?>'
237+
'<?php' . "\n" . '$compressed = (new SqlFormatter())->compress($sql);' . "\n" . '?>',
238238
); ?>
239239
</pre>
240240
</div>

phpcs.xml.dist

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@
77

88
<arg name="basepath" value="."/>
99
<arg name="extensions" value="php"/>
10+
<arg name="parallel" value="80"/>
1011
<arg name="cache" value=".phpcs-cache"/>
1112
<arg name="colors" />
1213

13-
<!-- Show progress of the run -->
14-
<arg value="p"/>
14+
<!-- Ignore warnings, show progress of the run and show sniff names -->
15+
<arg value="nps"/>
16+
17+
<config name="php_version" value="80100"/>
1518

1619
<rule ref="Doctrine"/>
1720

1821
<file>examples</file>
1922
<file>src</file>
2023
<file>tests</file>
2124

22-
<!-- Disable the rules that will require PHP 7.4 -->
23-
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
24-
<properties>
25-
<property name="enableNativeTypeHint" value="false"/>
26-
</properties>
27-
</rule>
28-
2925
<rule ref="Generic.Files.InlineHTML">
3026
<exclude-pattern>examples/*.php</exclude-pattern>
3127
<exclude-pattern>tests/performance.php</exclude-pattern>

phpunit.xml.dist

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.0/phpunit.xsd"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
55
bootstrap="vendor/autoload.php"
66
executionOrder="depends,defects"
7-
forceCoversAnnotation="true"
8-
beStrictAboutCoversAnnotation="true"
97
beStrictAboutOutputDuringTests="true"
10-
beStrictAboutTodoAnnotatedTests="true"
118
colors="true"
12-
verbose="true">
9+
cacheDirectory=".phpunit.cache"
10+
requireCoverageMetadata="true"
11+
beStrictAboutCoverageMetadata="true"
12+
>
1313
<testsuites>
1414
<testsuite name="default">
1515
<directory suffix="Test.php">tests</directory>
1616
</testsuite>
1717
</testsuites>
1818

19-
<filter>
20-
<whitelist processUncoveredFilesFromWhitelist="true">
19+
<source>
20+
<include>
2121
<directory suffix=".php">src</directory>
22-
</whitelist>
23-
</filter>
22+
</include>
23+
</source>
2424
</phpunit>

psalm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<psalm
33
errorLevel="5"
44
resolveFromConfigFile="true"
5+
findUnusedBaselineEntry="true"
6+
findUnusedCode="false"
57
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
68
xmlns="https://getpsalm.org/schema/config"
79
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

src/CliHighlighter.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ final class CliHighlighter implements Highlighter
1313
public const HIGHLIGHT_FUNCTIONS = 'functions';
1414

1515
/** @var array<string, string> */
16-
private $escapeSequences;
16+
private array $escapeSequences;
1717

18-
/**
19-
* @param array<string, string> $escapeSequences
20-
*/
18+
/** @param array<string, string> $escapeSequences */
2119
public function __construct(array $escapeSequences = [])
2220
{
2321
$this->escapeSequences = $escapeSequences + [
@@ -48,7 +46,7 @@ public function highlightToken(int $type, string $value): string
4846
return $prefix . $value . "\x1b[0m";
4947
}
5048

51-
private function prefix(int $type): ?string
49+
private function prefix(int $type): string|null
5250
{
5351
if (! isset(self::TOKEN_TYPE_TO_HIGHLIGHT[$type])) {
5452
return null;
@@ -64,7 +62,7 @@ public function highlightError(string $value): string
6462
PHP_EOL,
6563
$this->escapeSequences[self::HIGHLIGHT_ERROR],
6664
$value,
67-
"\x1b[0m"
65+
"\x1b[0m",
6866
);
6967
}
7068

0 commit comments

Comments
 (0)