2017 © Pedro PelĂĄez
 

library magento2-smilelab-quality-suite

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

image

smile/magento2-smilelab-quality-suite

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  • Friday, September 29, 2017
  • by afoucret
  • Repository
  • 6 Watchers
  • 2 Stars
  • 8,235 Installations
  • 18 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 8 Versions
  • 18 % Grown

The README.md

Smile Lab Quality Suite (Magento)

This library provides coding standards / rulesets that can be used on Magento projects., (*1)

It includes the following packages:, (*2)

Table of content

Installation

composer require --dev smile/magento2-smilelab-quality-suite

Configuration

Create three files at the root of your project directory:, (*3)

Usage

# Check registered vulnerabilities
composer audit

# Analyse php syntax
vendor/bin/parallel-lint --exclude vendor [src path]

# Analyse code style
vendor/bin/phpcs

# Analyse code complexity
vendor/bin/phpmd [src path] text phpmd.xml.dist

# Analyse code logic
vendor/bin/phpstan analyse

Fix your code

A lot of style errors can be fixed automatically by running this command:, (*4)

vendor/bin/phpcbf --extensions=php,phtml

CI

GitHub Workflow

Example of .github/workflows/static-analysis.yaml file:, (*5)

name: 'Static Analysis'

on:
    pull_request: ~
    push:
        branches:
            - 'master'

jobs:
    tests:
        runs-on: 'ubuntu-latest'

        steps:
            - name: 'Checkout'
              uses: 'actions/checkout@v3'

            - name: 'Install PHP'
              uses: 'shivammathur/setup-php@v2'
              with:
                  php-version: '8.1'
                  coverage: 'none'
                  tools: 'composer:v2'
              env:
                  COMPOSER_AUTH_JSON: |
                      {
                          "http-basic": {
                              "repo.magento.com": {
                                  "username": "${{ secrets.MAGENTO_USERNAME }}",
                                  "password": "${{ secrets.MAGENTO_PASSWORD }}"
                              }
                          }
                      }

            - name: 'Get composer cache directory'
              id: 'composer-cache'
              run: 'echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT'

            - name: 'Cache dependencies'
              uses: 'actions/cache@v3'
              with:
                  path: '${{ steps.composer-cache.outputs.dir }}'
                  key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
                  restore-keys: '${{ runner.os }}-composer-'

            - name: 'Install dependencies'
              run: 'composer install --prefer-dist'

            - name: 'Run composer audit'
              run: 'composer audit --format=plain'

            - name: 'Run Parallel Lint'
              run: 'vendor/bin/parallel-lint --exclude vendor [src path]'

            - name: 'Run PHP CodeSniffer'
              run: 'vendor/bin/phpcs --extensions=php,phtml'

            - name: 'Run PHPMD'
              run: 'vendor/bin/phpmd [src path] xml phpmd.xml.dist'

            - name: 'Run PHPStan'
              run: 'vendor/bin/phpstan analyse' 

GitLab Runner

Example of .gitlab-ci.yml file:, (*6)

before_script:
  - 'composer install'

sniffers:
    variables:
        COMPOSER_AUTH: $COMPOSER_AUTH
    script:
        - 'composer audit --format=plain'
        - 'vendor/bin/parallel-lint --exclude vendor [src path]'
        - 'vendor/bin/phpcs --extensions=php,phtml'
        - 'vendor/bin/phpmd [src path] text phpmd.xml.dist'
        - 'vendor/bin/phpstan analyse'
    tags:
        - 'php81'

Baseline

If you want to add this coding standard on an existing project, it might be complicated to fix all issues. The baseline is a mechanism that allows you to keep your legacy code as it is and enforces the quality analysis for the code you will add in the future., (*7)

:heavy_exclamation_mark: It is always better to fix all issues. Baseline are a tweak to help you have a fresh start. But keep in mind that all errors (in the baseline or not) must be corrected eventually., (*8)

To generate the baselines, run these commands:, (*9)

# PHPCS
composer require --dev digitalrevolution/php-codesniffer-baseline
vendor/bin/phpcs --report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline --report-file=phpcs.baseline.xml --extensions=php,phtml

# PHPMD
vendor/bin/phpmd app ansi phpmd.xml.dist --generate-baseline

# PHPSTAN
vendor/bin/phpstan analyse --generate-baseline

For phpstan, you'll need to add the file phpstan-baseline.neon to the include part of the phpstan.neon.dist file and config reportUnmatchedIgnoredErrors: false to the parameters part of the same file., (*10)

The baseline files must be added to git., (*11)

The Versions

29/09 2017

dev-master

9999999-dev https://github.com/Smile-SA/magento2-smilelab-phpcs

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  Sources   Download

OSL-3.0

The Requires

 

by Aurélien FOUCRET
by Romain Ruaud

phpcs php phpmd coding standards

29/09 2017

1.1.0

1.1.0.0 https://github.com/Smile-SA/magento2-smilelab-phpcs

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  Sources   Download

OSL-3.0

The Requires

 

by Aurélien FOUCRET
by Romain Ruaud

phpcs php phpmd coding standards

05/07 2017

1.0.5

1.0.5.0 https://github.com/Smile-SA/magento2-smilelab-phpcs

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  Sources   Download

OSL-3.0

The Requires

 

by Aurélien FOUCRET
by Romain Ruaud

phpcs php phpmd coding standards

05/07 2017

1.0.4

1.0.4.0 https://github.com/Smile-SA/magento2-smilelab-phpcs

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  Sources   Download

OSL-3.0

The Requires

 

by Aurélien FOUCRET
by Romain Ruaud

phpcs php phpmd coding standards

05/07 2017

1.0.3

1.0.3.0 https://github.com/Smile-SA/magento2-smilelab-phpcs

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  Sources   Download

OSL-3.0

The Requires

 

by Aurélien FOUCRET
by Romain Ruaud

phpcs php phpmd coding standards

05/07 2017

1.0.2

1.0.2.0 https://github.com/Smile-SA/magento2-smilelab-phpcs

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  Sources   Download

OSL-3.0

The Requires

 

by Aurélien FOUCRET
by Romain Ruaud

phpcs php phpmd coding standards

16/03 2017

1.0.1

1.0.1.0 https://github.com/Smile-SA/magento2-smilelab-phpcs

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  Sources   Download

OSL-3.0

The Requires

 

by Aurélien FOUCRET
by Romain Ruaud

phpcs php phpmd coding standards

06/02 2017

1.0.0

1.0.0.0 https://github.com/Smile-SA/magento2-smilelab-phpcs

Complete suite of quality tools used by Smile Lab for community Magento2 projects.

  Sources   Download

OSL-3.0

The Requires

 

by Aurélien FOUCRET
by Romain Ruaud

phpcs php phpmd coding standards