Skip to content

Latest commit

 

History

History
352 lines (258 loc) · 14.1 KB

pull_request.md

File metadata and controls

352 lines (258 loc) · 14.1 KB

Sending a Pull Request

Contributions

We expect the following in all Pull Requests (PRs).

Important

We expect all code changes or bug-fixes to be accompanied by one or more tests added to our test suite to prove the code works.

If pull requests do not comply with the above, they will likely be closed. Since we are a team of volunteers, we don't have any more time to work on the framework than you do. Please make it as painless for your contributions to be included as possible.

The Open Source Guide is a good first read for those new to contributing to open source!

CodeIgniter Internals Overview

CodeIgniter Internals Overview should help contributors understand how the core of the framework works. Specifically, it details the information needed to create new packages for the core.

Guidelines

Before we look into how to contribute to CodeIgniter4, here are some guidelines. Your Pull Requests (PRs) need to meet our guidelines.

If your Pull Requests fail to pass these guidelines, they will be declined, and you will need to re-submit when you've made the changes. This might sound a bit tough, but it is required for us to maintain the quality of the codebase.

PHP Style

All code must conform to our Style Guide, which is based on PSR-12.

This makes certain that all submitted code is of the same format as the existing code and ensures that the codebase will be as readable as possible.

You can fix most of the coding style violations by running this command in your terminal:

composer cs-fix

You can check the coding style violations:

composer cs

Unit Testing

If you are not familiar with Unit Testing, see the forum thread. If you need help with getting tests running on your local machines, ask for help on the forum. We would be happy to help out.

Unit testing is expected for all CodeIgniter components. We use PHPUnit, and run unit tests using GitHub Actions for each PR submitted or changed.

In the CodeIgniter project, there is a tests folder, with a structure that parallels that of system.

The normal practice would be to have a unit test class for each of the classes in system, named appropriately. For instance, the BananaTest class would test the Banana class. There will be occasions when it is more convenient to have separate classes to test different functionality of a single CodeIgniter component.

See Running System Tests and the PHPUnit website for more information.

Comments

PHPDoc Comments

Source code should be commented using PHPDoc comment blocks. This means implementation comments to explain potentially confusing sections of code, and documentation comments before each public or protected class/interface/trait, method, and variable.

Do not add PHPDoc comments that are superficial, duplicated, or stating the obvious.

See the following for more information.

Code Comments

Do not add comments that are superficial, duplicated, or stating the obvious.

User Guide

The User Guide is an essential component of the CodeIgniter framework.

Each framework component or group of components needs a corresponding section in the User Guide. Some of the more fundamental components will show up in more than one place.

If you change anything that requires a change to documentation, then you will need to add to the documentation. New classes, methods, parameters, changing default values, changing behavior etc. are all changes that require a change to documentation.

Also, the Changelog must be updated for every change, and PHPDoc blocks must be maintained.

See Writing CodeIgniter Documentation.

Changelog

The Changelog in the user guide needs to be kept up-to-date. Not all changes will need an entry in it, but the following items should.

  • all breaking changes (BCs)
  • all enhancements (new features, new classes, new APIs)
  • message changes
  • other behavior changes
  • deprecations
  • major bug fixes

Upgrading Guide

If your PR requires users to do something when they upgrade CodeIgniter, or changes the Config values, the Upgrading Guide in the installation folder is also needed.

  • Add an instruction what to do when upgrading.
  • If you add new properties or changes default values in Config files, add the changes in "Project Files > Content Changes > Config".

CSS

See Contribution CSS.

Compatibility

CodeIgniter4 requires PHP 8.1.

Backwards Compatibility

Generally, we aim to maintain backwards compatibility between minor versions of the framework. Any changes that break compatibility need a good reason to do so, and need to be pointed out in the Upgrading guide.

CodeIgniter4 itself represents a significant backwards compatibility break with earlier versions of the framework.

Breaking Changes

In general, any change that would disrupt existing uses of the framework is considered a "Breaking Change" (BC) and will not be favorably considered. A few specific examples to pay attention to:

  1. New classes/properties/constants in system are acceptable, but anything in the app directory that will be used in system should be backwards-compatible.
  2. Any changes to non-private methods must be backwards-compatible with the original definition.
  3. Deleting non-private properties or methods without prior deprecation notices is frowned upon and will likely be closed.
  4. Deleting or renaming public classes and interfaces, as well as those not marked as @internal, without prior deprecation notices or not providing fallback solutions will also not be favorably considered.

Mergeability

Your PRs need to be mergeable and GPG-signed before they will be considered.

We suggest that you synchronize your repository's develop branch with that in the main repository, and then your feature branch and your develop branch, before submitting a PR. You will need to resolve any merge conflicts introduced by changes incorporated since you started working on your contribution.

Branching

  • All bug fix PRs should be sent to the "develop" branch, this is where the next bug fix version will be developed.
  • PRs with any enhancement should be sent to next minor version branch, e.g. "4.6"

Note

If you sent your PR to the wrong branch, see Contribution Workflow.

The "master" branch will always contain the latest stable version and is kept clean so a "hotfix" (e.g. an emergency security patch) can be applied to the "master" branch to create a new version, without worrying about other features holding it up. Any sent to the "master" branch will be closed automatically.

If you have multiple changes to submit, please place all changes into their own branch on your fork.

One thing at a time: A pull request should only contain one change. That does not mean only one commit, but one change - however many commits it took. The reason for this is that if you change X and Y, but send a pull request for both at the same time, we might really want X but disagree with Y, meaning we cannot merge the request. Using the Git-Flow branching model you can create new branches for both of these features and send two requests.

Important

Please use separate branches for each of your PRs - it will make it easier for you to keep changes separate from each other and from whatever else you are doing with your repository!

Signing

You must GPG-sign your work, certifying that you either wrote the work or otherwise have the right to pass it on to an open-source project. See Developer's Certificate of Origin.

This is not just a "signed-off-by" commit, but instead, a digitally signed one.

See Contribution signing for details.

Note

If you forgot GPG-signing your commits, see Contribution Workflow.

Static Analysis on PHP code

We cannot, at all times, guarantee that all PHP code submitted on pull requests to be working well without actually running the code. For this reason, we make use of two static analysis tools, PHPStan and Rector to do the analysis for us.

These tools have already been integrated into our CI/CD workflow to minimize unannounced bugs. Pull requests are expected that their code will pass these two. In your local machine, you can manually run these tools so that you can fix whatever errors that pop up with your submission.

PHPStan

PHPStan is expected to scan the entire framework by running this command in your terminal:

composer phpstan:check

See also:

If PHPStan errors cannot be resolved by any means, or if the PHPStan error is false positive and should be ignored, the baseline can be updated with the following command:

composer phpstan:baseline

Rector

Rector, on the other hand, can be run on the specific files you modified or added:

vendor/bin/rector process --dry-run path/to/file

If you run it without --dry-run, Rector will fix the code:

vendor/bin/rector process path/to/file

How-to Guide

The best way to contribute is to fork the CodeIgniter4 repository, and "clone" that to your development area. That sounds like some jargon, but "forking" on GitHub means "making a copy of that repo to your account" and "cloning" means "copying that code to your environment so you can work on it".

  1. Set up Git (Windows, Mac, & Linux).
  2. Go to the CodeIgniter4 repository.
  3. Fork it (to your GitHub account).
  4. Clone your CodeIgniter repository: git@github.com:<your-name>/CodeIgniter4.git
    • > git clone git@github.com:<your-name>/CodeIgniter4.git
  5. Install Composer dependencies.
    • > cd CodeIgniter4/
    • > composer update
  6. Create a new branch in your project for each set of changes you want to make.
    • If your PR is for bug fixes:
      • > git switch develop
      • > git switch -c <new-branch-name>
    • If your PR has any enhancement, create new branch from next minor version branch, e.g. "4.6":
      • > git switch <next-minor-version-branch>
      • > git switch -c <new-branch-name>
  7. Fix existing bugs on the Issue tracker after confirming that no one else is working on them.
  8. Commit the changed files in your contribution branch.
    • > git commit
    • Commit messages are expected to be descriptive of why and what you changed specifically. Commit messages like "Fixes #1234" would be asked by the reviewer to be revised. Atomic commit is recommended. See Contribution Workflow for details.
  9. If you have touched PHP code, run static analysis.
    • > composer analyze
  10. Run unit tests on the specific file you modified. If there are no existing tests yet, please create one.
  • > vendor/bin/phpunit tests/system/path/to/file/you/modified
  • Make sure the tests pass to have a higher chance of merging.
  1. Push your contribution branch to your fork.
  • > git push origin <new-branch-name>
  1. Send a pull request.
  2. Label your pull request with the appropriate label if you can.

See Contribution workflow for Git workflow details.

The codebase maintainers will now be alerted to the submission and someone from the team will respond. If your change fails to meet the guidelines, it will be rejected or feedback will be provided to help you improve it.

Once the maintainer handling your pull request is satisfied with it, they will approve the pull request and merge it into the "develop" branch. Your patch will now be part of the next release!

Translating System Messages

If you wish to contribute to the system message translations, then fork and clone the translations repository separately from the codebase.

These are two independent repositories!