Skip to content

Commit 73bbefc

Browse files
authored
format all pure PHP files with prettier (#338)
1 parent c88b831 commit 73bbefc

File tree

88 files changed

+2123
-1505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2123
-1505
lines changed

.github/workflows/phpunit.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ jobs:
99
docker-compose-phpunit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
13-
with:
14-
submodules: true
15-
- name: setup PHP
16-
uses: shivammathur/setup-php@v2
17-
with:
18-
php-version: "8.3"
19-
tools: composer
20-
- name: install composer dependencies
21-
run: composer update
22-
- name: Run docker compose
23-
uses: hoverkraft-tech/[email protected]
24-
with:
25-
compose-file: "./tools/docker-dev/docker-compose.yml"
26-
- name: Execute tests in the running services
27-
run: docker compose -f ./tools/docker-dev/docker-compose.yml exec -w '/var/www/unity-web-portal' web bash -c 'XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-clover="$(mktemp --suffix=.xml)" -d --min-coverage=./coverage.php'
12+
- uses: actions/checkout@v3
13+
with:
14+
submodules: true
15+
- uses: shivammathur/setup-php@v2
16+
with:
17+
php-version: "8.3"
18+
tools: composer
19+
- run: composer install --dev
20+
- uses: hoverkraft-tech/[email protected]
21+
with:
22+
compose-file: "./tools/docker-dev/docker-compose.yml"
23+
- run: docker compose -f ./tools/docker-dev/docker-compose.yml exec -w '/var/www/unity-web-portal' web bash -c 'XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-clover="$(mktemp --suffix=.xml)" -d --min-coverage=./coverage.php'

.github/workflows/pre-commit.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
13-
with:
14-
submodules: true
15-
- uses: actions/setup-python@v3
16-
- name: setup PHP
17-
uses: shivammathur/setup-php@v2
18-
with:
19-
php-version: "8.3"
20-
tools: composer, phpcs, phpcbf
21-
- uses: pre-commit/[email protected]
12+
- uses: actions/checkout@v3
13+
with:
14+
submodules: true
15+
- uses: actions/setup-python@v3
16+
- uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: "8.3"
19+
tools: composer
20+
- run: composer install --dev
21+
- uses: actions/[email protected]
22+
- run: npm install --dev
23+
- uses: pre-commit/[email protected]

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ deployment/**/*
2020
!deployment/**/README.md
2121

2222
.phpunit.result.cache
23+
24+
node_modules

.pre-commit-config.yaml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,64 @@ repos:
1111
hooks:
1212
- id: trailing-whitespace
1313
- id: end-of-file-fixer
14+
# https://github.com/prettier/plugin-php/issues/2430
15+
exclude: workers/.*
16+
17+
- repo: https://github.com/rbubley/mirrors-prettier
18+
rev: v3.4.2
19+
hooks:
20+
- id: prettier
21+
exclude: |
22+
(?x)^(
23+
composer\.json|
24+
composer\.lock|
25+
)$
1426
1527
- repo: local
1628
hooks:
1729
- id: phpcbf
1830
name: PHP Code Beautifier and Fixer
19-
entry: phpcbf
31+
entry: ./vendor/bin/phpcbf
32+
args: [--standard=./.phpcs-ruleset.xml, --colors]
2033
language: system
2134
files: \.php$
22-
args: [--standard=./.phpcs-ruleset.xml, --colors]
35+
# exclude pure PHP files
2336
exclude: |
2437
(?x)^(
2538
test/.*|
2639
workers/.*|
40+
node_modules/.*|
41+
resources/lib/phpopenldaper/.*|
42+
vendor/.*|
43+
resources/lib/.*|
44+
)$
45+
46+
- repo: local
47+
hooks:
48+
- id: prettier (php)
49+
name: prettier (php)
50+
entry: npx
51+
args:
52+
[
53+
-p,
54+
prettier,
55+
-p,
56+
"@prettier/plugin-php",
57+
prettier,
58+
--plugin=@prettier/plugin-php,
59+
--php-version=8.3,
60+
--write,
61+
]
62+
language: system
63+
files: \.php$
64+
# exclude impure PHP files
65+
exclude: |
66+
(?x)^(
67+
node_modules/.*|
68+
resources/lib/phpopenldaper/.*|
69+
vendor/.*|
70+
resources/templates/.*|
71+
webroot/.*|
2772
)$
2873
2974
# linters (work required) ########################################################################
@@ -45,14 +90,19 @@ repos:
4590
hooks:
4691
- id: phpcs
4792
name: PHP CodeSniffer
48-
entry: phpcs
93+
entry: ./vendor/bin/phpcs
4994
language: system
5095
files: \.php$
5196
args: [--standard=./.phpcs-ruleset.xml, --colors]
97+
# exclude pure PHP files
5298
exclude: |
5399
(?x)^(
54100
test/.*|
55101
workers/.*|
102+
node_modules/.*|
103+
resources/lib/phpopenldaper/.*|
104+
vendor/.*|
105+
resources/lib/.*|
56106
)$
57107
- id: php-l
58108
name: php -l

CONTRIBUTING.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22

33
## Conventions
44

5-
* PHP version 8.3.
6-
* All files are required to be linted with PSR-12 standard.
7-
* The maximum line length for any PHP file is 100 characters, instead of PSR-12's 120 characters.
8-
* Comments should be used sparingly.
9-
* Empty lines should be used sparingly.
10-
* No code should fail quietly, instead exceptions should be thrown.
5+
- PHP version 8.3.
6+
- All pure PHP files are required to be formatted with Prettier.
7+
- All impure PHP files (mixed into HTML) are required to be linted with PSR-12 and formatted with `phpcbf`.
8+
- The maximum line length for any PHP file is 100 characters.
9+
- Comments should be used sparingly.
10+
- Empty lines should be used sparingly.
11+
- No code should fail quietly, instead exceptions should be thrown.
1112
PHP builtin functions that fail quietly (ex: `json_encode`) should be replaced with a wrapper in `resources/utils.php`.
12-
* No code should call `die()` or `exit()`, instead `UnityHTTPD::die()`.
13+
- No code should call `die()` or `exit()`, instead `UnityHTTPD::die()`.
1314
This will avoid the premature death of our automated testing processes.
14-
* No code should call `assert()`, instead `\ensure()`.
15+
- No code should call `assert()`, instead `\ensure()`.
1516
This will enforce conditions even in production.
16-
* No code should call `json_encode()`, instead `\jsonEncode()`.
17+
- No code should call `json_encode()`, instead `\jsonEncode()`.
1718
This will throw errors and escape slashes by default.
18-
* No code should call `mb_convert_encoding()`, instead `\mbConvertEncoding()`.
19+
- No code should call `mb_convert_encoding()`, instead `\mbConvertEncoding()`.
1920
This will throw an exception rather than returning `false`.
20-
* No code should call `mb_detect_encoding()`, instead `\mbDetectEncoding()`.
21+
- No code should call `mb_detect_encoding()`, instead `\mbDetectEncoding()`.
2122
This will enable strict mode and throw an exception rather than returning `false`.
22-
* `UnityHTTPD`'s user-facing error functionality (ex: `badRequest`) should only be called from `webroot/**/*.php`.
23+
- `UnityHTTPD`'s user-facing error functionality (ex: `badRequest`) should only be called from `webroot/**/*.php`.
2324
`resources/**/*.php` should throw exceptions instead.
2425

2526
This repository will automatically check PRs for linting compliance.
@@ -29,6 +30,7 @@ This repository will automatically check PRs for linting compliance.
2930
### Setting up your Environment
3031

3132
1. Clone this repo (including submodules): `git clone <this-repo> --recurse-submodules`
33+
1. Install php v8.3
3234
1. install [composer](https://getcomposer.org/)
3335
1. install PHP dependencies: `composer update`
3436
1. If you're on Windows, use [WSL](https://learn.microsoft.com/en-us/windows/wsl/)
@@ -38,15 +40,17 @@ This repository will automatically check PRs for linting compliance.
3840
1. Install [pre-commit](https://pre-commit.com/)
3941
1. setup pre-commit hooks: `pre-commit install`
4042
1. Install modern implementation of grep (not macOS builtin grep): `brew install grep`
43+
1. Install `npm`
44+
1. Install nodeJS tools: `npm install`
4145

4246
### Environment Usage
4347

4448
While the environment is running, the following is accessible:
4549

46-
* http://127.0.0.1:8000 - Web Portal
47-
* http://127.0.0.1:8010 - PHPLDAPAdmin Portal
48-
* http://127.0.0.1:8020 - PHPMyAdmin Portal
49-
* http://127.0.0.1:8030 - Mailcatcher Portal
50+
- http://127.0.0.1:8000 - Web Portal
51+
- http://127.0.0.1:8010 - PHPLDAPAdmin Portal
52+
- http://127.0.0.1:8020 - PHPMyAdmin Portal
53+
- http://127.0.0.1:8030 - Mailcatcher Portal
5054

5155
### Test Users
5256

@@ -55,9 +59,10 @@ When accessing locked down portions of the portal, you will be asked for a usern
5559
The password is always `password`. `tools/docker-dev/web/htpasswd` contains all valid usernames.
5660

5761
Notable users:
58-
* `[email protected]` - admin, PI
59-
* `[email protected]` - not admin, not PI
60-
* `[email protected]` - does not yet have an account
62+
63+
- `[email protected]` - admin, PI
64+
- `[email protected]` - not admin, not PI
65+
- `[email protected]` - does not yet have an account
6166

6267
### Changes to Dev Environment
6368

@@ -86,13 +91,15 @@ Once a user action has been taken, internal interfaces are used to verify the re
8691
To run `phpunit`, spawn 2 shells in differnt tabs:
8792

8893
tab 1:
94+
8995
```shell
9096
cd ./tools/docker-dev
9197
./build.sh
9298
./run.sh
9399
```
94100

95101
tab 2:
102+
96103
```
97104
$ container="$(docker container ls | grep web | awk '{print $1}')"
98105
$ docker exec -it "$container" bash
@@ -138,6 +145,7 @@ When writing a test, it may be tempting to use the PHP API directly, but the HTT
138145
Example:
139146

140147
using the PHP API:
148+
141149
```php
142150
private function requestGroupCreation()
143151
{
@@ -146,6 +154,7 @@ private function requestGroupCreation()
146154
```
147155

148156
using the HTTP API:
157+
149158
```php
150159
private function requestGroupCreation()
151160
{

0 commit comments

Comments
 (0)