• Stars
    star
    347
  • Rank 122,141 (Top 3 %)
  • Language
    PHP
  • License
    Open Software Lic...
  • Created almost 6 years ago
  • Updated 25 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Magento Coding Standard

Magento Coding Standard

A set of Magento rules for PHP_CodeSniffer tool.

Installation within a Magento 2 site

To use within your Magento 2 project you can use:

composer require --dev magento/magento-coding-standard

Due to security, when installed this way the Magento standard for phpcs cannot be added automatically. You can achieve this by adding the following to your project's composer.json:

"scripts": {
    "post-install-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
    ],
    "post-update-cmd": [
      "([ $COMPOSER_DEV_MODE -eq 0 ] || vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/)"
    ]
}

Installation for development

You can install Magento Coding Standard by cloning this GitHub repo:

git clone [email protected]:magento/magento-coding-standard.git
cd magento-coding-standard
composer install

It is possible also to install a standalone application via Composer

composer create-project magento/magento-coding-standard --stability=dev magento-coding-standard

Verify installation

Command should return the list of installed coding standards including Magento2.

vendor/bin/phpcs -i

Usage

Once installed, you can run phpcs from the command-line to analyze your code MyAwesomeExtension

vendor/bin/phpcs --standard=Magento2 app/code/MyAwesomeExtension

Fixing issues automatically

Also, you can run phpcbf from the command-line to fix your code MyAwesomeExtension for warnings like "PHPCBF CAN FIX THE [0-9]+ MARKED SNIFF VIOLATIONS AUTOMATICALLY"

vendor/bin/phpcbf --standard=Magento2 app/code/MyAwesomeExtension

Contribution

See the community contribution model.

Where to contribute

  • Documentation of existing rules. See ExtDN PHP CodeSniffer rules for Magento 2 as a good example.
  • Bug fixes and improvements of existing rules.
  • Creation of new PHP CodeSniffer rules.
  • Discussions on new rules (through periodic hangouts or discussions per GitHub issue).

How to contribute

  1. Start with looking into Community Dashboard. Any ticket in Up for grabs is a good candidate to start.
  2. Didn't satisfy your requirements? Create one of three types of issues:
    • Bug report - Found a bug in the code? Let us know!
    • Existing rule enhancement - Know how to improve existing rules? Open an issue describe how to enhance Magento Coding Standard.
    • New rule proposal - Know how to improve Magento ecosystem code quality? Do not hesitate to open a proposal.
  3. The issue will appear in the Backlog column of the Community Dashboard. Once it will be discussed and get accepted label the issue will appear in the Up for grabs column.

Testing

All rules should be covered by unit tests. Each Test.php class should be accompanied by a Test.inc file to allow for unit testing based upon the PHP_CodeSniffer parent class AbstractSniffUnitTest. You can verify your code by running

vendor/bin/phpunit

Also, verify that the sniffer code itself is written according to the Magento Coding Standard:

vendor/bin/phpcs --standard=Magento2 Magento2/ --extensions=php

ESLint

Prerequisites: Node.js (^12.22.0, ^14.17.0, or >=16.0.0).

You need to run the following command to install all the necessary packages described in the package.json file:

npm install

You can execute ESLint as follows:

npm run eslint -- path/to/analyze

RECTOR PHP

From magento-condign-standard project, you can execute rector php as follows:

vendor/bin/rector process Magento2 Magento2Framework PHP_CodeSniffer --dry-run --autoload-file vendor/squizlabs/php_codesniffer/autoload.php

The rules from rector that are applied are set inside the config file: rector.php

The option --dry-run displays errors found, but code is not automatically fixed.

To run rector for magento projects you need to:

  • Specify the magento path and the autoload file for the magento project:
vendor/bin/rector process MAGENTO_PATH --dry-run --autoload-file MAGENTO_AUTOLOAD_FILE

Example:

vendor/bin/rector process magento2ce/app/code/Magento/Cms/Model --dry-run --autoload-file magento2ce/vendor/autoload.php

License

Each Magento source file included in this distribution is licensed under the OSL-3.0 license.

Please see LICENSE.txt for the full text of the Open Software License v. 3.0 (OSL-3.0).

More Repositories

1

magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
PHP
11,535
star
2

pwa-studio

🛠Development tools to build, optimize and deploy Progressive Web Applications for Magento 2.
JavaScript
1,067
star
3

devdocs

[Deprecated] Magento Developer Documentation
Ruby
673
star
4

magento2-phpstorm-plugin

PHPStorm Plugin for Magento 2
Java
436
star
5

data-migration-tool

Magento Data Migration Tool
PHP
336
star
6

inventory

Magento Inventory Project (a.k.a MSI)
PHP
336
star
7

architecture

A place where Magento architectural discussions happen
274
star
8

magento-cloud-docker

All Submissions you make to Magento Inc. (“Magento") through GitHub are subject to the following terms and conditions: (1) You grant Magento a perpetual, worldwide, non-exclusive, no charge, royalty free, irrevocable license under your applicable copyrights and patents to reproduce, prepare derivative works of, display, publically perform, sublicense and distribute any feedback, ideas, code, or other information (“Submission") you submit through GitHub. (2) Your Submission is an original work of authorship and you are the owner or are legally entitled to grant the license stated above. (3) You agree to the Contributor License Agreement found here: https://github.com/magento/magento2/blob/master/CONTRIBUTOR_LICENSE_AGREEMENT.html
PHP
256
star
9

marketplace-eqp

Magento 1.x Coding Standard
PHP
224
star
10

magento2-sample-data

Magento 2 Sample Data
PHP
212
star
11

magento-cloud

Magento Cloud
PHP
205
star
12

baler

AMD module bundler and preloader for Magento 2 stores.
JavaScript
175
star
13

m2-devtools

Helpful in-browser debugging/inspection tools for the Magento 2 Front-End
TypeScript
171
star
14

magento2-functional-testing-framework

Magento2 Functional Testing Framework
PHP
155
star
15

quality-patches

PHP
148
star
16

graphql-ce

[ARCHIVED] Please use magento/magento2 project
PHP
131
star
17

ece-tools

All Submissions you make to Magento Inc. (“Magento") through GitHub are subject to the following terms and conditions: (1) You grant Magento a perpetual, worldwide, non-exclusive, no charge, royalty free, irrevocable license under your applicable copyrights and patents to reproduce, prepare derivative works of, display, publically perform, sublicense and distribute any feedback, ideas, code, or other information (“Submission") you submit through GitHub. (2) Your Submission is an original work of authorship and you are the owner or are legally entitled to grant the license stated above. (3) You agree to the Contributor License Agreement found here: https://github.com/magento/magento2/blob/master/CONTRIBUTOR_LICENSE_AGREEMENT.html
PHP
117
star
18

magento2-page-builder

Magento2 PageBuilder
JavaScript
80
star
19

security-package

Magento Security Extensions
PHP
73
star
20

magento2-samples

[ONLY Magento 2.0.x Compatible] Code samples for Magento developers
PHP
73
star
21

adobe-stock-integration

Magento Adobe Stock integration Community Project.
PHP
60
star
22

composer-root-update-plugin

PHP
57
star
23

community-features

Magento Features Development is an Initiative to Allows Community Memebers Join to Development of Magento Features
46
star
24

meta-for-magento2

PHP
38
star
25

magento-cloud-patches

All Submissions you make to Magento Inc. (“Magento") through GitHub are subject to the following terms and conditions: (1) You grant Magento a perpetual, worldwide, non-exclusive, no charge, royalty free, irrevocable license under your applicable copyrights and patents to reproduce, prepare derivative works of, display, publically perform, sublicense and distribute any feedback, ideas, code, or other information (“Submission") you submit through GitHub. (2) Your Submission is an original work of authorship and you are the owner or are legally entitled to grant the license stated above. (3) You agree to the Contributor License Agreement found here: https://github.com/magento/magento2/blob/master/CONTRIBUTOR_LICENSE_AGREEMENT.html
PHP
34
star
26

merchdocs

[Deprecated] Magento User Guide
Ruby
33
star
27

magento-semver

Magento Semantic Versioning Checker. Join #svc in our Community Slack: https://opensource.magento.com/slack. Static tests that identify required module version changes based on code diff, and look for backward incompatible changes.
PHP
33
star
28

backlog

Magento product backlog
31
star
29

composer

PHP
31
star
30

bulk-api-ce

Magento 2 CE repository dedicated for implementation of the Bulk API
30
star
31

m2-baler

PHP
30
star
32

commerce-data-export

PHP
25
star
33

magento2-upward-connector

Magento module for routing front-end requests to UPWARD-PHP
PHP
24
star
34

magento2-jp

Magento Community Project for providing best experience for Japanese market
PHP
24
star
35

magento-cloud-components

All Submissions you make to Magento Inc. (“Magento") through GitHub are subject to the following terms and conditions: (1) You grant Magento a perpetual, worldwide, non-exclusive, no charge, royalty free, irrevocable license under your applicable copyrights and patents to reproduce, prepare derivative works of, display, publically perform, sublicense and distribute any feedback, ideas, code, or other information (“Submission") you submit through GitHub. (2) Your Submission is an original work of authorship and you are the owner or are legally entitled to grant the license stated above. (3) You agree to the Contributor License Agreement found here: https://github.com/magento/magento2/blob/master/CONTRIBUTOR_LICENSE_AGREEMENT.html
PHP
23
star
36

glossary

Magento Glossary Application
JavaScript
20
star
37

magento2-kubernetes-devbox

Shell
18
star
38

magento2-pwa

PHP
15
star
39

devdocs-m1

HTML
14
star
40

upward-php

Implementation of UPWARD spec written in PHP
PHP
14
star
41

magento-eslint

Shared ESLint configuration for Magento PWA-related projects
JavaScript
13
star
42

knowledge-base

Shell
12
star
43

ts-types

TypeScript Definitions for Magento 2
8
star
44

catalog-storefront

PHP
7
star
45

module-grpc

PHP
6
star
46

aep-launch

PHP
6
star
47

pagebuilder-docs

Page Builder development documentation
5
star
48

magento-japan-tax

PHP
5
star
49

graphql

TypeScript
5
star
50

storefront-message-broker

PHP
4
star
51

storefront-search-ce

PHP
4
star
52

app-builder-samples

JavaScript
4
star
53

pwa-tests

4
star
54

composer-dependency-version-audit-plugin

validating packages through a composer plugin
PHP
4
star
55

adobe-commerce-catalog-service

4
star
56

page-builder-types

Magento Page Builder Types
4
star
57

devdocs-mbi

Magento Business Intelligence developer documentation
4
star
58

directive-parser

Parses Magento PWA Studio directives
JavaScript
3
star
59

marketplace-subscriptions

PHP
3
star
60

adobe-ims

PHP
3
star
61

storefront-product-reviews-ce

PHP
2
star
62

storefront-pricing-ce

PHP
2
star
63

magento2devbox-web

PHP
2
star
64

magento-zend-memory

PHP
2
star
65

magento-zend-log

PHP
2
star
66

magento-zend-exception

PHP
2
star
67

magento-zend-db

PHP
2
star
68

magento-zend-cache

PHP
2
star
69

magento-zend-pdf

PHP
2
star
70

php-proto-generator

A tool to generate Magento modules from proto definitions
PHP
2
star
71

mtf

PHP
2
star
72

magento-zend-loader

PHP
2
star
73

language-ja_JP

Japanese Language Pack for Magento 2 Resources
PHP
2
star
74

inventory-composer-installer

PHP
1
star
75

devops-cla-test-public

1
star
76

storefront-authentication-ce

1
star
77

magento2-pwa-commerce

1
star