Skip to content

This Repository contains the source files of our Coding-Standard.

License

Notifications You must be signed in to change notification settings

easybi-mr/coding-standard-source

 
 

Repository files navigation

CI Docker Build Packagist Release License

ZooRoyal Coding Standard Source


This repository holds the necessary sources to use and build the ZooRoyal Coding Standard.

It incorporates

In addition, there is a PHP script in src/bin to be used by a continuous integration tool of your choice. It searches your source code to find files to check with its static code analysis tools. Information about its usage can be found by calling it with -h option.

Installation (as intended)

Docker

The ZooRoyal Coding Standard is designed to be used as a docker isolated application. Therefore, no installation is needed if you have a docker daemon available on your system.

Composer

If ...

  • ... you don't feel comfortable with the docker user experience ...
  • ... want to bind your source code to a certain version of the ZooRoyal Coding Standard ...

... you find a ready-made composer package at https://github.com/ZooRoyal/coding-standard

composer require --dev "zooroyal/coding-standard"

It will still require you to have a docker daemon available on your system.

The ZooRoyal Coding Standard application will be available under vendor/bin/coding-standard.

Install from source (not recommended)

If all else fails, you can install the ZooRoyal Coding Standard from this source package. Please be aware that this is not recommended. There will be tons of dependencies the rest of your project will have to comply with. They will be very specific and change as we see fit.

Standalone

If you want to use the ZooRoyal Coding Standard as a standalone application, you can use the following commands:

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

The ZooRoyal Coding Standard application will be available under src/bin/coding-standard.

As composer dependency

To use the ZooRoyal Coding Standard as a composer dependency, you can require it via composer but this alone won't be enough. You will have to install the necessary tools as well. For this to happen, you can use the following process:

composer require --dev "zooroyal/coding-standard-source"

Now you need to add the following lines to your composer.json:

{
    [...]
    "extra": {
        [...]
        "bamarni-bin": {
            "bin-links": true,
            "forward-command": true
        }
    }
    [...]
}

The final step is to install the necessary tools. This can be done by running the following command:

cp -r vendor/zooroyal/coding-standard-source/vendor-bin .
composer update
# If you need Javascript support ...
npm install --save-dev vendor/zooroyal/coding-standard-source

This will install the following tools in several directories under vendor-bin:

This tools will be installed in node_modules:

The ZooRoyal Coding Standard application will be available under vendor/bin/coding-standard.

Usage ZooRoyal Coding Standard

Please keep in mind, that ZooRoyal Coding Standard can only check source code which is a git repository as well as a composer project

Using the docker image directly

If you want to use the docker image directly, you can use the following command:

docker run --rm -t -v $(pwd):/app ghcr.io/zooroyal/coding-standard-source:latest <parameter>

This will mount your current working directory as the root directory of the source code you want to check.

For your convenience, you can create an alias for this command:

alias coding-standard="docker run --rm -t -v $(pwd):/app ghcr.io/zooroyal/coding-standard-source:latest"

To use a certain version of the coding-standard, just add the version tag to the image name:

docker run --rm -t -v $(pwd):/app ghcr.io/zooroyal/coding-standard-source:4.0.0 <parameter>

Using one of the composer packages

The composer package will install a script in your vendor/bin folder of your composer project or src/bin of the standalone installation folder. Use them to run the ZooRoyal Coding Standard.

The ZooRoyal Coding Standard application must be executed from the root of your project.

Using the ZooRoyal Coding Standard

Run the command to get usage instructions.

coding-standard
Available commands:
  find-files                Finds files for code style checks.
  help                      Displays help for a command
  list                      Lists commands
 checks
  checks:forbidden-changes  Checks for unwanted code changes.
 sca
  sca:all                   Run all static code analysis tools.
  sca:copy-paste-detect     Run PHP-CPD on PHP files.
  sca:eslint                Run ESLint on JS files.
  sca:mess-detect           Run PHP-MD on PHP files.
  sca:parallel-lint         Run Parallel-Lint on PHP files.
  sca:sniff                 Run PHP-CS on PHP files.
  sca:stylelint             Run StyleLint on Less files.
  sca:stan                  Run PHPStan on PHP files.

Example sca:all

coding-standard sca:all -h
Usage:
  sca:all [options]

Options:
  -t, --target=TARGET      Finds Files which have changed since the current branch parted from the target
                           branch only. The Value has to be a commit-ish. [default: false]
  -a, --auto-target        Finds Files which have changed since the current branch parted from the parent
                           branch only. It tries to find the parent branch by automagic.
  -f, --fix                Runs tool to try to fix violations automagically.
  -p, --process-isolation  Runs all checks in separate processes. Slow but not as resource hungry.
  -h, --help               Display this help message
  -q, --quiet              Do not output any message
  -V, --version            Display this application version
      --ansi               Force ANSI output
      --no-ansi            Disable ANSI output
  -n, --no-interaction     Do not ask any interactive question
  -v|vv|vvv, --verbose     Increase the verbosity of messages: 1 for normal output, 2 for more verbose output
                           and 3 for debug

Help:
  This tool executes all static code analysis tools on files of this project. It ignores files which are in
  directories with a .dont<toolshortcut> file. Subdirectories are ignored too.

The all command forwards all applicable parameters to all implemented static code analysis tools.

coding-standard sca:all -a -f

This command for example tries to find the parent branch by automagic (-a) and tells all static code analysis tools to fix found violations if they are able to.

coding-standard sca:all -t origin/master

This command computes the diff to the branch origin/master and searches for all violations in this files.

For examples just have a look an the .travis.yml

Extend the Coding Standard

If you want to extend the ZooRoyal Coding Standard with your own tools there are two tutorials available:

About

This Repository contains the source files of our Coding-Standard.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 95.9%
  • JavaScript 2.4%
  • TypeScript 0.8%
  • Shell 0.2%
  • SCSS 0.2%
  • Dockerfile 0.2%
  • Other 0.3%