Skip to content

Commit

Permalink
remove support for versions less then php 8.1, nette/forms don't supp…
Browse files Browse the repository at this point in the history
…ort it anymore anyway...

switch to contributte codestyle, update phpunit
  • Loading branch information
dakorpar committed Jan 18, 2024
1 parent 580ba2b commit 7282105
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 121 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

strategy:
matrix:
php-version: [ "7.4" ]
php-version: [ "8.1" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:

strategy:
matrix:
php-version: [ "7.4" ]
php-version: [ "8.1" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

Expand Down Expand Up @@ -138,11 +138,11 @@ jobs:

strategy:
matrix:
php-version: [ "7.2", "7.3", "7.4", "8.0", "8.1", "8.2"]
php-version: ["8.1", "8.2"]
operating-system: [ "ubuntu-latest" ]
composer-args: [ "" ]
include:
- php-version: "7.2"
- php-version: "8.1"
operating-system: "ubuntu-latest"
composer-args: "--prefer-lowest"
- php-version: "8.3"
Expand Down Expand Up @@ -205,7 +205,7 @@ jobs:

strategy:
matrix:
php-version: [ "7.4" ]
php-version: [ "8.1" ]
operating-system: [ "ubuntu-latest" ]
fail-fast: false

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
}
],
"require": {
"php": ">=7.2",
"php": ">=8.1",
"nette/forms": "3.1.12",
"nette/application": "^3.0"
},
"require-dev": {
"ninjify/qa": "^v0.12",
"phpunit/phpunit": "^8.5",
"contributte/qa": "^v0.3",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^0.12.6",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-nette": "^0.12",
Expand Down
11 changes: 9 additions & 2 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?xml version="1.0"?>
<ruleset>
<!-- Contributte Coding Standard -->
<rule ref="./vendor/ninjify/coding-standard/contributte.xml">
<rule ref="./vendor/contributte/qa/ruleset.xml">
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" /> <!-- We have code in traits which has to be compatible with other classes and this rule breaks it-->
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.PartialUse" />

<!-- We have code in traits which has to be compatible with other classes and this rule breaks it-->
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint" />
<exclude name="SlevomatCodingStandard.Functions.StrictCall.StrictParameterMissing" />
</rule>

<!-- Specific rules -->
Expand Down
16 changes: 8 additions & 8 deletions src/BootstrapForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ class BootstrapForm extends Form
use BootstrapContainerTrait;
use AddRowTrait;

/** @var bool */
public static $allwaysUseNullable = false;

/** @var string Class to be added if this is ajax. Defaults to 'ajax' */
public $ajaxClass = 'ajax';

/** @var Html */
protected $elementPrototype;

/** @var int */
private static $bootstrapVersion = BootstrapVersion::V4;

/** @var bool */
private $isAjax = true;

Expand All @@ -40,24 +46,19 @@ class BootstrapForm extends Form
/** @var bool */
private $autoShowValidation = true;

/** @var bool */
public static $allwaysUseNullable = false;

/** @var int */
private static $bootstrapVersion = BootstrapVersion::V4;

/**
* @param IContainer|null $container
*/
public function __construct($container = null)
{
parent::__construct($container);

$this->setRenderer(new BootstrapRenderer());

$prototype = Html::el('form', [
'action' => '',
'method' => self::POST,
'class' => [],
'class' => [],
]);
$this->elementPrototype = $prototype;

Expand Down Expand Up @@ -86,7 +87,6 @@ public function getElementPrototype(): Html
return $this->elementPrototype;
}


/**
* @return BootstrapRenderer
*/
Expand Down
42 changes: 21 additions & 21 deletions src/BootstrapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,40 +159,40 @@ public function configElem($config, ?Html $el = null): ?Html
public function getConfig(): array
{
return [
Cnf::FORM => [],
Cnf::GROUP => [
Cnf::FORM => [],
Cnf::GROUP => [
Cnf::ELEMENT_NAME => 'fieldset',
],
Cnf::GROUP_LABEL => [
Cnf::ELEMENT_NAME => 'legend',
],

Cnf::GRID_ROW => [
Cnf::GRID_ROW => [
Cnf::ELEMENT_NAME => 'div',
Cnf::CLASS_ADD => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'row' : 'form-row',
Cnf::CLASS_ADD => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'row' : 'form-row',
],
Cnf::GRID_CELL => [
Cnf::ELEMENT_NAME => 'div',
],

Cnf::FORM_OWN_ERRORS => [],
Cnf::FORM_OWN_ERROR => [
Cnf::FORM_OWN_ERROR => [
Cnf::ELEMENT_NAME => 'div',
Cnf::CLASS_SET => ['alert', 'alert-danger'],
Cnf::CLASS_SET => ['alert', 'alert-danger'],
],

Cnf::PAIR => [
Cnf::PAIR => [
Cnf::ELEMENT_NAME => 'div',
Cnf::CLASS_SET => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'mb-3' : 'form-group',
Cnf::CLASS_SET => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'mb-3' : 'form-group',
],
Cnf::LABEL => [
Cnf::ELEMENT_NAME => 'label',
Cnf::CLASS_SET => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-label' : null,
Cnf::CLASS_SET => BootstrapForm::getBootstrapVersion() === BootstrapVersion::V5 ? 'form-label' : null,
],

Cnf::INPUT => [],
Cnf::INPUT => [],
// inputs which are normally inline elements (after bootstrap classes are applied)
Cnf::INPUT_VALID => [
Cnf::INPUT_VALID => [
Cnf::CLASS_ADD => 'is-valid',
],
Cnf::INPUT_INVALID => [
Expand All @@ -201,21 +201,21 @@ public function getConfig(): array

Cnf::DESCRIPTION => [
Cnf::ELEMENT_NAME => 'small',
Cnf::CLASS_SET => ['form-text', 'text-muted'],
Cnf::CLASS_SET => ['form-text', 'text-muted'],
],

Cnf::FEEDBACK => [
Cnf::FEEDBACK => [
Cnf::ELEMENT_NAME => 'div',
],
Cnf::FEEDBACK_VALID => [
Cnf::FEEDBACK_VALID => [
Cnf::CLASS_ADD => 'valid-feedback',
],
Cnf::FEEDBACK_INVALID => [
Cnf::CLASS_ADD => 'invalid-feedback',
],

// empty wrapper, but it gets utilized in side-by side and inline mode
Cnf::NON_LABEL => [
Cnf::NON_LABEL => [
Cnf::ELEMENT_NAME => null,
],
];
Expand All @@ -237,27 +237,27 @@ public function getConfigOverride(): array
$labelColClass .= ' col-form-label';

return [
RenderMode::INLINE => [
Cnf::FORM => [
RenderMode::INLINE => [
Cnf::FORM => [
Cnf::CLASS_ADD => 'form-inline',
],
Cnf::NON_LABEL => [
Cnf::ELEMENT_NAME => 'div',
],
],
RenderMode::SIDE_BY_SIDE_MODE => [
Cnf::PAIR => [
Cnf::PAIR => [
Cnf::CLASS_ADD => 'row',
],
Cnf::LABEL => [
Cnf::LABEL => [
Cnf::CLASS_ADD => $labelColClass,
],
Cnf::NON_LABEL => [
Cnf::ELEMENT_NAME => 'div',
Cnf::CLASS_SET => $nonLabelColClass,
Cnf::CLASS_SET => $nonLabelColClass,
],
],
RenderMode::VERTICAL_MODE => [],
RenderMode::VERTICAL_MODE => [],
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Enums/DateTimeFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static function validate(string $format, string $timeString): bool
}

/**
* Turns datetime format into a human readable format, e.g. 'd.m.Y' => 'dd.mm.yyyy'.
* Turns datetime format into a human readable format, e.g. 'd.m.Y' => 'dd.mm.yyyy'.
* Supported values: d, j, m, n, Y, y, a, A, g, G, h, H, i, s, c, U
*/
public static function toHumanFormat(string $format, bool $example = true, bool $appendExample = true): string
Expand Down
1 change: 1 addition & 0 deletions src/Enums/RenderMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RenderMode
* Labels above controls
*/
public const VERTICAL_MODE = 0;

/**
* Labels beside controls
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Enums/RendererConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RendererConfig
* Form group
*/
public const GROUP = 'group';

/**
* Label of a group
*/
Expand All @@ -35,6 +36,7 @@ class RendererConfig
* @see BootstrapRow
*/
public const GRID_ROW = 'grid-row';

/**
* @see BootstrapCell
*/
Expand All @@ -44,6 +46,7 @@ class RendererConfig
* Errors belonging to the form rather than an individual control. This is a container.
*/
public const FORM_OWN_ERRORS = 'form-own-errors';

/**
* Multiple of those will be inside FORM_OWN_ERRORS
*/
Expand All @@ -52,6 +55,7 @@ class RendererConfig
public const PAIR = 'pair';
public const LABEL = 'label';
public const DESCRIPTION = 'description';

/**
* form group parts which are not label - input, feedback, description
*/
Expand All @@ -63,6 +67,7 @@ class RendererConfig
public const INPUT = 'input';
public const INPUT_VALID = 'input-valid';
public const INPUT_INVALID = 'input-invalid';

/**
* Element that is normally an inline element within bootstrap
*/
Expand All @@ -71,10 +76,12 @@ class RendererConfig
* Text saying if field is valid or invalid
*/
public const FEEDBACK = 'feedback';

/**
* Child of 'feedback'. Extra attributes for invalid feedback
*/
public const FEEDBACK_VALID = 'feedback-valid';

/**
* Child of 'feedback'. Extra attributes for valid feedback
*/
Expand All @@ -84,20 +91,24 @@ class RendererConfig
* Element name
*/
public const ELEMENT_NAME = 'element';

/**
* Container. Must contain 'element' key. May be recursive.
*/
public const CONTAINER = 'container';

public const ATTRIBUTES = 'attributes';

/**
* Class or array of classes to set
*/
public const CLASS_SET = 'class-set';

/**
* Class or array of classes to add
*/
public const CLASS_ADD = 'class-add';

/**
* Class or array to classes to remove if they exist
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Enums/RendererOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,43 @@ class RendererOptions
* Internal. If control has already been rendered.
*/
public const _RENDERED = '_rendered';

/**
* Boolean. Can se set on groups, if false, group will not be rendered separately.
* Honestly I have no clue as to why would you do it, but is present on the original renderer...
*/
public const VISUAL = 'visual';

/**
* String|Html. Can be set on groups. If it's a string, it will be used as Html::el(container)
*/
public const CONTAINER = 'container';

/**
* String. Can be set on groups or controls. It is just a regular HTML attribute id.
* Note that if it's set on a control, it will be applied to the pair, not the control as it's already
* set internally.
*/
public const ID = 'id';

/**
* String. Standard input description, a.ka. bootstrap Help text
*/
public const DESCRIPTION = 'description';

/**
* String|Html. Can be set on a group and will dictate its <legend>. If it's a string, it will be
* translated (if applicable)
*/
public const LABEL = 'label';

/**
* String. Can be set on an input. If set to 'hidden', label is not rendered and all hidden inputs are
* rendered at the end of form.
* I wouldn't play with this.
*/
public const TYPE = 'type';

/**
* String. Can be set on an input. If form's validation state is shown and the input is valid, this is
* shown instead of an error
Expand Down
Loading

0 comments on commit 7282105

Please sign in to comment.