Skip to content

Commit c25cda7

Browse files
committed
Code analysis
1 parent 59fb8a5 commit c25cda7

10 files changed

Lines changed: 92 additions & 82 deletions

File tree

.github/workflows/project.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,4 @@ jobs:
5151
steps:
5252
- uses: actions/checkout@v5
5353
- run: |
54-
docker compose build
55-
docker compose run --user root --rm php composer install
56-
docker compose run --user root --rm --env COMPOSER_AUTH php scripts/code-analysis
54+
./scripts/code-analysis

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "itk-dev/dpl_pretix",
3+
"description": "pretix for DPL CMS",
4+
"license": "GPL-2.0-or-later",
35
"type": "drupal-module",
6+
"homepage": "https://www.drupal.org/project/dpl_pretix",
47
"require": {
58
"php": "^8.3",
69
"drupal/core-recommended": "^10"

docker-compose.override.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ services:
33
# At the time of writing, dpl-cms requires PHP 8.3 (!) (cf.
44
# https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/composer.json#L102)
55
image: itkdev/php8.3-fpm:latest
6+
profiles:
7+
- dev
8+
environment:
9+
PHP_MEMORY_LIMIT: 512M

phpstan.neon.dist

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ parameters:
99
- vendor
1010
ignoreErrors:
1111
- '#(Function|Method) (Drupal\\dpl_pretix\\|dpl_pretix_).+ return type has no value type specified in iterable type array.#'
12-
- '#(Function|Method) (Drupal\\dpl_pretix\\|dpl_pretix_).+ has parameter \$(element|form|options) with no value type specified in iterable type array.#'
12+
- '#(Function|Method) (Drupal\\dpl_pretix\\|dpl_pretix_).+ has parameter \$(element|form|complete_form|events_to_create|options) with no value type specified in iterable type array.#'
1313

14+
# https://github.com/drush-ops/drush/issues/6334
15+
scanDirectories:
16+
- ../../../../../../vendor/drush/drush/src-symfony-compatibility
1417

1518
# Local Variables:
1619
# mode: yaml

scripts/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COMPOSE_PROJECT_NAME=dpl_pretix_scripts

scripts/code-analysis

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ set -o errexit -o errtrace -o noclobber -o nounset -o pipefail
33
IFS=$'\n\t'
44

55
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
6-
project_dir=$(cd "$(dirname "$script_dir")" && pwd)
76

8-
cd "$project_dir" || exit
7+
cd "$script_dir" || exit
98

109
compose() {
1110
docker compose "$@"
@@ -23,77 +22,8 @@ shell() {
2322
compose exec dpl-cms "$@"
2423
}
2524

26-
set -x
25+
compose up --detach --build
2726

28-
drupal_dir=dpl-cms
29-
# Extract the module path from the service.
30-
module_path=$(compose run --rm dpl-cms sh -c 'echo $MODULE_PATH')
27+
shell vendor/bin/phpstan --configuration=web/sites/default/files/modules_local/dpl_pretix/phpstan.neon.dist
3128

32-
compose down --remove-orphans
33-
compose pull
34-
# mkdir -p dpl-cms/web/sites/default/files/modules_local
35-
compose up --detach --remove-orphans --wait
36-
37-
shell curl --location --remote-name https://github.com/danskernesdigitalebibliotek/dpl-cms/archive/refs/heads/main.tar.gz
38-
# https://linux.die.net/man/1/tar#content
39-
shell tar xvf main.tar.gz --strip-components=1
40-
41-
composer config --no-plugins allow-plugins true
42-
composer config extra.merge-plugin.include "$module_path/composer.json"
43-
composer require drush/drush wikimedia/composer-merge-plugin
44-
45-
composer require --dev symfony/phpunit-bridge
46-
47-
# # Run PHPStan
48-
# (cd "$drupal_dir/$module_path" && "$script_dir/$drupal_dir/vendor/bin/phpstan" --configuration=phpstan.neon.dist -vvv --debug)
49-
50-
# # Reset Drupal installation
51-
# compose exec drupal sh -c 'find . -name .ht.sqlite -ls -delete; rm web/sites/default/settings.php' || true
52-
# drush site:install --db-url='sqlite://sites/default/files/.ht.sqlite?module=sqlite' --yes
53-
# drush pm:install azure_ad_delta_sync
54-
# compose exec drupal php web/core/scripts/generate-proxy-class.php 'Drupal\azure_ad_delta_sync\UserManager' "$module_path/src"
55-
# compose exec drupal php web/core/scripts/generate-proxy-class.php 'Drupal\azure_ad_delta_sync\Controller' "$module_path/src"
56-
# compose down --remove-orphans
57-
58-
59-
# ------------------------------------------------------------------------------
60-
61-
62-
# #!/usr/bin/env bash
63-
64-
# script_dir=$PWD
65-
# module_name=dpl_pretix
66-
# drupal_dir=vendor/drupal-module-code-analysis
67-
# # Relative to $drupal_dir
68-
# module_path=web/sites/default/files/modules_local/$module_name
69-
70-
# cd "$script_dir" || exit
71-
72-
# drupal_composer() {
73-
# composer --working-dir="$drupal_dir" --no-interaction "$@"
74-
# }
75-
76-
# set -x
77-
78-
# rm -fr "$drupal_dir"
79-
# git clone --branch=develop --depth=1 https://github.com/danskernesdigitalebibliotek/dpl-cms "$drupal_dir"
80-
81-
# # Copy our code into the modules folder
82-
# mkdir -p "$drupal_dir/$module_path"
83-
84-
# # https://stackoverflow.com/a/15373763
85-
# rsync --archive --delete --compress . --filter=':- .gitignore' --exclude "$drupal_dir" --exclude .git "$drupal_dir/$module_path"
86-
87-
# drupal_composer config minimum-stability dev
88-
89-
# # Allow ALL plugins
90-
# # https://getcomposer.org/doc/06-config.md#allow-plugins
91-
# drupal_composer config --no-plugins allow-plugins true
92-
93-
# drupal_composer require wikimedia/composer-merge-plugin
94-
# drupal_composer config extra.merge-plugin.include "$module_path/composer.json"
95-
# # https://www.drupal.org/project/drupal/issues/3220043#comment-14845434
96-
# drupal_composer require --dev symfony/phpunit-bridge
97-
98-
# # Run PHPStan
99-
# (cd "$drupal_dir/$module_path" && "$script_dir/$drupal_dir/vendor/bin/phpstan" --configuration=phpstan.neon.dist -vvv --debug)
29+
compose down

scripts/compose.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
services:
2+
dpl-cms:
3+
# image: itkdev/php8.3-fpm:latest
4+
build:
5+
# context: .
6+
dockerfile_inline: |
7+
# syntax=docker/dockerfile:1
8+
# check=skip=SecretsUsedInArgOrEnv
9+
10+
FROM itkdev/php8.3-fpm:latest
11+
ENV PHP_MEMORY_LIMIT=512M
12+
13+
# https://stackoverflow.com/a/33439625
14+
SHELL ["/bin/bash", "-c"]
15+
16+
WORKDIR /app
17+
18+
RUN curl --location https://github.com/danskernesdigitalebibliotek/dpl-cms/archive/refs/heads/main.tar.gz --output main.tar.gz \
19+
&& tar xvf main.tar.gz --strip-components=1 \
20+
&& rm main.tar.gz \
21+
&& composer install
22+
23+
# Add the sqlite module to the existing config
24+
RUN sed --in-place '/dpl_event: 0/a \ \ sqlite: 0' config/sync/core.extension.yml \
25+
&& cat <<'EOF' > web/sites/default/settings.local.php
26+
<?php
27+
28+
$$databases['default']['default'] = [
29+
'driver' => 'sqlite',
30+
'database' => 'sites/default/files/.ht.sqlite',
31+
];
32+
EOF
33+
34+
ENV BNF_GRAPHQL_CONSUMER_SECRET=this_is_not_a_real_secret
35+
ENV GO_GRAPHQL_CONSUMER_SECRET=this_is_not_a_real_secret
36+
ENV BNF_GRAPHQL_CONSUMER_USER_PASSWORD==this_is_not_a_real_password
37+
ENV NEXT_PUBLIC_GO_GRAPHQL_CONSUMER_USER_PASSWORD=this_is_not_a_real_password
38+
39+
ENV GO_DOMAIN=dpl_pretix.example.com
40+
ENV LAGOON_ROUTE=https://dpl_pretix.example.com
41+
42+
RUN vendor/bin/drush site:install --existing-config --yes --account-mail itkdev+dpl_pretix@mkb.aarhus.dk --site-mail itkdev+dpl_pretix@mkb.aarhus.dk
43+
44+
# profiles:
45+
# - dev
46+
user: root
47+
volumes:
48+
# - ./settings.local.php:/app/web/sites/default/settings.local.php
49+
# Mount our code into the web/modules/contrib folder
50+
- ../:/app/web/sites/default/files/modules_local/dpl_pretix
51+
environment:
52+
# Let the module path, i.e. the mounted path, be known in the container
53+
MODULE_PATH: web/sites/default/files/modules_local/dpl_pretix
54+
55+
PHP_MAX_EXECUTION_TIME: 60
56+
PHP_MEMORY_LIMIT: 512M
57+
58+
BNF_GRAPHQL_CONSUMER_SECRET: this_is_not_a_real_secret
59+
GO_GRAPHQL_CONSUMER_SECRET: this_is_not_a_real_secret
60+
BNF_GRAPHQL_CONSUMER_USER_PASSWORD: =this_is_not_a_real_password
61+
NEXT_PUBLIC_GO_GRAPHQL_CONSUMER_USER_PASSWORD: this_is_not_a_real_password
62+
63+
GO_DOMAIN: dpl_pretix.example.com
64+
LAGOON_ROUTE: https://dpl_pretix.example.com

src/Form/SettingsForm.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Drupal\dpl_pretix\Settings;
1818
use Drupal\dpl_pretix\Settings\EventFormSettings;
1919
use Drupal\dpl_pretix\Settings\PretixSettings;
20+
use Drupal\field\FieldConfigInterface;
2021
use Drupal\user\RoleInterface;
2122
use Drupal\user\RoleStorageInterface;
2223
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -477,9 +478,13 @@ private function buildFormEventForm(array &$form): void {
477478
$section = self::SECTION_EVENT_FORM;
478479
$defaults = $this->settings->getEventForm();
479480

481+
$fieldRelevantTicketManagerLabel = EventFormSettings::FIELD_RELEVANT_TICKET_MANAGER;
482+
480483
$eventSeriesFields = $this->entityFieldManager->getFieldDefinitions('eventseries', 'default');
481-
$fieldRelevantTicketManagerLabel = $eventSeriesFields[EventFormSettings::FIELD_RELEVANT_TICKET_MANAGER]?->label()
482-
?? EventFormSettings::FIELD_RELEVANT_TICKET_MANAGER;
484+
$fieldRelevantTicketManager = $eventSeriesFields[EventFormSettings::FIELD_RELEVANT_TICKET_MANAGER] ?? NULL;
485+
if ($fieldRelevantTicketManager instanceof FieldConfigInterface) {
486+
$fieldRelevantTicketManagerLabel = $fieldRelevantTicketManager->label();
487+
}
483488

484489
// @todo Get the label from the actual field group.
485490
$ticketsGroupLabel = $this->t('Tickets');

src/FormHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function fieldGroupFormProcessBuildAlter(array &$element, FormStateInterf
118118
/**
119119
* Hide the Dates group depending on event series state.
120120
*/
121-
private function hideDatesGroup(array &$form, FormStateInterface $formState) {
121+
private function hideDatesGroup(array &$form, FormStateInterface $formState): void {
122122
if ($event = $this->getEventSeriesEntity($formState)) {
123123
$maintainCopy = (bool) $this->eventDataHelper->getEventData($event)?->maintainCopy;
124124
if ($event->isNew() || !$maintainCopy) {
@@ -140,7 +140,7 @@ private function hideDatesGroup(array &$form, FormStateInterface $formState) {
140140
// instance on the event series form (cf.
141141
// https://github.com/danskernesdigitalebibliotek/dpl-cms/blob/develop/web/modules/custom/dpl_event/src/Plugin/EventInstanceCreator/DplEventInstanceCreator.php#L31-L34).
142142
$datesGroupKey = 'group_dates';
143-
if ((int) $event?->getInstanceCount() > 1
143+
if ($event->getInstanceCount() > 1
144144
&& isset($form['#fieldgroups'][$datesGroupKey]) && isset($form[$datesGroupKey])) {
145145
$weight = $form['#fieldgroups'][$datesGroupKey]->weight;
146146
// unset($form['#fieldgroups'][$datesGroupKey]);

src/Settings/EventFormSettings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class EventFormSettings extends AbstractSettings {
3535

3636
/**
3737
* Roles that can delete event instances.
38+
*
39+
* @var array<string, string>
3840
*/
3941
public array $rolesThatCanDeleteEventInstances = [];
4042

0 commit comments

Comments
 (0)