Skip to content

Commit 6681146

Browse files
committed
Upgrade to PHP 8.1 and higher.
1 parent a3450a8 commit 6681146

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

build.xml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project name="php-helper-code-store-php" default="build" basedir=".">
3-
<target name="build"/>
4-
5-
<!-- Run composer update -->
3+
<!-- Run composer update and executes various other updates -->
64
<target name="update">
7-
<exec command="composer update" checkreturn="true" passthru="true"/>
5+
<exec executable="composer" checkreturn="true" passthru="true">
6+
<arg value="--ansi"/>
7+
<arg value="update"/>
8+
</exec>
9+
10+
<phing phingfile="build.xml" target="outdated" haltonfailure="true"/>
11+
</target>
12+
13+
<!-- Show outdated packages -->
14+
<target name="outdated">
15+
<exec executable="composer" checkreturn="false" passthru="true">
16+
<arg value="--ansi"/>
17+
<arg value="outdated"/>
18+
<arg value="--direct"/>
19+
</exec>
820
</target>
921

1022
<!-- Runs all unit tests -->
1123
<target name="unit">
12-
<exec command="bin/phpunit test" passthru="true" checkreturn="true"/>
24+
<exec executable="bin/phpunit" passthru="true" checkreturn="true"/>
1325
</target>
14-
</project>
26+
27+
<target name="build" depends="update,unit"/>
28+
</project>

composer.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
"type": "library",
1010
"license": "MIT",
1111
"require": {
12-
"php": ">=7.4",
13-
"setbased/helper-code-store": "^2.3.1"
12+
"php": ">=8.1",
13+
"setbased/helper-code-store": "^2.4.0"
1414
},
15+
"minimum-stability": "dev",
16+
"prefer-stable": true,
1517
"require-dev": {
16-
"phpunit/phpunit": "^9.5.0",
17-
"phing/phing": "^2.16.3"
18+
"phing/phing": "^3.0.0-RC4",
19+
"phpunit/phpunit": "^9.5.28"
1820
},
1921
"autoload": {
2022
"psr-4": {
@@ -28,6 +30,9 @@
2830
},
2931
"config": {
3032
"bin-dir": "bin/",
31-
"sort-packages": true
33+
"sort-packages": true,
34+
"allow-plugins": {
35+
"phing/phing-composer-configurator": true
36+
}
3237
}
3338
}

src/Importing.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ class Importing
1414
*
1515
* @var array
1616
*/
17-
private $classes = [];
17+
private array $classes = [];
1818

1919
/**
2020
* The import statements.
2121
*
2222
* @var string[]
2323
*/
24-
private $imports;
24+
private array $imports;
2525

2626
/**
2727
* The namespace.
2828
*
2929
* @var string
3030
*/
31-
private $namespace;
31+
private string $namespace;
3232

3333
/**
34-
* The replace pairs from fully qualified name to imported name.
34+
* The replacement pairs from fully qualified name to imported name.
3535
*
3636
* @var array
3737
*/
38-
private $replace;
38+
private array $replace;
3939

4040
//--------------------------------------------------------------------------------------------------------------------
4141
/**
@@ -160,7 +160,7 @@ public function prepare(): void
160160

161161
//--------------------------------------------------------------------------------------------------------------------
162162
/**
163-
* Returns the replace pairs from fully qualified name to imported name.
163+
* Returns the replacement pairs from fully qualified name to imported name.
164164
*
165165
* @return array
166166
*/
@@ -186,7 +186,7 @@ public function simplyFullyQualifiedName(string $fullyQualifiedName): string
186186

187187
//--------------------------------------------------------------------------------------------------------------------
188188
/**
189-
* Returns true if and only if the a name space is the global or current namespace.
189+
* Returns whether a name space is the global or current namespace.
190190
*
191191
* @param string $namespace The namespace.
192192
*
@@ -270,7 +270,7 @@ private function prepare1(array $rawImports): void
270270

271271
//--------------------------------------------------------------------------------------------------------------------
272272
/**
273-
* Prepares the replace pairs.
273+
* Prepares the replacement pairs.
274274
*
275275
* @param array $rawImports The raw data about classes to import.
276276
*/

src/PhpCodeStore.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class PhpCodeStore extends CodeStore
1414
*
1515
* @var int[]
1616
*/
17-
private $defaultLevel = [];
17+
private array $defaultLevel = [];
1818

1919
/**
2020
* The heredoc identifier.
2121
*
2222
* @var string|null
2323
*/
24-
private $heredocIdentifier;
24+
private ?string $heredocIdentifier = null;
2525

2626
//--------------------------------------------------------------------------------------------------------------------
2727
/**
@@ -52,7 +52,7 @@ protected function indentationMode(string $line): int
5252

5353
$mode |= $this->indentationModeHeredoc($line);
5454
$mode |= $this->indentationModeSwitch($line);
55-
$mode |= $this->indentationModeBLock($line);
55+
$mode |= $this->indentationModeBlock($line);
5656

5757
return $mode;
5858
}
@@ -83,7 +83,7 @@ private function defaultLevelIncrement(): void
8383

8484
//--------------------------------------------------------------------------------------------------------------------
8585
/**
86-
* Returns true if the indent level of the current switch statement (if any) is zero. Otherwise, returns false.
86+
* Returns whether the indent level of the current switch statement (if any) is zero.
8787
*/
8888
private function defaultLevelIsZero(): bool
8989
{
@@ -104,14 +104,14 @@ private function indentationModeBlock(string $line): int
104104

105105
if ($this->heredocIdentifier!==null) return $mode;
106106

107-
if (substr($line, -1, 1)=='{')
107+
if (str_ends_with($line, '{'))
108108
{
109109
$mode |= self::C_INDENT_INCREMENT_AFTER;
110110

111111
$this->defaultLevelIncrement();
112112
}
113113

114-
if (substr($line, 0, 1)=='}')
114+
if (str_starts_with($line, '}'))
115115
{
116116
$this->defaultLevelDecrement();
117117

@@ -132,6 +132,7 @@ private function indentationModeBlock(string $line): int
132132

133133
//--------------------------------------------------------------------------------------------------------------------
134134
/**
135+
* Returns the indentation mode based on a line of code starting a heredoc.
135136
*
136137
* @param string $line The line of code.
137138
*
@@ -176,19 +177,19 @@ private function indentationModeSwitch(string $line): int
176177

177178
if ($this->heredocIdentifier!==null) return $mode;
178179

179-
if (substr($line, 0, 5)=='case ')
180+
if (str_starts_with($line, 'case '))
180181
{
181182
$mode |= self::C_INDENT_INCREMENT_AFTER;
182183
}
183184

184-
if (substr($line, 0, 8)=='default:')
185+
if (str_starts_with($line, 'default:'))
185186
{
186187
$this->defaultLevel[] = 0;
187188

188189
$mode |= self::C_INDENT_INCREMENT_AFTER;
189190
}
190191

191-
if (substr($line, 0, 6)=='break;')
192+
if (str_starts_with($line, 'break;'))
192193
{
193194
$mode |= self::C_INDENT_DECREMENT_AFTER;
194195
}

0 commit comments

Comments
 (0)