|
6 | 6 | - All PHP files are required to be linted with PSR-12 and formatted with `phpcbf`. |
7 | 7 | - Note: Some changes have been made to PSR-12, see `.phpcs-ruleset-pure.php` |
8 | 8 | - All pure PHP files are required to be formatted with Prettier as well as above. |
9 | | -- The maximum line length for any PHP file is 100 characters. |
| 9 | +- The maximum line length for any pure PHP file is 100 characters. |
10 | 10 | - Comments should be used sparingly. |
11 | 11 | - Empty lines should be used sparingly. |
12 | | -- No code should fail quietly, instead exceptions should be thrown. |
13 | | - PHP builtin functions that fail quietly (ex: `json_encode`) should be replaced with a wrapper in `resources/utils.php`. |
14 | 12 | - No code should call `die()` or `exit()`, instead `UnityHTTPD::die()`. |
15 | | - This will avoid the premature death of our automated testing processes. |
| 13 | + - This will avoid the premature death of our automated testing processes. |
16 | 14 | - No code should call `assert()`, instead `\ensure()`. |
17 | | - This will enforce conditions even in production. |
18 | | -- No code should call `json_encode()`, instead `\jsonEncode()`. |
19 | | - This will throw errors and escape slashes by default. |
20 | | -- No code should call `json_decode()`, instead `\jsonDecode()`. |
21 | | - This will throw an exception rather than returning `null`. |
22 | | -- No code should call `mb_convert_encoding()`, instead `\mbConvertEncoding()`. |
23 | | - This will throw an exception rather than returning `false`. |
24 | | -- No code should call `mb_detect_encoding()`, instead `\mbDetectEncoding()`. |
25 | | - This will enable strict mode and throw an exception rather than returning `false`. |
26 | | -- No code should call `intval()`, instead `\str2int()`. |
27 | | - This will enable strict mode and throw an exception rather than issuing a warning. |
| 15 | + - This will enforce conditions even in production. |
| 16 | +- No code should fail quietly, instead exceptions should be thrown. PHP builtin functions that fail quietly (ex: `json_encode`) should be replaced with a wrapper in `resources/utils.php`. Current wrappers: |
| 17 | + - `json_encode` -> `jsonEncode` |
| 18 | + - `json_decode` -> `jsonDecode` |
| 19 | + - `mb_convert_encoding` -> `mbConvertEncoding` |
| 20 | + - `mb_detect_encoding` -> `mbDetectEncoding` |
| 21 | + - `intval` -> `digits2int` |
28 | 22 | - `UnityHTTPD`'s user-facing error functionality (ex: `badRequest`) should only be called from `webroot/**/*.php`. |
29 | 23 | `resources/**/*.php` should throw exceptions instead. |
30 | 24 | - all pages under `webroot/admin/` must check for `$USER->getFlag(UserFlag::ADMIN)` and call `UnityHTTPD::forbidden()` if not admin. |
31 | | - |
32 | | -This repository will automatically check PRs for linting compliance. |
| 25 | +- All these conventions should be enforced with `pre-commit` / github CI if possible |
33 | 26 |
|
34 | 27 | ## Development Environment |
35 | 28 |
|
|
0 commit comments