Skip to content

Commit fe1d64e

Browse files
committed
Automalically check and fix coding-style
1 parent 0743ea0 commit fe1d64e

File tree

9 files changed

+140
-23
lines changed

9 files changed

+140
-23
lines changed

.github/workflows/format_php.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Format (PHP)
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
- 'composer.*'
8+
- 'phpcs.xml'
9+
10+
jobs:
11+
format_php:
12+
name: Format PHP
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 7
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
ref: ${{ github.head_ref }}
19+
20+
# mtime needs to be restored for PHP-CS-Fixer cache to work correctly
21+
- name: Restore mtimes
22+
uses: weirdan/git-restore-mtime-action@master
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: 8.2
28+
coverage: none
29+
tools: cs2pr
30+
env:
31+
COMPOSER_TOKEN: ${{ secrets.GH_TOKEN_FOR_COMPOSER_FOR_PRIVATE_REPOS }}
32+
33+
- name: Get Composer cache directory
34+
id: composer-cache
35+
run: |
36+
echo "::set-output name=dir::$(composer config cache-files-dir)"
37+
38+
- name: Retrieve Composer‘s cache
39+
uses: actions/cache@v3
40+
with:
41+
path: ${{ steps.composer-cache.outputs.dir }}
42+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
43+
restore-keys: |
44+
${{ runner.os }}-composer-
45+
46+
- name: Install composer dependencies -- step 1
47+
run: 'composer install --working-dir=tools/php-cs-fixer --no-interaction --no-progress --no-scripts'
48+
49+
- name: Install composer dependencies -- step 2
50+
run: 'composer install --working-dir=tools/phpcs --no-interaction --no-progress --no-scripts'
51+
52+
- name: Retrieve PHP-CS-Fixer‘s cache
53+
uses: actions/cache@v3
54+
with:
55+
path: .php-cs-fixer.cache
56+
key: ${{ runner.os }}-php-cs-fixer-${{ hashFiles('.php-cs-fixer.php', '.phpcs/**/**') }}
57+
restore-keys: |
58+
${{ runner.os }}-php-cs-fixer-
59+
60+
- name: Retrieve PHPCS‘s cache
61+
uses: actions/cache@v3
62+
with:
63+
path: .phpcs.cache
64+
key: ${{ runner.os }}-phpcs-${{ hashFiles('phpcs.xml') }}
65+
restore-keys: |
66+
${{ runner.os }}-phpcs-
67+
68+
- name: Detect PHP coding style issues
69+
id: lint_php
70+
run: composer php:lint
71+
continue-on-error: true
72+
73+
- name: Fix detected PHP coding style issues (if any)
74+
if: ${{ steps.lint_php.outcome == 'failure' }}
75+
id: fix_php
76+
run: composer php:fix
77+
continue-on-error: true
78+
79+
- name: Commit PHP code-style fixes (if any)
80+
if: ${{ steps.lint_php.outcome == 'failure' }}
81+
uses: EndBug/add-and-commit@v9
82+
with:
83+
message: '#15000 🪄️ Apply coding style fixes to PHP'
84+
committer_name: GitHub Actions
85+
committer_email: [email protected]
86+
add: '*.php'
87+
pull: '--rebase --autostash'
88+
89+
- name: Lint PHP coding style issues (if previously detected)
90+
if: ${{ steps.lint_php.outcome == 'failure' }}
91+
run: composer phpcs -- --report-full --report-checkstyle=./phpcs-report.xml
92+
93+
- name: Show PHPCS results in on GitHub UI
94+
if: ${{ steps.lint_php.outcome == 'failure' }}
95+
run: cs2pr ./phpcs-report.xml

composer.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "interaction-design-foundation/nova-html-card",
33
"description": "A Laravel Nova card to display arbitrary HTML content",
4+
"license": "MIT",
45
"keywords": [
56
"laravel",
67
"nova",
@@ -9,21 +10,24 @@
910
"text",
1011
"markdown"
1112
],
12-
"license": "MIT",
1313
"require": {
1414
"php": ">=8.0",
1515
"laravel/nova": "^4.20"
1616
},
1717
"require-dev": {
18+
"interaction-design-foundation/coding-standard": "^0.0.4",
1819
"orchestra/testbench": "^7.0",
1920
"phpunit/phpunit": "^9.6 || ^10.0",
2021
"vimeo/psalm": "^5.6"
2122
},
2223
"repositories": [
2324
{
24-
"type": "composer", "url": "https://nova.laravel.com"
25+
"type": "composer",
26+
"url": "https://nova.laravel.com"
2527
}
2628
],
29+
"minimum-stability": "dev",
30+
"prefer-stable": true,
2731
"autoload": {
2832
"psr-4": {
2933
"InteractionDesignFoundation\\HtmlCard\\": "src/"
@@ -34,19 +38,22 @@
3438
"InteractionDesignFoundation\\HtmlCard\\Tests\\": "tests"
3539
}
3640
},
41+
"config": {
42+
"allow-plugins": {
43+
"dealerdirect/phpcodesniffer-composer-installer": true
44+
},
45+
"sort-packages": true
46+
},
3747
"extra": {
3848
"laravel": {
3949
"providers": [
4050
"InteractionDesignFoundation\\HtmlCard\\CardServiceProvider"
4151
]
4252
}
4353
},
44-
"config": {
45-
"sort-packages": true
46-
},
47-
"minimum-stability": "dev",
48-
"prefer-stable": true,
4954
"scripts": {
55+
"cs:check": "phpcs -p -s --colors --report-full --report-summary",
56+
"cs:fix": "phpcbf -p --colors",
5057
"test": "phpunit --colors=always"
5158
}
5259
}

phpcs.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="My Coding Standard">
3+
<!-- Include all rules from the IxDF Coding Standard -->
4+
<rule ref="IxDFCodingStandard">
5+
<exclude ref="IxDFCodingStandard.Files.BemCasedFilename.InvalidCharacters"/>
6+
<exclude ref="SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal"/>
7+
<exclude ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName.NoMatchBetweenTypeNameAndFileName"/>
8+
</rule>
9+
10+
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
11+
<exclude-pattern>./tests*</exclude-pattern>
12+
</rule>
13+
14+
<rule ref="Generic.Files.LineLength.TooLong">
15+
<severity>1</severity><!-- Temp hide the warn -->
16+
</rule>
17+
18+
<!-- Paths to check -->
19+
<file>src</file>
20+
<file>tests</file>
21+
</ruleset>

src/CardServiceProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
namespace InteractionDesignFoundation\HtmlCard;
44

5-
use Laravel\Nova\Nova;
6-
use Laravel\Nova\Events\ServingNova;
75
use Illuminate\Support\ServiceProvider;
6+
use Laravel\Nova\Events\ServingNova;
7+
use Laravel\Nova\Nova;
88

9-
class CardServiceProvider extends ServiceProvider
9+
class CardServiceProvider extends ServiceProvider // phpcs:ignore SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal
1010
{
1111
/**
1212
* Bootstrap any application services.
1313
* @return void
1414
*/
1515
public function boot()
1616
{
17-
Nova::serving(function (ServingNova $event) {
17+
Nova::serving(static function (ServingNova $event) {
1818
Nova::script('html-card', __DIR__.'/../dist/js/card.js');
1919
});
2020
}

src/HtmlCard.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Support\Facades\App;
66
use Laravel\Nova\Card;
77

8-
class HtmlCard extends Card
8+
class HtmlCard extends Card // phpcs:ignore SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal
99
{
1010
/**
1111
* The width of the card (1/3, 1/2, or full).
@@ -15,9 +15,8 @@ class HtmlCard extends Card
1515

1616
/**
1717
* Create a new element.
18-
* @param string|null $component
1918
*/
20-
public function __construct($component = null)
19+
public function __construct(string | null $component = null)
2120
{
2221
parent::__construct($component);
2322

@@ -54,8 +53,8 @@ public function markdown(string $markdownContent): static
5453

5554
/**
5655
* Use blade view file to render Card content.
57-
* @param string $view
5856
* @param array<string, mixed> $viewData
57+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint.DisallowedMixedTypeHint
5958
*/
6059
public function view(string $view, array $viewData = []): static
6160
{

src/LaravelMarkdownConverter.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66

77
final class LaravelMarkdownConverter extends Markdown implements MarkdownConverter
88
{
9-
109
}

src/MarkdownConverter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface MarkdownConverter
88
* Parse the given Markdown text into HTML.
99
* @param string $text
1010
* @return \Illuminate\Support\HtmlString
11+
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
1112
*/
1213
public static function parse($text);
1314
}

tests/CardServiceProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace InteractionDesignFoundation\HtmlCard\Tests;
44

5-
use InteractionDesignFoundation\HtmlCard\MarkdownConverter;
65
use Illuminate\Support\Facades\App;
6+
use InteractionDesignFoundation\HtmlCard\MarkdownConverter;
77

88
/** @covers \InteractionDesignFoundation\HtmlCard\CardServiceProvider */
99
final class CardServiceProviderTest extends TestCase

tests/TestCase.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77

88
abstract class TestCase extends OrchestraTestCase
99
{
10-
public function setUp(): void
11-
{
12-
parent::setUp();
13-
}
14-
1510
/** @inheritDoc */
16-
protected function getPackageProviders($app): array
11+
protected function getPackageProviders(): array
1712
{
1813
return [
1914
CardServiceProvider::class,

0 commit comments

Comments
 (0)