Skip to content

Commit d16620a

Browse files
authored
Merge pull request #35 from dingo-d/docs/update-readme
Add comprehensive documentation
2 parents eb94497 + 396cd04 commit d16620a

File tree

2 files changed

+537
-17
lines changed

2 files changed

+537
-17
lines changed

CONTRIBUTING.md

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
# Contributing to PHP MJML Renderer
2+
3+
Thank you for your interest in contributing to the PHP MJML Renderer! This document provides guidelines and instructions for contributing.
4+
5+
## Getting Started
6+
7+
1. Fork the repository
8+
2. Clone your fork locally
9+
3. Create a feature branch from `main`
10+
4. Make your changes
11+
5. Submit a pull request
12+
13+
## Development Setup
14+
15+
### Requirements
16+
17+
- PHP 8.1 or higher
18+
- Composer
19+
20+
### Installation
21+
22+
```bash
23+
git clone https://github.com/YOUR_USERNAME/php-mjml-renderer.git
24+
cd php-mjml-renderer
25+
composer install
26+
```
27+
28+
### Running Tests
29+
30+
```bash
31+
# Run all tests
32+
composer test
33+
34+
# Run only unit tests
35+
composer test:unit
36+
37+
# Run with coverage
38+
composer test:coverage
39+
40+
# Code style check
41+
composer test:style
42+
43+
# Static analysis
44+
composer test:types
45+
```
46+
47+
## Coding Standards
48+
49+
### PSR-12 Compliance
50+
51+
All code must follow PSR-12 coding standards. We enforce this using PHP_CodeSniffer.
52+
53+
```bash
54+
# Check code style
55+
composer test:style
56+
57+
# Auto-fix code style issues
58+
vendor/bin/phpcbf
59+
```
60+
61+
### Type Safety
62+
63+
- Use strict types: `declare(strict_types=1);` at the top of every PHP file
64+
- Add type hints to all method parameters and return types
65+
- Aim for PHPStan level 9 compliance
66+
67+
### Documentation
68+
69+
- Write PHPDoc blocks for all public methods
70+
- Include parameter descriptions and return types
71+
- Add `@throws` tags for exceptions
72+
- Document complex logic with inline comments
73+
74+
Example:
75+
```php
76+
/**
77+
* Render MJML content to HTML
78+
*
79+
* @param string $mjml The MJML markup to render
80+
* @return string The rendered HTML output
81+
* @throws \RuntimeException If MJML parsing fails
82+
*/
83+
public function render(string $mjml): string
84+
{
85+
// Implementation
86+
}
87+
```
88+
89+
## Testing Requirements
90+
91+
### Write Tests for New Features
92+
93+
All new features must include comprehensive tests:
94+
95+
- Unit tests for individual methods and classes
96+
- Integration tests for component interactions
97+
- E2E tests for complete email rendering (if applicable)
98+
99+
### Test Structure
100+
101+
We use Pest PHP for testing. Follow the existing test patterns:
102+
103+
```php
104+
describe('ComponentName', function () {
105+
it('does something specific', function () {
106+
$component = new ComponentName();
107+
108+
expect($component->someMethod())->toBe('expected result');
109+
});
110+
});
111+
```
112+
113+
### Coverage Requirements
114+
115+
- Maintain high test coverage for new code
116+
- Critical rendering paths should have 100% coverage
117+
- Edge cases and error conditions must be tested
118+
119+
## Pull Request Process
120+
121+
### Before Submitting
122+
123+
1. **Run all tests**: Ensure `composer test` passes
124+
2. **Check code style**: Ensure `composer test:style` passes
125+
3. **Run static analysis**: Ensure `composer test:types` passes
126+
4. **Update documentation**: If you've changed public APIs
127+
5. **Add tests**: Ensure your changes are tested
128+
129+
### PR Guidelines
130+
131+
1. **Branch naming**: Use descriptive names like `feature/element-name` or `fix/bug-description`
132+
2. **Commit messages**: Write clear, atomic commits with descriptive messages
133+
3. **PR description**: Explain what changes were made and why
134+
4. **Link issues**: Reference related issues in your PR description
135+
5. **Keep focused**: One feature/fix per PR when possible
136+
137+
### Commit Message Format
138+
139+
Use imperative mood and focus on why changes were made:
140+
141+
```
142+
Add support for mj-social element
143+
144+
Implement the mj-social component with support for major social
145+
platforms. Includes built-in icons and customization options.
146+
```
147+
148+
## Pre-commit Hooks
149+
150+
The project uses CaptainHook for pre-commit hooks. These run automatically:
151+
152+
- Tests must pass
153+
- Code style must be compliant
154+
- PHPStan analysis must pass
155+
156+
Install hooks after cloning:
157+
```bash
158+
vendor/bin/captainhook install
159+
```
160+
161+
## Code Review Process
162+
163+
1. All PRs require review before merging
164+
2. Address feedback promptly and professionally
165+
3. Be open to suggestions and improvements
166+
4. Maintainers may request changes or additional tests
167+
168+
## Implementing New MJML Elements
169+
170+
When adding a new MJML element:
171+
172+
1. **Create element class** in `src/Elements/BodyComponents/` (or appropriate directory)
173+
2. **Extend AbstractElement** and implement required methods
174+
3. **Define attributes** in `$allowedAttributes` array
175+
4. **Implement render()** method to generate HTML output
176+
5. **Implement getStyles()** method for CSS styling
177+
6. **Write comprehensive tests** covering all attributes and edge cases
178+
7. **Update documentation** with usage examples
179+
180+
Example element structure:
181+
```php
182+
<?php
183+
184+
declare(strict_types=1);
185+
186+
namespace MadeByDenis\PhpMjmlRenderer\Elements\BodyComponents;
187+
188+
use MadeByDenis\PhpMjmlRenderer\Elements\AbstractElement;
189+
190+
class MjNewElement extends AbstractElement
191+
{
192+
public const string TAG_NAME = 'mj-new-element';
193+
public const bool ENDING_TAG = false;
194+
195+
protected array $allowedAttributes = [
196+
'attribute-name' => [
197+
'unit' => 'string',
198+
'type' => 'string',
199+
'default_value' => 'default',
200+
],
201+
];
202+
203+
protected array $defaultAttributes = [
204+
'attribute-name' => 'default',
205+
];
206+
207+
public function render(): string
208+
{
209+
// Implementation
210+
}
211+
212+
public function getStyles(): array
213+
{
214+
return [];
215+
}
216+
}
217+
```
218+
219+
## Questions?
220+
221+
If you have questions about contributing:
222+
223+
- Open a [Discussion](https://github.com/dingo-d/php-mjml-renderer/discussions)
224+
- Check existing [Issues](https://github.com/dingo-d/php-mjml-renderer/issues)
225+
- Review the [MJML documentation](https://documentation.mjml.io/)
226+
227+
## License
228+
229+
By contributing to this project, you agree that your contributions will be licensed under the MIT License.

0 commit comments

Comments
 (0)