Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.4
coverage: none
tools: cs2pr
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.4', '8.0', '8.2']
php-versions: ['8.1', '8.4']
prefer: ['prefer-stable', 'prefer-lowest']
name: PHPStan with PHP ${{ matrix.php-versions }} ${{ matrix.prefer }}

Expand Down Expand Up @@ -42,4 +42,4 @@ jobs:
composer composer-phpstan -- update --no-progress --prefer-dist --optimize-autoloader

- name: Run PHPStan
run: composer phpstan -- analyse -c phpstan.neon.dist
run: composer phpstan -- analyze -c phpstan.ci.neon
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
}
},
"require": {
"php": "^7.4 || ^8",
"php": "^8.1",
"systopia/expression-language-ext": "~0.1",
"systopia/opis-json-schema-ext": "~0.2"
},
"require-dev": {
"drupal/core": "^9.5 || ^10",
"drupal/core-dev": "^9.5 || ^10"
"drupal/core": "^10 || ^11",
"drupal/core-dev": "^10 || ^11"
},
"scripts": {
"composer-phpstan": [
Expand Down
4 changes: 2 additions & 2 deletions json_forms.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: JSONForms
type: module
description: Create a Drupal form from a JSONForms definition.
package: JSONForms
core_version_requirement: ^9.5 || ^10
php: 7.4
core_version_requirement: ^10 || ^11
php: 8.1
hidden: true
version: 0.7.1-dev
'interface translation project': json_forms
Expand Down
4 changes: 2 additions & 2 deletions modules/json_forms_example/json_forms_example.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: JSONForms example
type: module
description: Demonstrates how to use JSONForms.
package: JSONForms
core_version_requirement: ^9.5 || ^10
php: 7.4
core_version_requirement: ^10 || ^11
php: 8.1
dependencies:
- json_forms:json_forms
version: 0.7.1-dev
9 changes: 9 additions & 0 deletions phpstan.ci.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
includes:
- phpstan.neon.dist

parameters:
# Because we test with different versions in CI we have unmatched errors
reportUnmatchedIgnoredErrors: false
ignoreErrors:
# Required for Drupal 10.
- '#^Method Drupal\\Core\\Form\\FormBuilderInterface::getForm\(\) invoked with \d+ parameters, 1 required.$#'
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ parameters:
# https://youtrack.jetbrains.com/issue/WI-63891/PHPStan-ignoreErrors-configuration-isnt-working-with-inspections
# Wrong phpdoc type hint in Drupal
- '/^Parameter #1 \$key of method Drupal\\Core\\Form\\FormStateInterface::hasTemporaryValue\(\) expects string, array<int\|string> given.$/'
- '#^Method Drupal\\Core\\Form\\FormBuilderInterface::getForm\(\) invoked with \d+ parameters, 1 required.$#'
-
message: '#^Variable property access on mixed.$#'
paths:
Expand Down
1 change: 1 addition & 0 deletions src/Form/AbstractJsonFormsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ protected function buildJsonFormsForm(
$formState->set('uiSchema', $uiSchema);
$formState->set('recalculateOnChange', $recalculateOnChange);

// @phpstan-ignore equal.notAllowed
if (new \stdClass() == $uiSchema) {
return [];
}
Expand Down
2 changes: 0 additions & 2 deletions src/Form/Control/ArrayArrayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public function createFormArray(
FormArrayFactoryInterface $formArrayFactory
): array {
Assertion::isInstanceOf($definition, ControlDefinition::class);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\ControlDefinition $definition */
$definition = ArrayControlDefinition::fromDefinition($definition);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\ArrayControlDefinition $definition */

$fieldsetWrapperId = 'array-wrapper-' . str_replace('.', '__', implode('_', $definition->getPropertyPath()));
// phpcs:disable Drupal.Commenting.InlineComment.DocBlock
Expand Down
1 change: 1 addition & 0 deletions src/Form/Control/Callbacks/ArrayCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static function ajaxRemove(array &$form, FormStateInterface $formState):
$propertyPath = $triggeringElement['#_controlPropertyPath'];

$arrayForm = &self::getArrayForm($form, $triggeringElement);
// @phpstan-ignore argument.type
FormValueAccessor::setValue($arrayForm['items'], $propertyPath, $formState->getTemporaryValue($propertyPath));

/** @var \Drupal\Core\Render\MainContent\AjaxRenderer $ajaxRenderer */
Expand Down
1 change: 1 addition & 0 deletions src/Form/Control/Callbacks/NumberValueCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private static function isIntegerish($value): bool {
$value = \trim($value);
}

// @phpstan-ignore equal.notAllowed
return \is_numeric($value) && $value == (string) $value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private static function doAddAjaxCommands(
if ($oldData === $newData
|| NULL === $newData && '' === $oldData
|| \is_numeric($newData) && \is_numeric($oldData) && (float) $newData === (float) $oldData
// @phpstan-ignore equal.notAllowed
|| (is_bool($newData) && !$strictBooleanComparison && $newData == $oldData)
) {
return;
Expand Down
2 changes: 0 additions & 2 deletions src/Form/Control/CheckboxesArrayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public function createFormArray(
FormArrayFactoryInterface $formArrayFactory
): array {
Assertion::isInstanceOf($definition, ControlDefinition::class);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\ControlDefinition $definition */
$definition = ArrayControlDefinition::fromDefinition($definition);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\ArrayControlDefinition $definition */
$form = [
'#type' => 'checkboxes',
// @todo Handle non-string values and integerish strings.
Expand Down
2 changes: 0 additions & 2 deletions src/Form/Control/HtmlArrayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public function createFormArray(
FormArrayFactoryInterface $formArrayFactory
): array {
Assertion::isInstanceOf($definition, ControlDefinition::class);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\ControlDefinition $definition */
$definition = StringControlDefinition::fromDefinition($definition);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\StringControlDefinition $definition */

$form = [
'#type' => 'text_format',
Expand Down
2 changes: 0 additions & 2 deletions src/Form/Control/NumberArrayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public function createFormArray(
FormArrayFactoryInterface $formArrayFactory
): array {
Assertion::isInstanceOf($definition, ControlDefinition::class);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\ControlDefinition $definition */
$definition = NumberControlDefinition::fromDefinition($definition);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\NumberControlDefinition $definition */

$form = [
'#type' => 'number',
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/Rule/StatesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function buildCondition(ControlDefinition $definition, $value): array {
/**
* @phpstan-param scalar|array<scalar>|null $value
*
* @phpstan-return array<string|int, conditionT|'or'>>
* @phpstan-return array<string|int, conditionT|'or'>
*/
private function buildContainsCondition(string $fieldName, $value): array {
if (!is_array($value)) {
Expand Down
2 changes: 0 additions & 2 deletions src/Form/Control/StringArrayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public function createFormArray(
FormArrayFactoryInterface $formArrayFactory
): array {
Assertion::isInstanceOf($definition, ControlDefinition::class);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\ControlDefinition $definition */
$definition = StringControlDefinition::fromDefinition($definition);
/** @var \Drupal\json_forms\JsonForms\Definition\Control\StringControlDefinition $definition */

$form = [
'#type' => TRUE === $definition->getOptionsValue('multi', FALSE) ? 'textarea' : 'textfield',
Expand Down
1 change: 1 addition & 0 deletions src/Form/Control/Util/BasicFormPropertiesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static function createBasicProperties(ControlDefinition $definition): arr
DescriptionDisplayUtil::handleDescriptionDisplay($form, $definition->getOptionsValue('descriptionDisplay'));

if (NULL !== $definition->getOptionsValue('placeholder')) {
// @phpstan-ignore offsetAccess.nonOffsetAccessible
$form['#attributes']['placeholder'] = $definition->getOptionsValue('placeholder');
}

Expand Down
1 change: 0 additions & 1 deletion src/Form/Layout/AbstractLayoutArrayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function createFormArray(
FormArrayFactoryInterface $formArrayFactory
): array {
Assertion::isInstanceOf($definition, LayoutDefinition::class);
/** @var \Drupal\json_forms\JsonForms\Definition\Layout\LayoutDefinition $definition */
$form = $this->createBasicFormArray($definition);

// @phpstan-ignore argument.type
Expand Down
1 change: 1 addition & 0 deletions src/Form/Layout/TableArrayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private function getHeader(LayoutDefinition $definition): array {
}

/** @phpstan-var array<string|array<string, mixed>> $header */
// @phpstan-ignore varTag.type
return $header;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Util/DescriptionDisplayUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
final class DescriptionDisplayUtil {

/**
* @phpstan-param array<string, mixed> $form
* @phpstan-param array<int|string, mixed> $form
*/
public static function handleDescriptionDisplay(array &$form, ?string $descriptionDisplay): void {
if (NULL !== $descriptionDisplay) {
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Validation/FormValidationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function mapErrors(ValidationResult $validationResult, FormStateInterface
$element = [
'#parents' => FormValidationUtil::getFormErrorMapping(
$formState,
// @phpstan-ignore argument.type
// @phpstan-ignore argument.type, argument.type
FieldNameUtil::toFormParents($pointer->absolutePath())
),
];
Expand Down
10 changes: 3 additions & 7 deletions src/JsonForms/Definition/Control/ControlDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ class ControlDefinition implements DefinitionInterface {

private ?string $scopePrefix;

/**
* @param \Drupal\json_forms\JsonForms\Definition\Control\ControlDefinition $definition
*
* @return static
*/
public static function fromDefinition(ControlDefinition $definition): self {
public static function fromDefinition(ControlDefinition $definition): static {
return new static(
$definition->controlSchema,
$definition->objectSchema,
Expand Down Expand Up @@ -263,7 +258,7 @@ public function getPropertyKeywordValue(string $keyword, $default = NULL) {
* @return string Value of the attribute "name" in HTML.
*/
public function getPropertyFormName(): string {
if (NULL == $this->propertyFormName) {
if (NULL === $this->propertyFormName) {
$this->propertyFormName = FormPropertyUtil::getFormNameForPropertyPath($this->getPropertyPath());
}

Expand Down Expand Up @@ -326,6 +321,7 @@ public function getSuffix(): ?string {
*/
public function getType(): string {
if (is_array($this->propertySchema->type)) {
/** @var string $type */
foreach ($this->propertySchema->type as $type) {
if ('null' !== $type) {
return $type;
Expand Down
16 changes: 8 additions & 8 deletions tools/phpstan/composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"require": {
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.7",
"phpstan/phpstan-beberlei-assert": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-strict-rules": "^1.2",
"thecodingmachine/phpstan-strict-rules": "^1.0",
"voku/phpstan-rules": "^3"
"kcs/phpstan-strict-rules": "^2",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2",
"phpstan/phpstan-beberlei-assert": "^2",
"phpstan/phpstan-deprecation-rules": "^2",
"phpstan/phpstan-phpunit": "^2",
"phpstan/phpstan-strict-rules": "^2",
"voku/phpstan-rules": "^3.6"
},
"config": {
"allow-plugins": {
Expand Down