Skip to content

Commit db609ef

Browse files
committed
ci: add static analysis and security workflows
1 parent d85a2b2 commit db609ef

12 files changed

+193
-20
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ representative at an online or offline event.
6060

6161
Instances of abusive, harassing, or otherwise unacceptable behavior may be
6262
reported to the community leaders responsible for enforcement at
63-
the@wayof.dev.
63+
<the@wayof.dev>.
6464
All complaints will be reviewed and investigated promptly and fairly.
6565

6666
All community leaders are obligated to respect the privacy and security of the
@@ -116,13 +116,13 @@ the community.
116116

117117
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118118
version 2.0, available at
119-
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
119+
<https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>.
120120

121121
Community Impact Guidelines were inspired by [Mozilla's code of conduct
122122
enforcement ladder](https://github.com/mozilla/diversity).
123123

124124
[homepage]: https://www.contributor-covenant.org
125125

126126
For answers to common questions about this code of conduct, see the FAQ at
127-
https://www.contributor-covenant.org/faq. Translations are available at
128-
https://www.contributor-covenant.org/translations.
127+
<https://www.contributor-covenant.org/faq>. Translations are available at
128+
<https://www.contributor-covenant.org/translations>.

.github/workflows/security.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
3+
name: 🔐 Security analysis
4+
5+
on: # yamllint disable-line rule:truthy
6+
pull_request:
7+
push:
8+
9+
jobs:
10+
security-analysis:
11+
timeout-minutes: 4
12+
runs-on: ${{ matrix.os }}
13+
concurrency:
14+
cancel-in-progress: true
15+
group: security-analysis-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
16+
strategy:
17+
fail-fast: true
18+
matrix:
19+
os:
20+
- ubuntu-latest
21+
php-version:
22+
- '8.2'
23+
dependencies:
24+
- locked
25+
steps:
26+
- name: 📦 Check out the codebase
27+
uses: actions/checkout@v4.1.5
28+
29+
- name: 🛠️ Setup PHP
30+
uses: shivammathur/setup-php@2.30.4
31+
with:
32+
php-version: ${{ matrix.php-version }}
33+
extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets
34+
ini-values: error_reporting=E_ALL
35+
coverage: none
36+
37+
- name: 🛠️ Setup problem matchers
38+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
39+
40+
- name: 🤖 Validate composer.json and composer.lock
41+
run: composer validate --ansi --strict
42+
43+
- name: 🔍 Get composer cache directory
44+
uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0
45+
46+
- name: ♻️ Restore cached dependencies installed with composer
47+
uses: actions/cache@v4.0.2
48+
with:
49+
path: ${{ env.COMPOSER_CACHE_DIR }}
50+
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
51+
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
52+
53+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies
54+
uses: wayofdev/gh-actions/actions/composer/install@v3.1.0
55+
with:
56+
dependencies: ${{ matrix.dependencies }}
57+
58+
- name: 🐛 Check installed packages for security vulnerability advisories
59+
run: composer audit --ansi

.github/workflows/static-analysis.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
3+
on: # yamllint disable-line rule:truthy
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- 'src/**'
9+
- 'tests/**'
10+
- 'bin/trap'
11+
- '.php-cs-fixer.dist.php'
12+
pull_request:
13+
branches:
14+
- master
15+
paths:
16+
- 'src/**'
17+
- 'tests/**'
18+
- 'bin/trap'
19+
- '.php-cs-fixer.dist.php'
20+
21+
name: 🔍 Static analysis
22+
23+
jobs:
24+
static-analysis:
25+
timeout-minutes: 4
26+
runs-on: ${{ matrix.os }}
27+
concurrency:
28+
cancel-in-progress: true
29+
group: static-analysis-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
30+
strategy:
31+
fail-fast: true
32+
matrix:
33+
os:
34+
- ubuntu-latest
35+
php-version:
36+
- '8.2'
37+
dependencies:
38+
- locked
39+
steps:
40+
- name: 📦 Check out the codebase
41+
uses: actions/checkout@v4.1.5
42+
43+
- name: 🛠️ Setup PHP
44+
uses: shivammathur/setup-php@2.30.4
45+
with:
46+
php-version: ${{ matrix.php-version }}
47+
extensions: none, ctype, curl, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter, sockets, opcache, pcntl, posix
48+
ini-values: error_reporting=E_ALL
49+
coverage: none
50+
51+
- name: 🛠️ Setup problem matchers
52+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
53+
54+
- name: 🤖 Validate composer.json and composer.lock
55+
run: composer validate --ansi --strict
56+
57+
- name: 🔍 Get composer cache directory
58+
uses: wayofdev/gh-actions/actions/composer/get-cache-directory@v3.1.0
59+
60+
- name: ♻️ Restore cached dependencies installed with composer
61+
uses: actions/cache@v4.0.2
62+
with:
63+
path: ${{ env.COMPOSER_CACHE_DIR }}
64+
key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }}
65+
restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-
66+
67+
- name: 📥 Install "${{ matrix.dependencies }}" dependencies
68+
uses: wayofdev/gh-actions/actions/composer/install@v3.1.0
69+
with:
70+
dependencies: ${{ matrix.dependencies }}
71+
72+
- name: 🔍 Run static analysis using phpstan/phpstan
73+
run: composer stan:ci

.pre-commit-config.yaml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,40 @@
22

33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.3.0
5+
rev: v4.6.0
66
hooks:
77
- id: trailing-whitespace
88
- id: end-of-file-fixer
99
- id: check-added-large-files
10-
- id: fix-encoding-pragma
10+
args: ['--maxkb=600']
1111

1212
- repo: https://github.com/commitizen-tools/commitizen
13-
rev: v2.28.0
13+
rev: v3.26.0
1414
hooks:
1515
- id: commitizen
1616
stages:
1717
- commit-msg
1818

19+
- repo: local
20+
hooks:
21+
- id: php-cs-fixer
22+
name: PHP CS Fixer
23+
description: Lint files using PHP CS Fixer
24+
entry: vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --verbose --diff
25+
language: system
26+
types: [php]
27+
exclude: ^vendor/
28+
files: \.php$
29+
pass_filenames: false
30+
require_serial: true
31+
32+
- repo: local
33+
hooks:
34+
- id: markdownlint
35+
name: markdownlint-cli2
36+
description: Run markdownlint-cli2 on your Markdown files using the docker image
37+
language: docker_image
38+
types: [markdown]
39+
entry: davidanson/markdownlint-cli2-rules:latest
40+
1941
...

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<br>
22

33
<div align="center">
4-
<img width="456" src="https://raw.githubusercontent.com/wayofdev/php-cs-fixer-config/master/assets/logo.gh-light-mode-only.png#gh-light-mode-only">
5-
<img width="456" src="https://raw.githubusercontent.com/wayofdev/php-cs-fixer-config/master/assets/logo.gh-dark-mode-only.png#gh-dark-mode-only">
4+
<img alt="Logo for Light Theme" width="456" src="https://raw.githubusercontent.com/wayofdev/php-cs-fixer-config/master/assets/logo.gh-light-mode-only.png#gh-light-mode-only">
5+
<img alt="Logo for Dark Theme" width="456" src="https://raw.githubusercontent.com/wayofdev/php-cs-fixer-config/master/assets/logo.gh-dark-mode-only.png#gh-dark-mode-only">
66
</div>
77

8-
9-
108
<br>
119

1210
<br>
@@ -36,7 +34,7 @@ If you **like/use** this package, please consider **starring** it. Thanks!
3634
Require as dependency:
3735

3836
```bash
39-
$ composer req wayofdev/cs-fixer-config
37+
composer req wayofdev/cs-fixer-config
4038
```
4139

4240
<br>
@@ -75,7 +73,7 @@ $ composer req wayofdev/cs-fixer-config
7573
Fix coding standards by simply running console command:
7674

7775
```bash
78-
$ php vendor/bin/php-cs-fixer fix -v
76+
php vendor/bin/php-cs-fixer fix -v
7977
```
8078

8179
### → Using Makefile
@@ -112,23 +110,23 @@ To use with our `Makefile`:
112110
To run tests, run the following command:
113111

114112
```bash
115-
$ make test
113+
make test
116114
```
117115

118116
### → Static Analysis
119117

120118
Code quality using PHPStan:
121119

122120
```bash
123-
$ make stan
121+
make stan
124122
```
125123

126124
### → Coding Standards Fixing
127125

128126
Fix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards:
129127

130128
```bash
131-
$ make cs-fix
129+
make cs-fix
132130
```
133131

134132
<br>

phpstan-baseline.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
ignoreErrors: []

phpstan.neon.dist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
14
parameters:
25
level: max
3-
46
paths:
57
- src/
68
- tests/
7-
8-
checkMissingIterableValueType: false
9-
9+
- .php-cs-fixer.dist.php
1010
tmpDir: .build/phpstan/

src/ConfigBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public static function createFromRuleSet(RuleSet $ruleSet): self
2828
}
2929

3030
/**
31+
* @param array<mixed> $arguments
32+
*
3133
* @throws BadMethodCallException
3234
*/
3335
public function __call(string $name, array $arguments): self
@@ -50,6 +52,9 @@ public function inDir(string $dir): self
5052
return $this;
5153
}
5254

55+
/**
56+
* @param array<mixed> $files
57+
*/
5358
public function addFiles(array $files): self
5459
{
5560
$this->getFinder()->append($files);

src/RuleSet.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ public function allowRisky(): bool;
1212

1313
public function useCache(): bool;
1414

15+
/**
16+
* @return array<string, array<string, mixed>|bool>
17+
*/
1518
public function rules(): array;
1619
}

src/RuleSets/DefaultSet.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
final class DefaultSet implements RuleSet
1313
{
14+
/**
15+
* @param array<string, array<string, mixed>|bool> $rules
16+
*/
1417
public function __construct(private readonly array $rules = [])
1518
{
1619
}

src/RuleSets/ExtendedPERSet.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
final class ExtendedPERSet implements RuleSet
1313
{
14+
/**
15+
* @param array<string, array<string, mixed>|bool> $rules
16+
*/
1417
public function __construct(private readonly array $rules = [])
1518
{
1619
}

tests/Unit/ConfigBuilderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ public function it_overrides_default_rules(): void
131131
self::assertEmpty(array_diff_assoc($expected, $rules));
132132
}
133133

134+
/**
135+
* @param iterable<SplFileInfo> $finder
136+
*
137+
* @return array<string>
138+
*/
134139
private function finderToArray(iterable $finder): array
135140
{
136141
$map = static function (SplFileInfo $info): string {

0 commit comments

Comments
 (0)