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
20 changes: 4 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
strategy:
matrix:
php-version:
- 8.1
- 8.2
- 8.3
- 8.4
Expand Down Expand Up @@ -54,7 +53,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
php-version: "8.2"
tools: composer:v2

- name: Install dependencies
Expand All @@ -70,14 +69,12 @@ jobs:
strategy:
matrix:
include:
- php-version: '8.1'
typo3-version: '^12.4'
- php-version: '8.2'
typo3-version: '^12.4'
typo3-version: '^13.4'
- php-version: '8.3'
typo3-version: '^12.4'
typo3-version: '^13.4'
- php-version: '8.4'
typo3-version: '^12.4'
typo3-version: '^13.4'
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -112,9 +109,6 @@ jobs:
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= fossar.cachix.org-1:Zv6FuqIboeHPWQS7ysLCJ7UT7xExb4OE8c4LyGb5AsE=
substituters = https://cache.nixos.org/ https://fossar.cachix.org

- name: Run Unit Tests PHP8.1
run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-unit

- name: Run Unit Tests PHP8.2
run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-unit

Expand All @@ -124,9 +118,6 @@ jobs:
- name: Run Unit Tests PHP8.4
run: nix-shell --arg phpVersion \"php84\" --pure --run project-test-unit

- name: Run Functional Tests PHP8.1
run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-functional

- name: Run Functional Tests PHP8.2
run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-functional

Expand All @@ -150,9 +141,6 @@ jobs:
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= fossar.cachix.org-1:Zv6FuqIboeHPWQS7ysLCJ7UT7xExb4OE8c4LyGb5AsE=
substituters = https://cache.nixos.org/ https://fossar.cachix.org

- name: Run Acceptance Tests PHP8.1
run: nix-shell --arg phpVersion \"php81\" --pure --run project-test-acceptance

- name: Run Acceptance Tests PHP8.2
run: nix-shell --arg phpVersion \"php82\" --pure --run project-test-acceptance

Expand Down
25 changes: 4 additions & 21 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cache:
- .php_cs.cache

variables:
TYPO3_VERSION: ^12.4
TYPO3_VERSION: ^13.4

before_script:
- apk add git --update
Expand Down Expand Up @@ -39,11 +39,6 @@ lint:yaml:
script:
- find *.php Classes Configuration Tests -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l

lint:php81:
<<: *lint_php
variables:
CONTAINER_IMAGE: php:8.1-alpine

lint:php82:
<<: *lint_php
variables:
Expand All @@ -60,11 +55,11 @@ lint:php84:
CONTAINER_IMAGE: php:8.4-alpine

phpstan:analyse:
image: $CI_REGISTRY/containers/phpunit-with-php-8.1:main
image: $CI_REGISTRY/containers/phpunit-with-php-8.2:main
stage: lint
before_script:
- sed -i -e "s#ssh://git@code.extco.de:22722#https://gitlab-ci-token:$CI_JOB_TOKEN@code.extco.de#g" composer.json
- composer config platform.php 8.1
- composer config platform.php 8.2
- composer install --no-progress --no-ansi --no-interaction
script:
- vendor/bin/codecept build
Expand All @@ -83,12 +78,7 @@ phpstan:analyse:
- composer require typo3/cms-core="${TYPO3_VERSION}"
script:
- vendor/bin/phpunit -c Build/UnitTests.xml
- typo3DatabaseDriver=pdo_sqlite vendor/bin/phpunit -c Build/FunctionalTests.xml

test:php81:
<<: *test_php
variables:
CONTAINER_IMAGE: $CI_REGISTRY/containers/phpunit-with-php-8.1:main
- typo3DatabaseDriver=pdo_sqlite vendor/bin/phpunit -d memory_limit=256M -c Build/FunctionalTests.xml

test:php82:
<<: *test_php
Expand Down Expand Up @@ -129,15 +119,8 @@ test:php84:
expire_in: 1 day
when: always

codeception:php81:
<<: *test_codeception
variables:
CONTAINER_IMAGE: $CI_REGISTRY/containers/codeception-with-php-8.1:main

codeception:php82:
<<: *test_codeception
needs:
- codeception:php81
variables:
CONTAINER_IMAGE: $CI_REGISTRY/containers/codeception-with-php-8.2:main

Expand Down
19 changes: 19 additions & 0 deletions Build/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
ignoreErrors:
-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Extcode\\\\CartEvents\\\\Domain\\\\Model\\\\AbstractEventDate'' and Extcode\\CartEvents\\Domain\\Model\\CalendarEntry will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: ../Tests/Unit/Domain/Model/CalenderEntryTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''TYPO3\\\\CMS\\\\Extbase\\\\Domain\\\\Model\\\\Category'' and Extcode\\CartEvents\\Domain\\Model\\Category will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: ../Tests/Unit/Domain/Model/CategoryTest.php

-
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertInstanceOf\(\) with ''Extcode\\\\CartEvents\\\\Domain\\\\Model\\\\AbstractEventDate'' and Extcode\\CartEvents\\Domain\\Model\\EventDate will always evaluate to true\.$#'
identifier: staticMethod.alreadyNarrowedType
count: 1
path: ../Tests/Unit/Domain/Model/EventDateTest.php
32 changes: 31 additions & 1 deletion Build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
includes:
- 'phpstan-baseline.neon'

parameters:
level: 0
level: 5

paths:
- ../Classes
- ../Configuration
- ../Tests
- ../ext_emconf.php
- ../ext_localconf.php
excludePaths:
- '../Tests/Acceptance/Support/_generated/TesterActions.php'

disallowedFunctionCalls:
-
function:
- 'var_dump()'
- 'xdebug_break()'
message: 'Do not add debugging'
-
function: 'header()'
message: 'Use API instead'

disallowedStaticCalls:
-
method: 'TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump()'
message: 'Do not add debugging'

disallowedSuperglobals:
-
superglobal:
- '$_GET'
- '$_POST'
- '$_FILES'
- '$_SERVER'
message: 'Use API instead'
77 changes: 34 additions & 43 deletions Classes/Controller/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
* LICENSE file that was distributed with this source code.
*/

use Exception;
use Extcode\Cart\Domain\Model\Cart\Cart;
use Extcode\Cart\Service\SessionHandler;
use Extcode\Cart\Utility\CartUtility;
use Extcode\CartEvents\Domain\Model\Category;
use Extcode\CartEvents\Domain\Model\Dto\EventDemand;
use Extcode\CartEvents\Domain\Model\Event;
use Extcode\CartEvents\Domain\Model\EventDate;
Expand All @@ -28,9 +30,8 @@
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Http\ForwardResponse;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface;

class EventController extends ActionController
final class EventController extends ActionController
{
private Cart $cart;

Expand All @@ -40,6 +41,7 @@ public function __construct(
private readonly SessionHandler $sessionHandler,
private readonly CartUtility $cartUtility,
private readonly EventRepository $eventRepository,
private readonly EventDateRepository $eventDateRepository,
private readonly CategoryRepository $categoryRepository,
) {}

Expand Down Expand Up @@ -118,6 +120,10 @@ public function showAction(?Event $event = null): ResponseInterface
#[IgnoreValidation(['value' => 'priceCategory'])]
public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCategory = null): ResponseInterface
{
if (class_exists(\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface::class) === false) {
throw new \BadFunctionCallException('This action requires the installation of typo3/cms-form.');
}

if (!$eventDate) {
$arguments = $this->request->getArguments();
foreach ($arguments as $argumentKey => $argumentValue) {
Expand All @@ -126,14 +132,17 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
$priceCategoryId = (int)$argumentValue['priceCategoryId'];

if ($eventDateId) {
$eventDateRepository = GeneralUtility::makeInstance(
EventDateRepository::class
);
$eventDate = $eventDateRepository->findByUid($eventDateId);

$formDefinition = $eventDate->getEvent()->getFormDefinition();
$eventDate = $this->eventDateRepository->findByUid($eventDateId);
if (($eventDate instanceof EventDate) === false) {
throw new Exception('Can not find EventDate with uid ' . $eventDateId . '.', 1769617660);
}
$event = $eventDate->getEvent();
if (($event instanceof Event) === false) {
throw new Exception('EventDate with uid ' . $eventDateId . ' has no event!', 1769617873);
}
$formDefinition = $event->getFormDefinition();
$formPersistenceManager = GeneralUtility::makeInstance(
FormPersistenceManagerInterface::class
\TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface::class
);
$form = $formPersistenceManager->load($formDefinition);

Expand All @@ -146,14 +155,17 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
PriceCategoryRepository::class
);
$priceCategory = $priceCategoryRepository->findByUid($priceCategoryId);
if (($priceCategory instanceof PriceCategory) === false) {
throw new Exception('Can not find PriceCategory with uid ' . $priceCategoryId . '.', 1769642011);
}
}
}
}
}
}

if (!$eventDate) {
throw new \InvalidArgumentException();
if (($eventDate instanceof EventDate) === false) {
throw new Exception('Can not find EventDate.', 1769641914);
}

$this->view->assign('eventDate', $eventDate);
Expand All @@ -169,19 +181,19 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
'type' => 'Hidden',
'identifier' => 'productType',
'label' => 'productType',
'defaultValue' => ($eventDate ? 'CartEvents' : ''),
'defaultValue' => 'CartEvents',
],
9998 => [
'type' => 'Hidden',
'identifier' => 'eventDateId',
'label' => 'eventDateId',
'defaultValue' => ($eventDate ? $eventDate->getUid() : ''),
'defaultValue' => $eventDate->getUid(),
],
9999 => [
'type' => 'Hidden',
'identifier' => 'priceCategoryId',
'label' => 'priceCategoryId',
'defaultValue' => ($priceCategory ? $priceCategory->getUid() : ''),
'defaultValue' => (($priceCategory instanceof PriceCategory) ? $priceCategory->getUid() : ''),
],
],
],
Expand All @@ -195,28 +207,7 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
return $this->htmlResponse();
}

protected function getEvent(): ?Event
{
$eventUid = 0;

if ((int)$GLOBALS['TSFE']->page['doktype'] == 186) {
$eventUid = (int)$GLOBALS['TSFE']->page['cart_events_event'];
}

if ($eventUid > 0) {
$event = $this->eventRepository->findByUid($eventUid);
if ($event && $event instanceof Event) {
return $event;
}
}

return null;
}

/**
* Create the demand object which define which records will get shown
*/
protected function createDemandObjectFromSettings(string $type, array $settings): EventDemand
private function createDemandObjectFromSettings(string $type, array $settings): EventDemand
{
/** @var EventDemand $demand */
$demand = GeneralUtility::makeInstance(
Expand Down Expand Up @@ -254,7 +245,7 @@ protected function createDemandObjectFromSettings(string $type, array $settings)
return $demand;
}

protected function addCategoriesToDemandObjectFromSettings(EventDemand &$demand): void
private function addCategoriesToDemandObjectFromSettings(EventDemand &$demand): void
{
if ($this->settings['categoriesList']) {
$selectedCategories = GeneralUtility::intExplode(
Expand All @@ -268,6 +259,9 @@ protected function addCategoriesToDemandObjectFromSettings(EventDemand &$demand)
if ($this->settings['listSubcategories']) {
foreach ($selectedCategories as $selectedCategory) {
$category = $this->categoryRepository->findByUid($selectedCategory);
if (($category instanceof Category) === false) {
continue;
}
$categories = array_merge(
$categories,
$this->categoryRepository->findSubcategoriesRecursiveAsArray($category)
Expand All @@ -281,10 +275,7 @@ protected function addCategoriesToDemandObjectFromSettings(EventDemand &$demand)
}
}

/**
* assigns currency translation array to view
*/
protected function assignCurrencyTranslationData(): void
private function assignCurrencyTranslationData(): void
{
$this->restoreSession();

Expand All @@ -297,7 +288,7 @@ protected function assignCurrencyTranslationData(): void
$this->view->assign('currencyTranslationData', $currencyTranslationData);
}

protected function addCacheTags(iterable $events): void
private function addCacheTags(iterable $events): void
{
$cacheTags = [];

Expand Down Expand Up @@ -333,7 +324,7 @@ private function forwardToShowActionWhenRequested(): ?ForwardResponse
return $forwardResponse->withArguments(['event' => $this->request->getArgument('event')]);
}

protected function restoreSession(): void
private function restoreSession(): void
{
$cart = $this->sessionHandler->restoreCart($this->cartConfiguration['settings']['cart']['pid']);

Expand Down
Loading