Skip to content

Commit 165a841

Browse files
committed
docs: document exceptions style
1 parent fc63fd4 commit 165a841

File tree

1 file changed

+97
-66
lines changed

1 file changed

+97
-66
lines changed

src/Web/Documentation/content/main/5-extra-topics/03-contributing.md

Lines changed: 97 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,35 @@ Welcome aboard! We're excited that you are interested in contributing to the Tem
99

1010
To report an error or a bug, please:
1111

12-
* Head over to the [issue page](https://github.com/tempestphp/tempest-framework/issues) to open an issue.
13-
* Provide as much context about the problem you are running into and the environment you are running Tempest in.
14-
* Provide the version and, if relevant, the component you are running into issues with.
15-
* For a shot at getting our "Perfect Storm" label, submit a PR with a failing test!
12+
- Head over to the [issue page](https://github.com/tempestphp/tempest-framework/issues) to open an issue.
13+
- Provide as much context about the problem you are running into and the environment you are running Tempest in.
14+
- Provide the version and, if relevant, the component you are running into issues with.
15+
- For a shot at getting our "Perfect Storm" label, submit a PR with a failing test!
1616

1717
Once the issue has been opened, the Tempest team will:
1818

1919
<!-- TODO: Update this section with some links -->
20-
* Label the issue appropriately.
21-
* Assign the issue to the appropriate team member.
22-
* Try and get a response to you as quickly as possible.
20+
21+
- Label the issue appropriately.
22+
- Assign the issue to the appropriate team member.
23+
- Try and get a response to you as quickly as possible.
2324

2425
In the event that an issue is opened, but we get no response within 30 days, the issue will be closed.
2526

2627
## Request a feature
2728

2829
Tempest is a work in progress. We recognize that some features you might benefit from or expect may be missing. If you do have a feature request, please:
2930

30-
* Head over to the [issue page](https://github.com/tempestphp/tempest-framework/issues) to open an issue.
31-
* Provide as much detail about the feature you are looking for and how it might benefit you and others.
31+
- Head over to the [issue page](https://github.com/tempestphp/tempest-framework/issues) to open an issue.
32+
- Provide as much detail about the feature you are looking for and how it might benefit you and others.
3233

3334
Once the feature request has been opened, the Tempest team will:
3435

3536
<!-- TODO: Update this section with some links -->
36-
* Label the issue appropriately.
37-
* Ask any clarifying question to help better understand the use case.
38-
* If the feature requested is accepted, the Tempest team will assign the `{txt}Uncharted waters` label. A Tempest team member or a member of the community can contribute the code for this.
37+
38+
- Label the issue appropriately.
39+
- Ask any clarifying question to help better understand the use case.
40+
- If the feature requested is accepted, the Tempest team will assign the `{txt}Uncharted waters` label. A Tempest team member or a member of the community can contribute the code for this.
3941

4042
:::tip
4143
We welcome all contributions and greatly value your time and effort. To ensure your work aligns with Tempest's vision and avoids unnecessary effort, we aim to provide clear guidance and feedback throughout the process.
@@ -50,47 +52,52 @@ We welcome contributions of any size! Feel free to submit a pull request, even i
5052
:::
5153

5254
To contribute to Tempest's documentation, please:
53-
* Head over to the [Tempest docs repository](https://github.com/tempestphp/tempest-docs) to fork the project.
54-
* Add or edit any relevant documentation in a manner consistent with the rest of the documentation.
55-
* Re-read what you wrote and run it through a spell checker.
56-
* Open a pull request with your changes.
55+
56+
- Head over to the [Tempest docs repository](https://github.com/tempestphp/tempest-docs) to fork the project.
57+
- Add or edit any relevant documentation in a manner consistent with the rest of the documentation.
58+
- Re-read what you wrote and run it through a spell checker.
59+
- Open a pull request with your changes.
5760

5861
Once a pull request has been opened, the Tempest team will:
59-
* Use GitHub reviews to review your pull request.
60-
* If necessary, ask for revisions.
61-
* If we decide to pass on your pull request, we will thank you for your contribution and explain our decision. We appreciate all the time contributors put into Tempest!
62-
* If your pull request is accepted, we will mark it as such and merge it into the project. It will be released in the next tagged version! 🎉
62+
63+
- Use GitHub reviews to review your pull request.
64+
- If necessary, ask for revisions.
65+
- If we decide to pass on your pull request, we will thank you for your contribution and explain our decision. We appreciate all the time contributors put into Tempest!
66+
- If your pull request is accepted, we will mark it as such and merge it into the project. It will be released in the next tagged version! 🎉
6367

6468
## Contribute code
6569

6670
So, you want to dive into the code. To make the most of your time, please ensure that any contributions pertain to an approved feature request or a confirmed bug. This helps us focus on the vision for Tempest and ensuring the best developer experience.
6771

6872
To contribute to Tempest's code, you will need to first [setup Tempest locally](#setting-up-tempest-locally). Then,
69-
* Make the relevant code changes.
70-
* Write tests that verify that your contribution works as expected.
71-
* Run `composer qa` to ensure you are adhering to our style guidelines.
72-
* Create a [pull request](https://github.com/tempestphp/tempest-framework/pulls) with your changes.
73-
* If your pull request is connected to an open issue, add a line in your description that says `{txt}Fixes #xxx`, where `{txt}#xxx` is the number of the issue you're fixing.
73+
74+
- Make the relevant code changes.
75+
- Write tests that verify that your contribution works as expected.
76+
- Run `composer qa` to ensure you are adhering to our style guidelines.
77+
- Create a [pull request](https://github.com/tempestphp/tempest-framework/pulls) with your changes.
78+
- If your pull request is connected to an open issue, add a line in your description that says `{txt}Fixes #xxx`, where `{txt}#xxx` is the number of the issue you're fixing.
7479

7580
:::tip Pull request titles
7681
We use [conventional commits](#commit-and-merge-conventions) to automatically generate readable changelogs. You may help with this by providing a clear pull request title, which will appear in the changelog and needs to be understandable without the pull request's content as a context. Read more about this in the [pull requests](#pull-requests) section.
7782
:::
7883

7984
Once a pull request has been opened, the Tempest team will:
80-
* Use GitHub reviews to review your pull request.
81-
* Ensure all CI pipelines are passing.
82-
* If necessary, ask for revisions.
83-
* If we decide to pass on your pull request, we will thank you for your contribution and explain our decision. We appreciate all the time contributors put into Tempest!
84-
* If your pull request is accepted, we will mark it as such and merge it into the project. It will be released in the next tagged version! 🎉
85+
86+
- Use GitHub reviews to review your pull request.
87+
- Ensure all CI pipelines are passing.
88+
- If necessary, ask for revisions.
89+
- If we decide to pass on your pull request, we will thank you for your contribution and explain our decision. We appreciate all the time contributors put into Tempest!
90+
- If your pull request is accepted, we will mark it as such and merge it into the project. It will be released in the next tagged version! 🎉
8591

8692
### Setting up Tempest locally
8793

88-
* Install PHP.
89-
* Install Composer.
90-
* Install [Bun](https://bun.sh) or Node.
91-
* [Fork and clone](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) the Tempest repository.
94+
- Install PHP.
95+
- Install Composer.
96+
- Install [Bun](https://bun.sh) or Node.
97+
- [Fork and clone](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) the Tempest repository.
9298

9399
In your terminal, run:
100+
94101
```sh
95102
cd /path/to/your/clone
96103
composer update
@@ -108,16 +115,16 @@ Add the following in your `composer.json`, replacing `{txt}/path/to/your/clone`
108115

109116
```json
110117
{
111-
// ...
112-
"repositories": [
113-
{
114-
"type": "path",
115-
"url": "/path/to/your/clone"
116-
}
117-
],
118-
"minimum-stability": "dev",
119-
"prefer-stable": true
120-
// ...
118+
// ...
119+
"repositories": [
120+
{
121+
"type": "path",
122+
"url": "/path/to/your/clone"
123+
}
124+
],
125+
"minimum-stability": "dev",
126+
"prefer-stable": true
127+
// ...
121128
}
122129
```
123130

@@ -133,7 +140,7 @@ bun install /Users/you/Code/forks/tempest/packages/vite-plugin-tempest
133140

134141
Do not forget to run `bun dev` in the root of your local version of the framework, so your changes can be reflected on your local application without needing to run `bun build` each time.
135142

136-
### Styling decisions
143+
### Code style and conventions
137144

138145
Tempest uses a modified version of PSR-12. We automate the entire styling process because we know everyone is used to different standards and workflows. To see some of the rules we enforce, check out our [Mago](https://github.com/tempestphp/tempest-framework/blob/main/mago.toml) and [Rector](https://github.com/tempestphp/tempest-framework/blob/main/rector.php) configurations.
139146

@@ -143,8 +150,8 @@ The following outlines some other guidelines we have established for Tempest.
143150

144151
Whenever possible, classes should be `final` and `readonly`. This practice promotes immutability and prevents inadvertent changes to logic.
145152

146-
:::tip
147-
You may watch this [video](https://www.youtube.com/watch?v=HiD6CwWq5Ds&ab_channel=PHPAnnotated) to understand my thoughts about using `final`.
153+
:::tip{tabler:bulb}
154+
You may watch this [video](https://www.youtube.com/watch?v=HiD6CwWq5Ds&ab_channel=PHPAnnotated) to understand {x:brendt_gd}'s thoughts about using `final`.
148155
:::
149156

150157
---
@@ -153,53 +160,77 @@ You may watch this [video](https://www.youtube.com/watch?v=HiD6CwWq5Ds&ab_channe
153160

154161
Tempest uses a modified version of the [.NET best practices](https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms229043(v=vs.100)?redirectedfrom=MSDN) for acronym casing. Please see below for our guidelines:
155162

156-
__Do capitalize all characters of two to three character acronyms, except the first word of a camel-cased identifier.__
163+
**Do capitalize all characters of two to three character acronyms, except the first word of a camel-cased identifier.**
157164
A class named `IPAddress` is an example of a short acronym (IP) used as the first word of a Pascal-cased identifier. A parameter named `ipAddress` is an example of a short acronym (ip) used as the first word of a camel-cased identifier.
158165

159-
__Do capitalize only the first character of acronyms with four or more characters, except the first word of a camel-cased identifier.__
166+
**Do capitalize only the first character of acronyms with four or more characters, except the first word of a camel-cased identifier.**
160167
A class named `UuidGenerator` is an example of a long acronym (Uuid) used as the first word of a Pascal-cased identifier. A parameter named `uuidGenerator` is an example of a long acronym (uuid) used as the first word of a camel-cased identifier.
161168

162-
__Do not capitalize any of the characters of any acronyms, whatever their length, at the beginning of a camel-cased identifier.__
169+
**Do not capitalize any of the characters of any acronyms, whatever their length, at the beginning of a camel-cased identifier.**
163170
A class named `Uuid` is an example of a long acronym (Uuid) used as the first word of a camel-cased identifier. A parameter named `dbUsername` is an example of a short acronym (db) used as the first word of a camel-cased identifier.
164171

165172
---
166173

167-
#### Validation class formatting
174+
#### Validation classes
168175

169-
1. __Error message formatting__:
170-
- __Avoid ending punctuation__. When writing error messages for validation rules, refrain from including ending punctuation such as periods, exclamation marks, or question marks. This helps in maintaining a uniform style and prevents inconsistency in error message presentation.
176+
When writing error messages for validation rules, **refrain from including ending punctuation** such as periods, exclamation marks, or question marks. This helps in maintaining a uniform style and prevents inconsistency in error message presentation.
171177

172178
```diff
173179
- Value should be a valid email address!
174180
+ Value should be a valid email address
175181
```
176182

183+
---
184+
185+
#### Exception classes
186+
187+
Exception classes can be thought of as events and should be named accordingly. Use a subject-verb structure in the past tense to describe what happened (e.g., `DatabaseOperationFailed`, `StorageUsageWasForbidden`, `AuthenticatedUserWasMissing`).
188+
189+
- Do not suffix class names with `Exception`; the context of `throw` or `catch` language constructs makes their purpose clear.
190+
- All exception classes must extend PHP's built-in `\Exception`.
191+
- When appropriate, define marker interfaces such as `CacheException`, `DatabaseException`, or `FilesystemException` to group related exceptions. These interfaces must be suffixed with `Exception`.
192+
- Set the exception message within the exception class itself—not where it is thrown.
193+
- Override the constructor to only accept relevant context-specific input.
194+
195+
For instance, the following exception accepts a the relevant cache key as a constructor argument, and keeps it accessible through a public property:
196+
197+
```php LockAcquisitionTimedOut.php
198+
final class LockAcquisitionTimedOut extends Exception implements CacheException
199+
{
200+
public function __construct(
201+
public readonly string $key,
202+
) {
203+
parent::__construct("Lock with key `{$key}` could not be acquired on time.");
204+
}
205+
}
206+
```
207+
177208
## Release workflow
178209

179210
Tempest uses sub-splits to allow components to be installed as individual packages. The following outlines how this process works.
180211

181212
### Workflow steps
182213

183214
1. **Trigger event**
184-
- When a pull request is merged, or a new tag is created, the `.github/workflows/subsplit-packages.yml` action is run.
215+
- When a pull request is merged, or a new tag is created, the `.github/workflows/subsplit-packages.yml` action is run.
185216

186217
2. **Package information retrieval**
187-
- When the `subsplit-packages.yml` is run, it calls `bin/get-packages`.
188-
- This PHP script uses a combination of Composer and the filesystem to return (in JSON) some information about every package. It returns the:
189-
- **Directory**
190-
- **Name**
191-
- **Package**
192-
- **Organization**
193-
- **Repository**
218+
- When the `subsplit-packages.yml` is run, it calls `bin/get-packages`.
219+
- This PHP script uses a combination of Composer and the filesystem to return (in JSON) some information about every package. It returns the:
220+
- **Directory**
221+
- **Name**
222+
- **Package**
223+
- **Organization**
224+
- **Repository**
194225

195226
3. **Action matrix creation**
196-
- The result of the `get-packages` command is then used to create an action matrix.
197-
- This ensures that the next steps are performed for _every_ package discovered.
227+
- The result of the `get-packages` command is then used to create an action matrix.
228+
- This ensures that the next steps are performed for _every_ package discovered.
198229

199230
4. **Monorepo split action**
200-
- The `symplify/[email protected]` GitHub action is called for every package and provided the necessary information (destination repo, directory, etc.).
201-
- This action takes any changes and pushes them to the sub-split repository determined by combining the "Organization" and "Repository" values returned in step 2.
202-
- Depending on whether a tag is found or not, a tag is also supplied so the repository is tagged appropriately.
231+
- The `symplify/[email protected]` GitHub action is called for every package and provided the necessary information (destination repo, directory, etc.).
232+
- This action takes any changes and pushes them to the sub-split repository determined by combining the "Organization" and "Repository" values returned in step 2.
233+
- Depending on whether a tag is found or not, a tag is also supplied so the repository is tagged appropriately.
203234

204235
## Commit and merge conventions
205236

0 commit comments

Comments
 (0)