Official Coding Standards for CodeIgniter

Overview

CodeIgniter Coding Standard

Unit Tests Coding Standards PHPStan Static Analysis PHPStan level Coverage Status Latest Stable Version License Total Downloads

This library holds the official coding standards of CodeIgniter based on PHP CS Fixer and powered by Nexus CS Config.

Installation

You can add this library as a local, per-project dependency to your project using Composer:

composer require codeigniter/coding-standard

If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:

composer require --dev codeigniter/coding-standard

Setup

To start, let us create a .php-cs-fixer.dist.php file at the root of your project.



use CodeIgniter\CodingStandard\CodeIgniter4;
use Nexus\CsConfig\Factory;

return Factory::create(new CodeIgniter4())->forProjects();

This minimal setup will return a default instance of PhpCsFixer\Config containing all rules applicable for the CodeIgniter organization.

Then, in your terminal, run the following command:

$ vendor/bin/php-cs-fixer fix --verbose

Adding License Headers

The default setup will not configure a license header in files. License headers can be especially useful for library authors to assert copyright. To add license headers in your PHP files, you can simply provide your name and name of library. Optionally, you can also provide your email and starting license year.

 -return Factory::create(new CodeIgniter4())->forProjects();
+return Factory::create(new CodeIgniter4())->forLibrary(
+    'CodeIgniter 4 framework',
+    'CodeIgniter Foundation',
+    '[email protected]',
+    2021,
+);

Providing Overriding Rules and Options

The list of enabled rules can be found in the CodeIgniter\CodingStandard\CodeIgniter4 class. If you feel the rule is not applicable to you or you want to modify it, you can do so by providing an array of overriding rules to the second parameter of Factory::create().

Similarly, you can further modify the PhpCsFixer\Config instance returned by using the available options. All available options are fully supported by Nexus CS Config and abstracted by simply providing an array of key-value pairs in the third parameter of Factory::create().

 -return Factory::create(new CodeIgniter4())->forProjects();
+return Factory::create(new CodeIgniter4(), [], [
+    'usingCache' => false,
+])->forProjects();

You can check out this library's own .php-cs-fixer.dist.php for inspiration on how it is done. For more detailed documentation on all available options, you can check here.

Contributing

All forms of contributions are welcome!

Since the rules here will be propagated and used within the CodeIgniter organization, all proposed rules and modifications to existing rules should have a proof-of-concept (POC) PR sent first to the CodeIgniter4 repository with possible changes to the code styles applied there. Once accepted there, you can send in a PR here to apply those rules.

License

This work is open-sourced under the MIT license.

You might also like...
DataTables server-side for CodeIgniter, supported both for CodeIgniter 3 and CodeIgniter 4.

CodeIgniter DataTables DataTables server-side for CodeIgniter, supported both for CodeIgniter 3 and CodeIgniter 4. Note: This library only handle the

A tool to automatically fix PHP Coding Standards issues
A tool to automatically fix PHP Coding Standards issues

PHP Coding Standards Fixer The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP codi

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

About PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a define

(Hard) Fork of WordPress Plugin Boilerplate, actively taking PRs and actively maintained. Following WordPress Coding Standards. With more features than the original.

Better WordPress Plugin Boilerplate This is a Hard Fork of the original WordPress Plugin Boilerplate. The Better WordPress Plugin Boilerplate actively

A tool to automatically fix Twig Coding Standards issues

Twig CS Fixer Installation This standard can be installed with the Composer dependency manager. Add the coding standard as a dependency of your projec

Composer installer for PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

A tool to automatically fix PHP Coding Standards issues by Dragon Code.

A tool to automatically fix PHP Coding Standards issues by Dragon Code.

This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards

PHP_CodeSniffer Standards Composer Installer Plugin This composer installer plugin allows for easy installation of PHP_CodeSniffer coding standards (r

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

A tool to automatically fix PHP Coding Standards issues by Dragon Code.

The Dragon Code Styler Installation Required PHP: ^8.0 Composer: ^2.0 Locally composer global require dragon-code/codestyler Usage When you run the co

A tool to automatically fix PHP Coding Standards issues
A tool to automatically fix PHP Coding Standards issues

PHP Coding Standards Fixer The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP codi

Coding-standard - Magento PHP CodeSniffer Coding Standard

ECG Magento Code Sniffer Coding Standard ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool. It allows aut

Documentation on clean coding and demonstration of studied clean coding principals with PHP.

practice-php-clean-code Documentation on clean coding and demonstration of studied clean coding principals with PHP. The document contained in this re

Upload Vimeo video with CodeIgniter, Official PHP library for the Vimeo API

Upload Vimeo video with CodeIgniter, Official PHP library for the Vimeo API. Vimeo Video upload with API using Official PHP library for the Vimeo API.

PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Manufacturing Industry, Phone numbers & Zipcodes for many countries

IsoCodes PHP library - Validators for standards from ISO, International Finance, Public Administrations, GS1, Book Industry, Phone numbers & Zipcodes

Standards compliant HTML filter written in PHP

HTML Purifier HTML Purifier is an HTML filtering solution that uses a unique combination of robust whitelists and aggressive parsing to ensure that no

The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).

JBZoo / CI-Report-Converter Why? Installing Using as GitHub Action Example GitHub Action workflow Available Directions Help description in terminal Co

Standards Alignment Tool

Standards Alignment Tool (SALT) [] Overview This is a prototype for testing the IMS Global Learning Consortium® CASE™ Specification and proving its us

Standards either proposed or approved by the Framework Interop Group

PHP Framework Interoperability Group The idea behind the group is for project representatives to talk about the commonalities between our projects and

Comments
  • CodeIgniter4 marked as internal

    CodeIgniter4 marked as internal

    Low-prio issue, but as you have marked CodeIgniter\CodingStandard\CodeIgniter4 as @internal phpstorm complains on me using it. Is there a reason for this class to be internal?

    opened by tangix 10
  • Add

    Add "static analysis" Composer keyword

    As per https://getcomposer.org/doc/04-schema.md#keywords by including "static analysis" as a keyword in the composer.json file, Composer 2.4.0-RC1 and later will prompt users if the package is installed with composer require instead of composer require --dev. See https://github.com/composer/composer/pull/10960 for more info.

    The "phpcs" keyword is to match other coding-standards packages.

    opened by GaryJones 3
  • Test failure

    Test failure

    There was 1 failure:
    
    1) CodeIgniter\CodingStandard\Tests\CodeIgniter4Test::testAllBuiltInFixersNotDeprecatedAreConfiguredInThisRuleset
    [CodeIgniter4 Coding Standards] Non-deprecated built-in fixer "no_useless_concat_operator" is not configured in the ruleset.
    Failed asserting that an array is empty.
    
    /home/runner/work/coding-standard/coding-standard/vendor/nexusphp/cs-config/src/Test/AbstractRulesetTestCase.php:105
    
    --
    
    There was 1 skipped test:
    
    1) CodeIgniter\CodingStandard\Tests\CodeIgniter4Test::testEnabledConfigurableFixerUsesAllAvailableOptionsNotDeprecated with data set "no_useless_concat_operator" ('no_useless_concat_operator', array('juggle_simple_strings'), array())
    `no_useless_concat_operator` is not yet defined in this ruleset.
    
    /home/runner/work/coding-standard/coding-standard/vendor/nexusphp/cs-config/src/Test/AbstractRulesetTestCase.php:185
    

    https://github.com/CodeIgniter/coding-standard/actions/runs/3243787612/jobs/5319015475

    opened by kenjis 2
Releases(v1.7.1)
  • v1.7.1(Dec 22, 2022)

  • v1.7.0(Nov 1, 2022)

    Changed

    • Bump php-cs-fixer to v3.13
    • Add 'case_sensitive' option to 'general_phpdoc_annotation_remove'
    • Add 'closure_fn_spacing' option to 'function_declaration'

    Please refer to the CHANGELOG for the detailed list of changes.

    Source code(tar.gz)
    Source code(zip)
  • v1.6.2(Oct 30, 2022)

  • v1.6.1(Oct 20, 2022)

    Fixed 🔧

    • Changed @internal description of class CodeIgniter4 to avoid warnings in phpstorm

    Please refer to the CHANGELOG for the detailed list of changes.

    New Contributors

    • @tangix made their first contribution in https://github.com/CodeIgniter/coding-standard/pull/7
    Source code(tar.gz)
    Source code(zip)
  • v1.6.0(Oct 15, 2022)

  • v1.5.0(Sep 13, 2022)

    Added

    • docs: add CONTRIBUTING.md (#3)
    • Normalize composer.json
    • Add "static analysis" Composer keyword (#2)

    Fixed

    • chore: fix editorconfig (#4)

    Changed

    • Enable ensure_single_space option of whitespace_after_comma_in_array
    • Use the space_multiple_catch option of types_spaces
    • Fix multi-lines
    • Add group_to_single_imports option to single_import_per_statement
    • Enable date_time_create_from_format_call
    • Add options to new_with_braces
    • Add order option to phpdoc_order
    • Add the trailing_comma_single_line option to function_declaration
    • Enable curly_braces_position
    • Enable single_line_comment_spacing
    • Enable no_trailing_comma_in_singleline
    • Add inline_constructor_arguments option to class_definition
    • Enable statement_indentation
    • Enable no_useless_nullsafe_operator
    • Enable no_multiple_statements_per_line
    • Enable control_structure_braces
    • Enable blank_line_between_import_groups
    • Remove deprecated fixers
    • Configure groups option in phpdoc_separation rule
    • Bump php-cs-fixer version

    New Contributors

    • @GaryJones made their first contribution in https://github.com/CodeIgniter/coding-standard/pull/2

    Full Changelog: https://github.com/CodeIgniter/coding-standard/compare/v1.4.0...v1.5.0

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Feb 9, 2022)

  • v1.3.0(Jan 15, 2022)

    Changed

    • Fix GHA workflows
    • Bump versions
      • PHP 7.4 minimum
      • friendsofphp/php-cs-fixer v3.4.0
      • phpstan/phpstan v1.0 minimum
    • Enable ordered_class_elements rule
    • Enable global_namespace_import rule (#1)
    • Use GITHUB_TOKEN so that secrets can be passed to PRs

    New Contributors

    • @kenjis made their first contribution in https://github.com/CodeIgniter/coding-standard/pull/1

    Please refer to the CHANGELOG for the detailed list of changes.

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Oct 18, 2021)

    Changed

    • Bump friendsofphp/php-cs-fixer to v3.2 minimum
    • Change behavior of class_attributes_separation rule
    • Add support for new fixers added in php-cs-fixer v3.2.0
    • Enable no_alternative_syntax rule

    Please refer to the CHANGELOG for the detailed list of changes.

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Aug 31, 2021)

    Changed

    • Bump to friendsofphp/php-cs-fixer v3.1.0 River for support of latest fixers
    • Bump to nexusphp/cs-config v3.3.0 for support of custom fixers

    Please refer to the CHANGELOG for the detailed list of changes.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Aug 29, 2021)

Owner
CodeIgniter
CodeIgniter
Open Source Point of Sale is a web based point of sale application written in PHP using CodeIgniter framework.

Open Source Point of Sale is a web based point of sale application written in PHP using CodeIgniter framework. It uses MySQL as the data back end and has a Bootstrap 3 based user interface.

opensourcepos 2.7k Jan 2, 2023
Integration of the popular Bootstrap CSS framework for CodeIgniter 4

Tatter\Bootstrap Integration of the popular Bootstrap CSS framework for CodeIgniter 4 Description This library leverages Tatter\Assets to automate ass

Tatter Software 1 Nov 27, 2021
Persistent user-specific settings for CodeIgniter 4

Tatter\Preferences Persistent user-specific settings for CodeIgniter 4 Quick Start Install with Composer: > composer require --dev tatter/preferences

Tatter Software 5 May 6, 2022
Customer Relationship Management (CRM) portal using PHP Codeigniter 4 & Tailwind CSS framework.

CRM Portal Customer Relationship Management (CRM) portal using PHP Codeigniter 4 & Tailwind CSS framework. Screenshots User (Dashboard) Admin (Employe

Dawood Khan Masood 5 Feb 2, 2022
CI4-Lic is a software license manager modul for Codeigniter 4, connecting to WordPress license server based on the Software License Manager Plugin.

CI4-Lic CI4-Lic is a software license manager modul for Codeigniter 4, connecting to WordPress license server based on Software License Manager Plugin

George Lewe 1 Jan 15, 2022
ZAP CRM is Customer Relationship Management portal built using PHP Codeigniter 4 & Tailwind CSS framework.

ZAP CRM ZAP CRM is Customer Relationship Management portal built using PHP Codeigniter 4 & Tailwind CSS framework. Screenshots User (Dashboard) Admin

Dawood Khan Masood 5 Feb 2, 2022
Official backend for VideoStream Android app.

About VideoStream Backend Official backend for VideoStream Android app, which is the CMS for VideoStream Android app. This backend is public for testi

Jesse Keskelä 1 Jan 30, 2022
Official repository for Find A PR. Find A PR is a platform that curates a list of issues around Laravel based project.

About Find A PR This is the official repository for Find A PR. Find A PR is a platform that curates a list of issues around Laravel based project. Req

Ash Allen 33 Dec 15, 2022
Cakephp-book allows you to search in the official CakePHP documentation directly from the console.

CakeDC/Book plugin for CakePHP cakephp-book allows you to search in the official CakePHP documentation directly from the console. Requirements CakePHP

Cake Development Corporation 3 Apr 13, 2022
Official Coding Standards for CodeIgniter

CodeIgniter Coding Standard This library holds the official coding standards of CodeIgniter based on PHP CS Fixer and powered by Nexus CS Config. Inst

CodeIgniter 37 Dec 19, 2022