diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..2dca508 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,32 @@ +name: "Build" + +on: + pull_request: + push: + branches: + - master + +jobs: + phpstan: + name: PHPStan + + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: [ '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + + - name: Install dependencies + run: composer install --prefer-dist + + - name: Run PHPStan + run: composer phpstan diff --git a/.gitignore b/.gitignore index 0e36ec8..8ba2eba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor /composer.lock /.idea +/phpstan.neon diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8b9ead9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: php - -php: - - 7.1 - - 7.2 - - 7.3 - -matrix: - fast_finish: true - -cache: - directories: - - $HOME/.composer/cache - -before_script: - - composer install --no-interaction --prefer-source - -script: - - vendor/bin/phpstan analyze src -l 7 -c .phpstan.neon - -after_failure: - # Print *.actual content & log content - - for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done - - for i in $(find tests -name \*.log); do echo "--- $i"; cat $i; echo; echo; done diff --git a/composer.json b/composer.json index ea00042..83ac8ac 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,9 @@ "autoload": { "psr-4": { "Nextras\\FormsRendering\\": "src/" } }, + "scripts": { + "phpstan": "phpstan analyze" + }, "autoload-dev": { "psr-4": { "NextrasDemos\\FormsRendering\\LatteMacros\\": "examples/lattemacros/", diff --git a/examples/lattemacros/LatteMacrosPresenter.php b/examples/lattemacros/LatteMacrosPresenter.php index b26dca4..c24113d 100644 --- a/examples/lattemacros/LatteMacrosPresenter.php +++ b/examples/lattemacros/LatteMacrosPresenter.php @@ -8,12 +8,12 @@ class LatteMacrosPresenter extends Presenter { - public function actionDefault() + public function actionDefault(): void { } - public function createComponentForm() + public function createComponentForm(): Form { $form = new Form(); $form->addText('text', 'Name'); diff --git a/examples/renderers/RenderersPresenter.php b/examples/renderers/RenderersPresenter.php index dc343db..8a03322 100644 --- a/examples/renderers/RenderersPresenter.php +++ b/examples/renderers/RenderersPresenter.php @@ -25,14 +25,14 @@ class RenderersPresenter extends Presenter public $showBulky = true; - public function actionDefault() + public function actionDefault(): void { $this->template->renderer = $this->renderer; $this->template->showBulky = $this->showBulky; } - public function createComponentForm() + public function createComponentForm(): Form { $form = new Form(); $form->addText('text', 'Name'); diff --git a/.phpstan.neon b/phpstan.dist.neon similarity index 64% rename from .phpstan.neon rename to phpstan.dist.neon index 25bf1ec..ead69a6 100644 --- a/.phpstan.neon +++ b/phpstan.dist.neon @@ -1,3 +1,9 @@ includes: - vendor/phpstan/phpstan-nette/extension.neon - vendor/phpstan/phpstan-nette/rules.neon + +parameters: + level: max + paths: + - src + - examples diff --git a/readme.md b/readme.md index c9d2acc..1296d2f 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ Nextras Forms Rendering ======================= -[![Build Status](https://travis-ci.org/nextras/forms-rendering.svg?branch=master)](https://travis-ci.org/nextras/forms-rendering) +[![Build](https://github.com/nextras/forms-rendering/actions/workflows/build.yaml/badge.svg)](https://github.com/nextras/forms-rendering/actions/workflows/build.yaml) [![Downloads this Month](https://img.shields.io/packagist/dm/nextras/forms-rendering.svg?style=flat)](https://packagist.org/packages/nextras/forms-rendering) [![Stable version](http://img.shields.io/packagist/v/nextras/forms-rendering.svg?style=flat)](https://packagist.org/packages/nextras/forms-rendering) diff --git a/src/LatteTags/LabelNode.php b/src/LatteTags/LabelNode.php index ca6e386..33590b5 100644 --- a/src/LatteTags/LabelNode.php +++ b/src/LatteTags/LabelNode.php @@ -33,7 +33,8 @@ public function print(PrintContext $context): string $this->attributes, $this->position, $this->content, - $this->endLine + // TODO: Drop the `endLine` support once we no longer support forms < 3.3. + property_exists($this, 'endLine') ? $this->endLine : end($this->tagRanges), ); } diff --git a/src/Renderers/Bs4FormRenderer.php b/src/Renderers/Bs4FormRenderer.php index de1cafb..2397ed4 100644 --- a/src/Renderers/Bs4FormRenderer.php +++ b/src/Renderers/Bs4FormRenderer.php @@ -147,7 +147,7 @@ private function controlsInit(): void } foreach ($this->form->getControls() as $control) { - if ($this->layout === FormLayout::INLINE && !$control instanceof Controls\Checkbox) { + if ($this->layout === FormLayout::INLINE && !$control instanceof Controls\Checkbox && method_exists($control, 'getLabelPrototype')) { $control->getLabelPrototype()->addClass('my-1')->addClass('mr-2'); } diff --git a/src/Renderers/Bs5FormRenderer.php b/src/Renderers/Bs5FormRenderer.php index 8d6a025..c920aef 100644 --- a/src/Renderers/Bs5FormRenderer.php +++ b/src/Renderers/Bs5FormRenderer.php @@ -151,13 +151,13 @@ private function controlsInit(): void } foreach ($this->form->getControls() as $control) { - if ($this->layout === FormLayout::INLINE) { + if ($this->layout === FormLayout::INLINE && method_exists($control, 'getLabelPrototype')) { // Unfortunately, the aforementioned solution does not seem to expect labels // so we need to add some hacks. Notably, `.form-control`, `.form-select` and // others add `display: block`, forcing the control onto a next line. // The checkboxes are exception since they have their own inline class. - if (!$control instanceof Controls\Checkbox && !$control instanceof Controls\CheckboxList && !$control instanceof Controls\RadioList) { + if (!$control instanceof Controls\Checkbox && !$control instanceof Controls\CheckboxList && !$control instanceof Controls\RadioList && method_exists($control, 'getControlPrototype')) { $control->getControlPrototype()->addClass('d-inline-block'); // But setting `display: inline-block` is not enough since the widgets will inherit