Skip to content

Commit 8238be4

Browse files
committed
Code analysis
1 parent d7aef81 commit 8238be4

9 files changed

Lines changed: 24 additions & 18 deletions

File tree

phpstan.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ parameters:
88
- rector.php
99
# Ignore any vendor folder (https://phpstan.org/user-guide/ignoring-errors#excluding-whole-files)
1010
- vendor (?)
11+
12+
ignoreErrors:
13+
- '#Call to method Drupal\\Core\\Entity\\Query\\QueryInterface::accessCheck\(\) will always evaluate to true.#'
14+
- '#Call to method PHPUnit\\Framework\\Assert::assertTrue\(\) with true will always evaluate to true.#'

scripts/base

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ setup() {
8181
# @todo Do this in a dockerfile.
8282
compose exec drupal sh -c 'apt update && apt --yes install git'
8383

84-
COMPOSER=composer.lenient.json composer init --no-interaction
85-
COMPOSER=composer.lenient.json composer config --no-plugins allow-plugins.mglaman/composer-drupal-lenient true
86-
COMPOSER=composer.lenient.json composer require mglaman/composer-drupal-lenient
87-
# COMPOSER=composer.lenient.json rm composer.lenient.*
88-
8984
# Allow all plugins to run.
9085
composer --no-plugins config allow-plugins true
86+
composer --no-plugins config minimum-stability dev
9187

92-
composer config minimum-stability dev
88+
composer --no-plugins config extra.drupal-lenient.allow-all --json true
89+
# composer --no-plugins config extra.drupal-lenient.allowed-list --json '[ "drupal/coc_forms_auto_export", "drupal/webform_node_element" ]'
90+
composer require mglaman/composer-drupal-lenient --with-all-dependencies
9391

9492
# --------------------------------------------------------------------------------------------------------------------
9593
# We need to install dev requirements from our module, so we use
@@ -103,21 +101,23 @@ setup() {
103101
# Install wikimedia/composer-merge-plugin without any configuration
104102
composer require wikimedia/composer-merge-plugin --with-all-dependencies
105103
# Patch to make COMPOSER_IGNORE_PLATFORM_REQS=1 have effect
104+
# https://github.com/wikimedia/composer-merge-plugin/pull/253
106105
shell sh -c 'cd vendor/wikimedia/composer-merge-plugin/ && curl https://patch-diff.githubusercontent.com/raw/wikimedia/composer-merge-plugin/pull/253.diff | patch --strip=1'
107106

108107
# Configure wikimedia/composer-merge-plugin
109108
composer --no-plugins config extra.merge-plugin.include "$module_path/composer.json"
110109
# Use --json to actually set a boolean value (rather that a string value, e.g. "true")
111110
composer --no-plugins config extra.merge-plugin.merge-extra --json true
112111
composer --no-plugins config extra.merge-plugin.merge-extra-deep --json true
112+
113113
composer update
114114
# Our module and its dev requirements are now installed.
115115
# --------------------------------------------------------------------------------------------------------------------
116116

117117
# Reset Drupal installation
118118
compose exec drupal sh -c 'find . -name .ht.sqlite -ls -delete; rm web/sites/default/settings.php' || true
119119
# Install a minimal Drupal site.
120-
drush --yes site:install --db-url='sqlite://sites/default/files/.ht.sqlite?module=sqlite' minimal
120+
drush --yes site:install --db-url='sqlite://sites/default/files/.ht.sqlite?module=sqlite' minimal -vvv
121121

122122
# Uncomment this line if you need to debug
123123
# shell bash

src/Controller/Os2formsFordelingskomponentDistributionObjectPreviewController.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Drupal\webform\WebformInterface;
1414
use Drupal\webform\WebformSubmissionStorageInterface;
1515
use Symfony\Component\HttpFoundation\Request;
16-
use Symfony\Component\HttpFoundation\Response;
1716
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1817

1918
/**
@@ -24,7 +23,7 @@ final class Os2formsFordelingskomponentDistributionObjectPreviewController exten
2423
/**
2524
* The webform submission storage.
2625
*/
27-
private WebformSubmissionStorageInterface $submissionStorage;
26+
private readonly WebformSubmissionStorageInterface $submissionStorage;
2827

2928
public function __construct(
3029
private readonly Settings $settings,
@@ -36,7 +35,7 @@ public function __construct(
3635
/**
3736
* Builds the response.
3837
*/
39-
public function __invoke(Request $request, WebformInterface $webform, string $webform_handler): array|Response {
38+
public function __invoke(Request $request, WebformInterface $webform, string $webform_handler): array {
4039
try {
4140
$handler = $webform->getHandler($webform_handler);
4241
}
@@ -93,7 +92,6 @@ public function __invoke(Request $request, WebformInterface $webform, string $we
9392
'#render_url' => $renderUrl,
9493
'#preview_urls' => $previewUrls,
9594
];
96-
9795
}
9896

9997
}

src/Helper/WebformHelperSF2900.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected function getAttachment(WebformSubmissionInterface $submission, Handler
130130
$instance = $this->elementInfoManager->createInstance($type);
131131

132132
if (!$instance instanceof WebformAttachmentBase) {
133-
throw new InvalidAttachmentElementException(sprintf('Attachment element must be an instance of %s. Found %s.', WebformAttachmentBase::class, get_class($instance)));
133+
throw new InvalidAttachmentElementException(sprintf('Attachment element must be an instance of %s. Found %s.', WebformAttachmentBase::class, $instance::class));
134134
}
135135

136136
$fileName = $instance::getFileName($element, $submission);
@@ -217,6 +217,7 @@ public function createJob(WebformSubmissionInterface $webformSubmission, Webform
217217
catch (\Exception $exception) {
218218
$this->error('Error creating job for afsend.', $context + [
219219
'operation' => 'Fordelingskomponent afsend failed',
220+
'exception' => $exception,
220221
]);
221222
return NULL;
222223
}

src/Hook/ThemeHooks.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* Theme hook implementations.
77
*/
88
final class ThemeHooks {
9-
const ROUTING_INFO = 'os2forms_fordelingskomponent_routing_info';
10-
const DISTRIBUTION_OBJECT_PREVIEW = 'os2forms_fordelingskomponent_distribution_object_preview';
11-
const DISTRIBUTION_OBJECT_PREVIEW_RENDER = 'os2forms_fordelingskomponent_distribution_object_preview_render';
9+
const string ROUTING_INFO = 'os2forms_fordelingskomponent_routing_info';
10+
const string DISTRIBUTION_OBJECT_PREVIEW = 'os2forms_fordelingskomponent_distribution_object_preview';
11+
const string DISTRIBUTION_OBJECT_PREVIEW_RENDER = 'os2forms_fordelingskomponent_distribution_object_preview_render';
1212

1313
/**
1414
* Implements hook_theme().

src/Plugin/WebformHandler/WebformHandlerSF2900.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ final class WebformHandlerSF2900 extends WebformHandlerBase {
5454
/**
5555
* {@inheritdoc}
5656
*/
57+
#[\Override]
5758
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
5859
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
5960
$instance->settingsService = $container->get(Settings::class);
@@ -66,6 +67,7 @@ public static function create(ContainerInterface $container, array $configuratio
6667
/**
6768
* {@inheritdoc}
6869
*/
70+
#[\Override]
6971
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
7072
$form[DistributionContextSettings::NAME] = [
7173
'#type' => 'fieldset',
@@ -327,6 +329,7 @@ public function postPurge(array $webform_submissions) {
327329
/**
328330
* {@inheritdoc}
329331
*/
332+
#[\Override]
330333
public function getSummary() {
331334
$settings = $this->settingsService->getHandlerSettings($this);
332335

src/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Settings {
2020
/**
2121
* The config.
2222
*/
23-
private ImmutableConfig $config;
23+
private readonly ImmutableConfig $config;
2424

2525
public function __construct(
2626
ConfigFactoryInterface $configFactory,

src/Settings/AbstractSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static function kebab2camel(string $value): string {
135135
* @see https://stackoverflow.com/a/40514305/2502647
136136
*/
137137
public static function camel2kebab(string $value): string {
138-
return strtolower(preg_replace('/(?<=\d)(?=[A-Za-z])|(?<=[A-Za-z])(?=\d)|(?<=[a-z])(?=[A-Z])/', '_', $value));
138+
return strtolower((string) preg_replace('/(?<=\d)(?=[A-Za-z])|(?<=[A-Za-z])(?=\d)|(?<=[a-z])(?=[A-Z])/', '_', $value));
139139
}
140140

141141
}

src/Settings/DistributionContextSettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class DistributionContextSettings extends AbstractSettings {
2626
public ?string $brugervendtNoegle = NULL;
2727

2828
// @todo Use this?
29-
public const ROUTING_MODTAGER_AKTOER = 'routing_modtager_aktoer';
29+
public const string ROUTING_MODTAGER_AKTOER = 'routing_modtager_aktoer';
3030
public ?string $routingModtagerAktoer = NULL;
3131

3232
public const string TITEL = 'titel';

0 commit comments

Comments
 (0)