From cdc9ea8a974d7721562fdb24c659da53904bdec8 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Fri, 25 Oct 2024 13:50:23 +0300 Subject: [PATCH] feat: add ci actions --- .github/dependabot.yml | 14 +++++++++++ .github/workflows/php-cs-fixer.yml | 20 ++++++++++++++++ .github/workflows/phpstan.yml | 26 +++++++++++++++++++++ .github/workflows/rector.yaml | 37 ++++++++++++++++++++++++++++++ ruleset-php_cs.php | 1 + src/Calendar.php | 4 ++-- src/Config.php | 3 +++ src/Views/Month.php | 3 ++- src/Views/View.php | 2 +- src/Views/Week.php | 3 ++- 10 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/php-cs-fixer.yml create mode 100644 .github/workflows/phpstan.yml create mode 100644 .github/workflows/rector.yaml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6c9c95a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ + + +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: weekly + day: tuesday + time: "12:00" diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..9ae75b4 --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,20 @@ +name: Check & fix styling + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run PHP CS Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=ruleset-php_cs.php --allow-risky=yes --show-progress=dots --diff --dry-run diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..ce3784c --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,26 @@ +name: PHPStan + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + phpstan: + name: phpstan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github analyse -c ruleset-phpstan.neon -vvv diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml new file mode 100644 index 0000000..c9ce0ae --- /dev/null +++ b/.github/workflows/rector.yaml @@ -0,0 +1,37 @@ +name: Rector + +on: + push: + branches: [main] + pull_request: + branches: [main] + + +jobs: + rector: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Rector Cache + uses: actions/cache@v3 + with: + path: /tmp/rector + key: ${{ runner.os }}-rector-${{ github.run_id }} + restore-keys: ${{ runner.os }}-rector- + + - run: mkdir -p /tmp/rector + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.0 + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v3 + + - name: Rector Dry Run + run: php vendor/bin/rector process --dry-run --config=rector.php + + diff --git a/ruleset-php_cs.php b/ruleset-php_cs.php index 4a2fc97..2d2bd52 100644 --- a/ruleset-php_cs.php +++ b/ruleset-php_cs.php @@ -8,6 +8,7 @@ 'php_unit_method_casing' => ['case' => 'snake_case'], 'elseif' => true, 'phpdoc_align' => ['align' => 'left'], + 'global_namespace_import' => true, ]; $dirsToCheck = [ diff --git a/src/Calendar.php b/src/Calendar.php index fc41202..c4edf31 100644 --- a/src/Calendar.php +++ b/src/Calendar.php @@ -5,10 +5,10 @@ namespace benhall14\phpCalendar; use BadMethodCallException; -use DateTimeInterface; use benhall14\phpCalendar\Views\Month; use benhall14\phpCalendar\Views\Week; use Carbon\Carbon; +use DateTimeInterface; /** * Simple PHP Calendar Class. @@ -146,7 +146,7 @@ public function addEvent( * (optional) 'mask' => a masking class name. * (optional) 'classes' => custom classes to include. * - * @param iterable), mask?: bool, event_box_classes?: (string|list)}> $events the events array + * @param iterable), mask?: bool, event_box_classes?: (string|list)}> $events the events array */ public function addEvents(iterable $events): static { diff --git a/src/Config.php b/src/Config.php index 7229a56..d44598a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -56,6 +56,9 @@ class Config */ public array $hiddenDays = []; + /** + * @return list + */ public function getHiddenDays(): array { return array_intersect($this->hiddenDays, Carbon::getDays()); diff --git a/src/Views/Month.php b/src/Views/Month.php index 266d58a..6cba354 100644 --- a/src/Views/Month.php +++ b/src/Views/Month.php @@ -7,6 +7,7 @@ use benhall14\phpCalendar\Event; use Carbon\Carbon; use Carbon\CarbonInterface; +use DateTimeInterface; class Month extends View { @@ -22,7 +23,7 @@ protected function findEvents(CarbonInterface $start, CarbonInterface $end): arr /** * Returns the calendar as a month view. */ - public function render(\DateTimeInterface|string|null $startDate = null, string $color = ''): string + public function render(DateTimeInterface|string|null $startDate = null, string $color = ''): string { $calendar = $this->makeHiddenStyles(); diff --git a/src/Views/View.php b/src/Views/View.php index 0c983ee..1deab27 100644 --- a/src/Views/View.php +++ b/src/Views/View.php @@ -4,11 +4,11 @@ namespace benhall14\phpCalendar\Views; -use DateTimeInterface; use benhall14\phpCalendar\Calendar; use benhall14\phpCalendar\Config; use benhall14\phpCalendar\Event; use Carbon\CarbonInterface; +use DateTimeInterface; abstract class View { diff --git a/src/Views/Week.php b/src/Views/Week.php index 3ad738a..7689c65 100644 --- a/src/Views/Week.php +++ b/src/Views/Week.php @@ -4,12 +4,12 @@ namespace benhall14\phpCalendar\Views; -use DateTimeInterface; use benhall14\phpCalendar\Event; use Carbon\Carbon; use Carbon\CarbonInterface; use Carbon\CarbonInterval; use Carbon\CarbonPeriod; +use DateTimeInterface; class Week extends View { @@ -98,6 +98,7 @@ protected function makeHeader(CarbonPeriod $carbonPeriod): string if ($this->config->dayShouldBeHidden($carbon)) { continue; } + $headerString .= ''; $headerString .= '
'.ucfirst($carbon->localeDayOfWeek).'
'; $headerString .= '
'.$carbon->day.'
';