From 6858574adf83305db0957c9ec41ad40dec77fc31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dezs=C5=91=20BICZ=C3=93?= <mxr576@gmail.com>
Date: Sun, 2 Mar 2025 13:38:07 +0100
Subject: [PATCH] Add Gitlab CI integration

by using PHP CS Fixer for linting instead of PHPCS and dropping PHPStan 2.x as requirement due to the lack of support for that before 11.2.0.

https://git.drupalcode.org/project/drupal/-/commit/220988979f7d2d20184f3d1f5c26fb47f025844b
---
 .gitignore            |  1 +
 .gitlab-ci.yml        | 54 ++++++++++++++++++++++++++++++++++++++
 .php-cs-fixer.php     | 60 +++++++++++++++++++++++++++++++++++++++++++
 composer.json         | 15 ++++++++---
 phpstan-baseline.neon |  0
 phpstan.neon          | 23 +++++++++++++++++
 6 files changed, 150 insertions(+), 3 deletions(-)
 create mode 100644 .gitlab-ci.yml
 create mode 100644 .php-cs-fixer.php
 create mode 100644 phpstan-baseline.neon
 create mode 100644 phpstan.neon

diff --git a/.gitignore b/.gitignore
index d3af295..65c8673 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
 /recipes
 /.ddev/config.local.yml
 composer.lock
+.php-cs-fixer.cache
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..4514871
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,54 @@
+################
+# GitLabCI template for Drupal projects.
+#
+# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification.
+# It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
+# As long as you include the project, ref and three files below, any future updates added by the Drupal Association will be used in your
+# pipelines automatically. However, you can modify this template if you have additional needs for your project.
+# The full documentation is on https://project.pages.drupalcode.org/gitlab_templates/
+################
+
+# For information on alternative values for 'ref' see https://project.pages.drupalcode.org/gitlab_templates/info/templates-version/
+# To test a Drupal 7 project, change the first include filename from .main.yml to .main-d7.yml
+include:
+  - project: $_GITLAB_TEMPLATES_REPO
+    ref: $_GITLAB_TEMPLATES_REF
+    file:
+      - "/includes/include.drupalci.main.yml"
+      - "/includes/include.drupalci.variables.yml"
+      - "/includes/include.drupalci.workflows.yml"
+
+################
+# Pipeline configuration variables are defined with default values and descriptions in the file
+# https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
+# Uncomment the lines below if you want to override any of the variables. The following is just an example.
+################
+# variables:
+#   SKIP_ESLINT: '1'
+#   OPT_IN_TEST_NEXT_MAJOR: '1'
+#   _CURL_TEMPLATES_REF: 'main'
+
+variables:
+  SKIP_CSPELL: '1'
+  SKIP_PHPCS: '1'
+
+php-cs-fixer:
+  stage: validate
+  rules:
+    - allow_failure: true
+    - when: on_success
+  needs:
+    - composer
+  script:
+    - cd $CI_PROJECT_DIR && pwd
+    - vendor/bin/php-cs-fixer fix --dry-run $_WEB_ROOT/modules/custom --format=junit > junit.xml
+  allow_failure: true
+  artifacts:
+    expose_as: junit
+    expire_in: 6 mos
+    when: always
+    name: artifacts-$CI_PIPELINE_ID-$CI_JOB_NAME_SLUG
+    paths:
+      - junit.xml
+    reports:
+      junit: junit.xml
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
new file mode 100644
index 0000000..350bdef
--- /dev/null
+++ b/.php-cs-fixer.php
@@ -0,0 +1,60 @@
+<?php
+
+use Ergebnis\License;
+use drupol\PhpCsFixerConfigsDrupal\Config\Drupal8;
+
+$finder = PhpCsFixer\Finder::create()
+  ->in(__DIR__)
+  ->notPath(['web', 'vendor', '.ddev', 'recipes'])
+  ->name('*.module')
+  ->name('*.inc')
+  ->name('*.install')
+  ->name('*.test')
+  ->name('*.profile')
+  ->name('*.theme');
+
+$license = License\Type\None::text(
+  License\Range::since(
+    License\Year::fromString('2025'),
+    new DateTimeZone('UTC')
+  ),
+  License\Holder::fromString('Dezső Biczó'),
+  License\Url::fromString('http://www.gnu.org/licenses/old-licenses/gpl-2.0.html')
+);
+
+$config = new Drupal8();
+$config->setFinder($finder);
+
+$rules = $config->getRules();
+$rules = array_merge($rules, [
+  'header_comment' => [
+    'comment_type' => 'PHPDoc',
+    'header' => $license->header(),
+    'location' => 'after_declare_strict',
+    'separate' => 'both',
+  ],
+  'ordered_class_elements' => [
+    'order' => [
+      'use_trait',
+      'constant_public',
+      'constant_protected',
+      'constant_private',
+      'property_public',
+      'property_protected',
+      'property_private',
+      'construct',
+      'destruct',
+      'magic',
+      'method_static',
+      'phpunit',
+      'method_public',
+      'method_protected',
+      'method_private',
+    ],
+    'sort_algorithm' => 'alpha',
+    'case_sensitive' => false,
+  ],
+]);
+
+$config->setRules($rules);
+return $config;
diff --git a/composer.json b/composer.json
index 37cc836..b457291 100644
--- a/composer.json
+++ b/composer.json
@@ -7,9 +7,18 @@
     "php": "8.1.* || 8.2.* || 8.3.*",
     "drupal/core": "^10.3.2 || ^11.0.0"
   },
+  "config": {
+    "sort-packages": true,
+    "allow-plugins": {
+      "phpstan/extension-installer": true
+    }
+  },
   "require-dev": {
-    "mglaman/phpstan-drupal": "^2.0.0",
-    "phpstan/phpstan": "^2.1.0",
-    "phpstan/phpstan-deprecation-rules": "^2.0.1"
+    "drupol/phpcsfixer-configs-drupal": "^2.2",
+    "ergebnis/license": "^2.6",
+    "mglaman/phpstan-drupal": "^1.3.3",
+    "phpstan/extension-installer": "^1.4",
+    "phpstan/phpstan": "^1.12.19",
+    "phpstan/phpstan-deprecation-rules": "^1.2.1"
   }
 }
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
new file mode 100644
index 0000000..e69de29
diff --git a/phpstan.neon b/phpstan.neon
new file mode 100644
index 0000000..0f3de97
--- /dev/null
+++ b/phpstan.neon
@@ -0,0 +1,23 @@
+includes:
+  - phpstan-baseline.neon
+  - phar://phpstan.phar/conf/bleedingEdge.neon
+
+parameters:
+  level: max
+  paths:
+    - web/modules/custom
+
+  ignoreErrors:
+    # Drupal codes have arrays all over the therefore it is more productive and
+    # sensible if we disable this check.
+    # See https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
+    # - identifier: missingType.iterableValue
+
+  drupal:
+    bleedingEdge:
+      checkCoreDeprecatedHooksInApiFiles: true
+      checkContribDeprecatedHooksInApiFiles: true
+    rules:
+      testClassSuffixNameRule: true
+      dependencySerializationTraitPropertyRule: true
+      accessResultConditionRule: true
-- 
GitLab