From c1e29f7e8462cc8988f0dca201f7f57dc2807add Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Wed, 4 Dec 2024 15:51:57 +0000
Subject: [PATCH] upgrade to phpstan 2, fixes #4958

Closes #4958

Merge request studip/studip!3722
---
 composer.json                   |  2 +-
 composer.lock                   | 19 ++++++++++---------
 lib/bootstrap.php               |  2 +-
 lib/models/Course.php           | 30 ++++++++++++++++--------------
 lib/phplib/Seminar_Auth.php     |  2 +-
 lib/seminar_open.php            |  2 +-
 phpstan.neon.dist               |  1 -
 tests/functional/_bootstrap.php |  2 +-
 tests/jsonapi/_bootstrap.php    |  4 ++--
 9 files changed, 33 insertions(+), 31 deletions(-)

diff --git a/composer.json b/composer.json
index 32617d6c8d7..20e1638924b 100644
--- a/composer.json
+++ b/composer.json
@@ -71,7 +71,7 @@
         "codeception/codeception": "5.1.2",
         "codeception/module-asserts": "3.0.0",
         "overtrue/phplint": "9.3.0",
-        "phpstan/phpstan": "1.11.0",
+        "phpstan/phpstan": "^2.0",
         "symfony/var-dumper": "6.4.7",
         "maximebf/debugbar": "1.22.3",
         "codeception/specify": "^2.0"
diff --git a/composer.lock b/composer.lock
index 7ebf09c08e4..7897e22c5d8 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "f64a6bfba9a1758196b21c6394535191",
+    "content-hash": "5bc2e4ef41517f46c14d02cfecdd95d9",
     "packages": [
         {
             "name": "algo26-matthias/idna-convert",
@@ -6516,20 +6516,20 @@
         },
         {
             "name": "phpstan/phpstan",
-            "version": "1.11.0",
+            "version": "2.0.2",
             "source": {
                 "type": "git",
                 "url": "https://github.com/phpstan/phpstan.git",
-                "reference": "666cb1703742cea9cc80fee631f0940e1592fa6e"
+                "reference": "6c98c7600fc717b2c78c11ef60040d5b1e359c82"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/phpstan/phpstan/zipball/666cb1703742cea9cc80fee631f0940e1592fa6e",
-                "reference": "666cb1703742cea9cc80fee631f0940e1592fa6e",
+                "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6c98c7600fc717b2c78c11ef60040d5b1e359c82",
+                "reference": "6c98c7600fc717b2c78c11ef60040d5b1e359c82",
                 "shasum": ""
             },
             "require": {
-                "php": "^7.2|^8.0"
+                "php": "^7.4|^8.0"
             },
             "conflict": {
                 "phpstan/phpstan-shim": "*"
@@ -6570,7 +6570,7 @@
                     "type": "github"
                 }
             ],
-            "time": "2024-05-13T06:02:22+00:00"
+            "time": "2024-11-17T14:17:00+00:00"
         },
         {
             "name": "phpunit/php-code-coverage",
@@ -8742,9 +8742,10 @@
         "ext-pcre": "*",
         "ext-pdo": "*",
         "ext-mbstring": "*",
-        "ext-dom": "*"
+        "ext-dom": "*",
+        "ext-iconv": "*"
     },
-    "platform-dev": [],
+    "platform-dev": {},
     "platform-overrides": {
         "php": "8.1"
     },
diff --git a/lib/bootstrap.php b/lib/bootstrap.php
index 2e762c5a142..2f8448ddf7a 100644
--- a/lib/bootstrap.php
+++ b/lib/bootstrap.php
@@ -112,7 +112,7 @@ if ($GLOBALS['ASSETS_URL'][0] === '/') {
     $GLOBALS['ASSETS_URL'] = $GLOBALS['ABSOLUTE_URI_STUDIP'] . $GLOBALS['ASSETS_URL'];
 }
 
-require 'config.inc.php';
+require $GLOBALS['STUDIP_BASE_PATH'] . '/config/config.inc.php';
 
 require 'lib/helpers.php';
 require 'lib/phplib/page_open.php';
diff --git a/lib/models/Course.php b/lib/models/Course.php
index 690fbc20d1c..bf5b7385ec2 100644
--- a/lib/models/Course.php
+++ b/lib/models/Course.php
@@ -1781,26 +1781,28 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
     public function getFullName($format = 'default')
     {
         $template = [
-            'name'                 => '%1$s',
-            'name-semester'        => '%1$s (%4$s)',
-            'number-name'          => '%3$s %1$s',
-            'number-name-semester' => '%3$s %1$s (%4$s)',
-            'number-type-name'     => '%3$s %2$s: %1$s',
-            'sem-duration-name'    => '%4$s',
-            'type'                 => '%2$s',
-            'type-name'            => '%2$s: %1$s',
-            'type-number-name'     => '%2$s: %3$s %1$s',
+            'name'                 => '%{name}',
+            'name-semester'        => '%{name} (%{semester})',
+            'number-name'          => '%{number} %{name}',
+            'number-name-semester' => '%{number} %{name} (%{semester})',
+            'number-type-name'     => '%{number} %{type}: %{name}',
+            'sem-duration-name'    => '%{semester}',
+            'type'                 => '%{type}',
+            'type-name'            => '%{type}: %{name}',
+            'type-number-name'     => '%{type}: %{number} %{name}',
         ];
 
         if ($format === 'default' || !isset($template[$format])) {
            $format = Config::get()->IMPORTANT_SEMNUMBER ? 'type-number-name' : 'type-name';
         }
         $sem_type = $this->getSemType();
-        $data[0] = $this->name;
-        $data[1] = $sem_type['name'];
-        $data[2] = $this->veranstaltungsnummer;
-        $data[3] = $this->getTextualSemester();
-        return trim(vsprintf($template[$format], array_map('trim', $data)));
+        $data = array_map('trim', [
+            'name'     => $this->name,
+            'type'     => $sem_type['name'],
+            'number'   => $this->veranstaltungsnummer,
+            'semester' => $this->getTextualSemester(),
+        ]);
+        return trim(studip_interpolate($template[$format], $data));
     }
 
     /**
diff --git a/lib/phplib/Seminar_Auth.php b/lib/phplib/Seminar_Auth.php
index 17d8b897a22..4ca21bf4dbd 100644
--- a/lib/phplib/Seminar_Auth.php
+++ b/lib/phplib/Seminar_Auth.php
@@ -442,7 +442,7 @@ class Seminar_Auth
 
         // init of output via I18N
         $_language_path = init_i18n($_SESSION['_language']);
-        include 'config.inc.php';
+        include $GLOBALS['STUDIP_BASE_PATH'] . '/config/config.inc.php';
 
         if (!empty($_SESSION['contrast'])) {
             PageLayout::addStylesheet('accessibility.css');
diff --git a/lib/seminar_open.php b/lib/seminar_open.php
index cfed84762a3..4fb856fc724 100644
--- a/lib/seminar_open.php
+++ b/lib/seminar_open.php
@@ -125,7 +125,7 @@ if (!empty($_SESSION['contrast']) || UserConfig::get($GLOBALS['user']->id)->USER
 // init of output via I18N
 $_language_path = init_i18n($_SESSION['_language']);
 //force reload of config to get translated data
-include 'config.inc.php';
+include $GLOBALS['STUDIP_BASE_PATH'] . '/config/config.inc.php';
 
 // Try to select the course or institute given by the parameter 'cid'
 // in the current request.
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
index 2d66785205c..4576401f332 100644
--- a/phpstan.neon.dist
+++ b/phpstan.neon.dist
@@ -13,7 +13,6 @@ parameters:
         - lib
         - vendor
     excludePaths:
-        - lib/classes/ZipArchiveLegacyTrait.php
         - lib/ilias_interface/studip_referrer_7x.php
         - lib/ilias_interface/studip_referrer_8x.php
     tmpDir: .caches
diff --git a/tests/functional/_bootstrap.php b/tests/functional/_bootstrap.php
index cdc9db19668..1897878bb10 100644
--- a/tests/functional/_bootstrap.php
+++ b/tests/functional/_bootstrap.php
@@ -37,7 +37,7 @@ StudipFileloader::load(
 foreach($added_configs as $key => $value) {
     $GLOBALS[$key] = $value;
 }
-require 'config/config.inc.php';
+require $GLOBALS['STUDIP_BASE_PATH'] . '/config/config.inc.php';;
 require_once __DIR__ . '/../../lib/bootstrap-autoload.php';
 
 // Do not send mails of any kind during tests
diff --git a/tests/jsonapi/_bootstrap.php b/tests/jsonapi/_bootstrap.php
index 2b30aa91ce6..1fc5ba7ba0d 100644
--- a/tests/jsonapi/_bootstrap.php
+++ b/tests/jsonapi/_bootstrap.php
@@ -27,8 +27,8 @@ $CACHING_ENABLE = false;
 
 date_default_timezone_set('Europe/Berlin');
 
-require 'config.inc.php';
-require 'mvv_config.php';
+require $GLOBALS['STUDIP_BASE_PATH'] . '/config/config.inc.php';;
+require $GLOBALS['STUDIP_BASE_PATH'] . '/config/mvv_config.php';
 require_once __DIR__ . '/../../lib/bootstrap-autoload.php';
 
 
-- 
GitLab