Skip to content

Commit d97b0ce

Browse files
authored
Merge pull request #1 from php-parallel-lint/feature/various-tweaks
Comprehensive update: use PSR12, PHPCompatibility, add Readme, add QA
2 parents 7073578 + f1a82cb commit d97b0ce

File tree

7 files changed

+189
-59
lines changed

7 files changed

+189
-59
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.github export-ignore
2+
.gitattributes export-ignore
3+
.gitignore export-ignore

.github/workflows/qa.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: QA
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- develop
8+
- master
9+
# Allow manually triggering the workflow.
10+
workflow_dispatch:
11+
12+
# Cancels all previous workflow runs for the same branch that have not yet completed.
13+
concurrency:
14+
# The concurrency group contains the workflow name and the branch name.
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
check:
20+
name: 'Basic QA checks'
21+
runs-on: ubuntu-latest
22+
23+
env:
24+
XMLLINT_INDENT: ' '
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v2
29+
30+
- name: Install PHP
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: '8.0'
34+
coverage: none
35+
tools: cs2pr
36+
37+
# Validate the composer.json file.
38+
# @link https://getcomposer.org/doc/03-cli.md#validate
39+
- name: Validate Composer installation
40+
run: composer validate --no-check-all --strict
41+
42+
# Verify the package can be installed succesfully.
43+
# @link https://github.com/marketplace/actions/install-composer-dependencies
44+
- name: Install Composer dependencies
45+
uses: ramsey/composer-install@v1
46+
47+
- name: Install xmllint
48+
run: sudo apt-get install --no-install-recommends -y libxml2-utils
49+
50+
# Show XML violations inline in the file diff.
51+
# @link https://github.com/marketplace/actions/xmllint-problem-matcher
52+
- uses: korelstar/xmllint-problem-matcher@v1
53+
54+
# Validate the ruleset XML file.
55+
# @link http://xmlsoft.org/xmllint.html
56+
- name: Validate ruleset against XML schema
57+
run: xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./PHPParallelLint/ruleset.xml
58+
59+
# Check the code-style consistency of the XML ruleset files.
60+
- name: Check XML ruleset code style
61+
run: diff -B --tabsize=4 ./PHPParallelLint/ruleset.xml <(xmllint --format "./PHPParallelLint/ruleset.xml")

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor
2+
composer.lock

PHPParallelLint/ruleset.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHPParallelLint" xsi:noNamespaceSchemaLocation="../vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
4+
<description>A coding standard for projects in the PHP Parallel Lint organisation.</description>
5+
6+
<!--
7+
#############################################################################
8+
CHECK CODE STYLE AGAINST PSR12
9+
https://www.php-fig.org/psr/psr-12/
10+
#############################################################################
11+
-->
12+
<rule ref="PSR12">
13+
<!-- Constant visibility is a PHP 7.1 feature and cannot (yet) be used. -->
14+
<exclude name="PSR12.Properties.ConstantVisibility"/>
15+
</rule>
16+
17+
<!-- ## Sniff specific configuration for sniffs included in PSR12 ## -->
18+
19+
<rule ref="Generic.Files.LineLength">
20+
<properties>
21+
<property name="lineLimit" value="125"/>
22+
<property name="absoluteLineLimit" value="200"/>
23+
</properties>
24+
</rule>
25+
26+
<rule ref="PSR12.ControlStructures.BooleanOperatorPlacement">
27+
<properties>
28+
<!-- Only allow them at the start of the line. -->
29+
<property name="allowOnly" value="first"/>
30+
</properties>
31+
</rule>
32+
33+
34+
<!--
35+
#############################################################################
36+
SNIFF FOR PHP CROSS-VERSION COMPATIBILITY
37+
https://github.com/PHPCompatibility/PHPCompatibility/
38+
39+
It is STRONGLY recommended for individual projects to set a `testVersion`
40+
config indicating which PHP versions should be supported.
41+
https://github.com/PHPCompatibility/PHPCompatibility/#using-a-custom-ruleset
42+
#############################################################################
43+
-->
44+
45+
<rule ref="PHPCompatibility"/>
46+
47+
48+
<!--
49+
#############################################################################
50+
MISCELLANEOUS ADDITIONAL RULES
51+
#############################################################################
52+
-->
53+
54+
<rule ref="Generic.Arrays.ArrayIndent"/>
55+
56+
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
57+
<rule ref="Generic.CodeAnalysis.EmptyPHPStatement"/>
58+
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
59+
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
60+
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
61+
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
62+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
63+
64+
<rule ref="Generic.ControlStructures.DisallowYodaConditions"/>
65+
66+
<rule ref="Generic.Formatting.SpaceAfterCast"/>
67+
68+
<rule ref="Generic.Metrics.CyclomaticComplexity"/>
69+
<rule ref="Generic.Metrics.NestingLevel"/>
70+
71+
<rule ref="Generic.NamingConventions.ConstructorName"/>
72+
73+
<rule ref="Generic.PHP.ForbiddenFunctions"/>
74+
<rule ref="Generic.PHP.NoSilencedErrors"/>
75+
76+
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
77+
78+
<rule ref="PEAR.Commenting.InlineComment"/>
79+
80+
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
81+
82+
<rule ref="Squiz.PHP.GlobalKeyword"/>
83+
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
84+
<rule ref="Squiz.PHP.NonExecutableCode"/>
85+
86+
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
87+
88+
</ruleset>

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
PHP Code Style
2+
=================
3+
4+
Basic, PSR-12 based, coding standard for use by projects in the PHP Parallel Lint GitHub organisation.
5+
6+
## Installation
7+
8+
Install this standard via Composer:
9+
10+
```bash
11+
composer require --dev php-parallel-lint/php-code-style
12+
```
13+
14+
## Using the standard
15+
16+
Once installed for a project, use this standard via the command-line:
17+
```bash
18+
vendor/bin/phpcs . --standard=PHPParallelLint
19+
```
20+
21+
Or use the standard in a project specific PHPCS ruleset:
22+
```xml
23+
<?xml version="1.0"?>
24+
<ruleset name="Project Name">
25+
26+
<rule ref="PHPParallelLint"/>
27+
28+
</ruleset>
29+
```

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "php-parallel-lint/php-code-style",
3-
"version": "1.0",
3+
"description": "PHP_CodeSniffer rules for projects in the PHP Parallel Lint organisation",
44
"type": "library",
55
"license": "MIT",
66
"authors": [
@@ -12,5 +12,10 @@
1212
],
1313
"replace": {
1414
"jakub-onderka/php-code-style": "*"
15+
},
16+
"require": {
17+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
18+
"phpcompatibility/php-compatibility": "^9.3",
19+
"squizlabs/php_codesniffer": "^3.6.1"
1520
}
1621
}

ruleset.xml

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)