Skip to content

Commit c603c42

Browse files
committed
Upgraded to PHP 8, including parameter and return types
1 parent 56b77a7 commit c603c42

22 files changed

+2446
-836
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ jobs:
2828
- uses: actions/checkout@v5
2929
with:
3030
persist-credentials: false
31-
- name: Set up PHP 7.4
31+
- name: Set up PHP 8.0
3232
uses: shivammathur/setup-php@v2
3333
with:
34-
php-version: '7.4'
34+
php-version: '8.0'
3535
coverage: xdebug
3636
tools: phpstan
3737
- name: Cache Composer packages
@@ -47,21 +47,17 @@ jobs:
4747
- name: PHPStan
4848
run: phpstan analyse
4949

50-
test:
50+
phpcs:
5151
runs-on: ubuntu-latest
52-
strategy:
53-
matrix:
54-
# PHP Unit 4.x is needed for PHP 5.4 but is not supported on PHP 8.x
55-
php: [5.4, 5.6, 7.0, 7.4]
56-
fail-fast: false
5752
steps:
5853
- uses: actions/checkout@v5
5954
with:
6055
persist-credentials: false
61-
- uses: shivammathur/setup-php@v2
56+
- name: Set up PHP 8.0
57+
uses: shivammathur/setup-php@v2
6258
with:
63-
php-version: ${{matrix.php}}
64-
coverage: xdebug
59+
php-version: '8.0'
60+
tools: phpcs
6561
- name: Cache Composer packages
6662
id: composer-cache
6763
uses: actions/cache@v4
@@ -72,12 +68,10 @@ jobs:
7268
${{ runner.os }}-php-
7369
- name: Install dependencies
7470
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
75-
- name: PHP Unit
76-
run: |
77-
echo '{}' | jq '.http.upload.skip |= true' > tests/config.json
78-
vendor/bin/phpunit tests
71+
- name: PHPCS
72+
run: phpcs src
7973

80-
test-php8:
74+
test:
8175
runs-on: ubuntu-latest
8276
strategy:
8377
matrix:
@@ -87,23 +81,6 @@ jobs:
8781
- uses: actions/checkout@v5
8882
with:
8983
persist-credentials: false
90-
fetch-depth: 0
91-
- name: Rebase PHP8 branch
92-
env:
93-
USER_EMAIL: ${{ github.event.pusher.email }}
94-
USER_NAME: ${{ github.event.pusher.name }}
95-
REBASE_TARGET: ${{ github.head_ref || github.ref_name }}
96-
run: |
97-
git config user.email "$USER_EMAIL"
98-
git config user.name "$USER_NAME"
99-
git pull
100-
git checkout php8
101-
git rebase "$REBASE_TARGET" php8
102-
git status
103-
echo 'diff origin/php8:'
104-
git diff origin/php8
105-
echo 'diff current:'
106-
git diff "$REBASE_TARGET"
10784
- uses: shivammathur/setup-php@v2
10885
with:
10986
php-version: ${{matrix.php}}
@@ -115,37 +92,10 @@ jobs:
11592
path: vendor
11693
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
11794
restore-keys: |
118-
${{ runner.os }}-php8-
95+
${{ runner.os }}-php-
11996
- name: Install dependencies
12097
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
12198
- name: PHP Unit
12299
run: |
123100
echo '{}' | jq '.http.upload.skip |= true' > tests/config.json
124101
vendor/bin/phpunit tests
125-
126-
rebase-php8:
127-
runs-on: ubuntu-latest
128-
needs: test-php8
129-
if: github.ref_name == 'master'
130-
permissions:
131-
contents: write
132-
steps:
133-
- uses: actions/checkout@v5
134-
with:
135-
ref: php8
136-
fetch-depth: 0
137-
- name: Rebase PHP8 branch
138-
env:
139-
USER_EMAIL: ${{ github.event.pusher.email }}
140-
USER_NAME: ${{ github.event.pusher.name }}
141-
run: |
142-
git config user.email "$USER_EMAIL"
143-
git config user.name "$USER_NAME"
144-
git pull
145-
git rebase origin/master php8
146-
git status
147-
echo 'diff origin/php8:'
148-
git diff origin/php8
149-
echo 'diff master:'
150-
git diff origin/master
151-
git push --force-with-lease

.github/workflows/http-upload-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
persist-credentials: false
3131
- uses: shivammathur/setup-php@v2
3232
with:
33-
php-version: '7.4'
33+
php-version: '8.0'
3434
coverage: xdebug
3535
- name: Cache Composer packages
3636
id: composer-cache

.github/workflows/release-site.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,8 @@ jobs:
2828
- uses: actions/checkout@v5
2929
with:
3030
persist-credentials: false
31-
- name: Set up PHP
32-
uses: shivammathur/setup-php@v2
33-
with:
34-
# highest version to support apigen/apigen
35-
php-version: '7.1'
36-
- name: Install apigen
37-
run: composer global require apigen/apigen
3831
- name: Generate API
39-
run: apigen generate -s src -d docs
32+
run: mkdir -p docs && docker run --rm -v "$GITHUB_WORKSPACE/code:/workspace" -w /workspace -u `id -u`:`id -g` apigen/apigen
4033
- uses: actions/upload-artifact@v4
4134
with:
4235
name: docs

.github/workflows/sonarcloud.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ jobs:
3131
- uses: actions/checkout@v5
3232
with:
3333
fetch-depth: 0
34-
- name: Set up PHP 7.4
34+
- name: Set up PHP 8.0
3535
uses: shivammathur/setup-php@v2
3636
with:
37-
php-version: '7.4'
37+
php-version: '8.0'
3838
coverage: xdebug
3939
- name: Cache Composer packages
4040
id: composer-cache

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/composer.lock
21
/vendor/
3-
/.buildpath
4-
/.project
5-
/.settings
2+
/docs/
3+
4+
/.phpunit.cache
5+
.phpunit.result.cache
6+
67
tests/config.json

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ To send a multipart object with a cURL request, you need to follow some steps:
114114

115115
* Set the request type using `CURLOPT_CUSTOMREQUEST`.
116116
* Set the `CURLOPT_UPLOAD` option to `true`.
117-
* Set the object's `curl_read` method as the `CURLOPT_READFUNCTION`.
117+
* Set the object's `curlRead` method as the `CURLOPT_READFUNCTION`.
118118
* Make sure the `Content-Type` and `Content-Length` headers are set. Note that the `Content-Length` header is optional.
119119

120120
For instance:
121121

122122
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
123123
curl_setopt($ch, CURLOPT_UPLOAD, true);
124-
curl_setopt($ch, CURLOPT_READFUNCTION, array($multipart, 'curl_read'));
124+
curl_setopt($ch, CURLOPT_READFUNCTION, array($multipart, 'curlRead'));
125125

126126
$headers = ['Content-Type: ' . $multipart->getContentType()];
127127
$contentLength = $multipart->getContentLength();
@@ -132,6 +132,6 @@ For instance:
132132

133133
## Non-streaming support
134134

135-
If streaming is not possible (e.g. because a string is required, like in the `mail` function), you can buffer a multipart object in-memory by calling the `buffer` method. This method takes an optional buffer size, and returns the buffered contents. The content length will be set accordingly. Note that you should do this before calling `read` (or `curl_read`), otherwise the buffered contents may not contain all desired contents (especially if you're using resources or callables).
135+
If streaming is not possible (e.g. because a string is required, like in the `mail` function), you can buffer a multipart object in-memory by calling the `buffer` method. This method takes an optional buffer size, and returns the buffered contents. The content length will be set accordingly. Note that you should do this before calling `read` (or `curlRead`), otherwise the buffered contents may not contain all desired contents (especially if you're using resources or callables).
136136

137137
`Multipart.__toString()` has been overridden to buffer the multipart object as well, so you can achieve the same by casting a multipart object to `string`. The difference is that `buffer` requires the multipart object to be finished.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"issues": "https://github.com/robtimus/php-multipart/issues"
1616
},
1717
"require": {
18-
"php": ">=5.4"
18+
"php": ">=8.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "~4"
21+
"phpunit/phpunit": "~9"
2222
},
2323
"autoload": {
2424
"psr-4": {

0 commit comments

Comments
 (0)