Skip to content

Commit

Permalink
Update the CI chain (#78)
Browse files Browse the repository at this point in the history
* Updated CI and fixed CS

* Update the GitHub CI
  • Loading branch information
Toflar authored Nov 16, 2023
1 parent 2dec6d0 commit 6a724f9
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 2,284 deletions.
24 changes: 4 additions & 20 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,31 @@ name: CI

on:
pull_request: ~
push:
branches:
- '*'
tags:
- '*'
schedule:
- cron: 0 13 * * MON

jobs:
cs:
name: Coding Style
runs-on: ubuntu-latest
if: github.event_name != 'push'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2

- name: Checkout
uses: actions/checkout@v2

- name: Install ecs
run: cd tools/ecs && composer install --no-interaction --no-suggest
- name: Install the dependencies
run: composer install --no-interaction --no-suggest

- name: Run the CS fixer
run: composer cs-fixer

tests:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
if: github.event_name != 'push'
strategy:
fail-fast: false
matrix:
php: [8.1, 8.2]
php: [8.1, 8.2, 8.3]
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -45,9 +36,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Install phpunit
run: cd tools/phpunit && composer install --no-interaction --no-suggest

- name: Install the dependencies
run: composer install --no-interaction --no-suggest

Expand All @@ -57,11 +45,10 @@ jobs:
prefer-lowest-tests:
name: PHP ${{ matrix.php }} --prefer-lowest
runs-on: ubuntu-latest
if: github.event_name != 'push'
strategy:
fail-fast: false
matrix:
php: [8.1, 8.2]
php: [8.1, 8.2, 8.3]
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -71,9 +58,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Install phpunit
run: cd tools/phpunit && composer install --no-interaction --no-suggest

- name: Install the dependencies
run: composer update --prefer-lowest --prefer-stable --no-interaction --no-suggest

Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/vendor/
/tools/*/vendor
/composer.lock
/.php-cs-fixer.cache
/tools/phpunit/.phpunit.result.cache
/.phpunit.result.cache
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,20 @@
"contao-manager-plugin": "Terminal42\\MultipageFormsBundle\\ContaoManager\\Plugin"
},
"scripts": {
"cs-fixer": "@php tools/ecs/vendor/bin/ecs check config/ contao/ src/ tests/ --config tools/ecs/config.php --fix --ansi",
"unit-tests": "@php tools/phpunit/vendor/bin/phpunit -c tools/phpunit/phpunit.xml.dist"
"unit-tests": "@php vendor/bin/phpunit"
},
"config": {
"allow-plugins": {
"contao-components/installer": false,
"contao/manager-plugin": false
"contao/manager-plugin": false,
"php-http/discovery": true,
"terminal42/contao-build-tools": true
}
},
"require-dev": {
"contao/manager-plugin": "^2.12"
"contao/manager-plugin": "^2.12",
"terminal42/contao-build-tools": "@dev",
"phpunit/phpunit": "^9.6",
"contao/test-case": "^5.0"
}
}
4 changes: 2 additions & 2 deletions tools/phpunit/phpunit.xml.dist → phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
bootstrap="../../vendor/autoload.php"
bootstrap="vendor/autoload.php"
colors="true"
>
<php>
Expand All @@ -12,7 +12,7 @@

<testsuites>
<testsuite name="MultipageForms Test Suite">
<directory>../../tests</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
6 changes: 4 additions & 2 deletions src/Controller/FrontendModule/StepsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
#[AsFrontendModule('mp_form_steps', template: 'mod_mp_form_steps')]
class StepsController extends AbstractFrontendModuleController
{
public function __construct(private ContaoFramework $contaoFramework, private FormManagerFactoryInterface $formManagerFactory)
{
public function __construct(
private readonly ContaoFramework $contaoFramework,
private readonly FormManagerFactoryInterface $formManagerFactory,
) {
}

protected function getResponse(Template $template, ModuleModel $model, Request $request): Response
Expand Down
6 changes: 4 additions & 2 deletions src/EventListener/CompileFormFieldsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#[AsHook('compileFormFields')]
class CompileFormFieldsListener
{
public function __construct(private FormManagerFactoryInterface $formManagerFactory, private RequestStack $requestStack)
{
public function __construct(
private readonly FormManagerFactoryInterface $formManagerFactory,
private readonly RequestStack $requestStack,
) {
}

/**
Expand Down
15 changes: 6 additions & 9 deletions src/EventListener/InsertTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#[AsHook('replaceInsertTags')]
class InsertTagsListener
{
public function __construct(private FormManagerFactoryInterface $formManagerFactory)
public function __construct(private readonly FormManagerFactoryInterface $formManagerFactory)
{
}

Expand All @@ -28,14 +28,11 @@ public function __invoke(string $tag)

$manager = $this->formManagerFactory->forFormId((int) $formId);

switch ($type) {
case 'step':
return $this->getStepValue($manager, $value);
case 'field_value':
return $manager->getDataOfAllSteps()->getAllSubmitted()[$value] ?? '';
}

return '';
return match ($type) {
'step' => $this->getStepValue($manager, $value),
'field_value' => $manager->getDataOfAllSteps()->getAllSubmitted()[$value] ?? '',
default => '',
};
}

private function getStepValue(FormManager $manager, string $value): string
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/LoadFormFieldListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[AsHook('loadFormField')]
class LoadFormFieldListener
{
public function __construct(private FormManagerFactoryInterface $formManagerFactory)
public function __construct(private readonly FormManagerFactoryInterface $formManagerFactory)
{
}

Expand All @@ -38,7 +38,7 @@ public function __invoke(Widget $widget, string $formId, array $formData, Form $
// 3. The widget default value itself
if (!$postData->has($widget->name)) {
$widget->value = $stepData->getSubmitted()->get(
$widget->name, $stepData->getOriginalPostData()->get($widget->name, $widget->value)
$widget->name, $stepData->getOriginalPostData()->get($widget->name, $widget->value),
);
}

Expand Down
8 changes: 5 additions & 3 deletions src/EventListener/PrepareFomDataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#[AsHook('prepareFormData')]
class PrepareFomDataListener
{
public function __construct(private FormManagerFactoryInterface $formManagerFactory, private RequestStack $reqestStack)
{
public function __construct(
private readonly FormManagerFactoryInterface $formManagerFactory,
private readonly RequestStack $reqestStack,
) {
}

/**
Expand Down Expand Up @@ -77,7 +79,7 @@ public function __invoke(array &$submitted, array &$labels, array $fields, Form
private function getUploadedFiles($hook = []): FileParameterBag
{
// Contao 5
if (0 !== \count($hook)) {
if (0 !== (is_countable($hook) ? \count($hook) : 0)) {
return new FileParameterBag($hook);
}

Expand Down
23 changes: 13 additions & 10 deletions src/FormManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
class FormManager
{
private FormModel $formModel;

private string $sessionRef;

private string $storageIdentifier;

private bool $prepared = false;

private bool $preparing = false;

/**
Expand All @@ -40,13 +43,13 @@ class FormManager
private bool $isValidFormFieldCombination = true;

public function __construct(
private int $formId,
private Request $request,
private ContaoFramework $contaoFramework,
private StorageInterface $storage,
private StorageIdentifierGeneratorInterface $storageIdentifierGenerator,
private SessionReferenceGeneratorInterface $sessionReferenceGenerator,
private UrlParser $urlParser,
private readonly int $formId,
private readonly Request $request,
private readonly ContaoFramework $contaoFramework,
private readonly StorageInterface $storage,
private readonly StorageIdentifierGeneratorInterface $storageIdentifierGenerator,
private readonly SessionReferenceGeneratorInterface $sessionReferenceGenerator,
private readonly UrlParser $urlParser,
) {
}

Expand Down Expand Up @@ -230,7 +233,7 @@ public function getGetParamForSessionReference()
/**
* @throws RedirectResponseException
*/
public function redirectToStep(int $step): void
public function redirectToStep(int $step): never
{
$this->prepare();
$this->validateStep($step);
Expand Down Expand Up @@ -354,7 +357,7 @@ private function loadFormFieldModels(): void
// Ignore the name of form fields which do not use a name (see contao/core-bundle #1268)
if (
$formFieldModel->name && isset($GLOBALS['TL_DCA']['tl_form_field']['palettes'][$formFieldModel->type])
&& preg_match('/[,;]name[,;]/', $GLOBALS['TL_DCA']['tl_form_field']['palettes'][$formFieldModel->type])
&& preg_match('/[,;]name[,;]/', (string) $GLOBALS['TL_DCA']['tl_form_field']['palettes'][$formFieldModel->type])
) {
$formFieldModels[$formFieldModel->name] = $formFieldModel;
} else {
Expand Down Expand Up @@ -467,7 +470,7 @@ private function initSessionReference(bool $forceNew = false): void

$this->sessionRef = $this->request->query->get(
$this->getGetParamForSessionReference(),
$this->sessionReferenceGenerator->generate($this)
$this->sessionReferenceGenerator->generate($this),
);
}
}
10 changes: 6 additions & 4 deletions src/FormManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
class FormManagerFactory implements FormManagerFactoryInterface
{
private StorageInterface|null $storage = null;

private StorageIdentifierGeneratorInterface|null $storageIdentifierGenerator = null;

private SessionReferenceGeneratorInterface|null $sessionReferenceGenerator = null;

/**
Expand All @@ -28,9 +30,9 @@ class FormManagerFactory implements FormManagerFactoryInterface
private array $managers = [];

public function __construct(
private ContaoFramework $contaoFramework,
private RequestStack $requestStack,
private UrlParser $urlParser,
private readonly ContaoFramework $contaoFramework,
private readonly RequestStack $requestStack,
private readonly UrlParser $urlParser,
) {
}

Expand Down Expand Up @@ -78,7 +80,7 @@ public function forFormId(int $id): FormManager
$storage,
$storageIdentifierGenerator,
$sessionReferenceGenerator,
$this->urlParser
$this->urlParser,
);

if ($storage instanceof FormManagerAwareInterface) {
Expand Down
7 changes: 4 additions & 3 deletions src/Step/FileParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class FileParameterBag extends ParameterBag
*/
public function set(string $name, mixed $value): self
{
if (\is_array($value) &&
\array_key_exists('tmp_name', $value) &&
\is_string($value['tmp_name'])
if (
\is_array($value)
&& \array_key_exists('tmp_name', $value)
&& \is_string($value['tmp_name'])
&& is_uploaded_file($value['tmp_name'])
) {
$target = (new Filesystem())->tempnam(sys_get_temp_dir(), 'nc');
Expand Down
9 changes: 7 additions & 2 deletions src/Step/StepData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

class StepData
{
private function __construct(private int $step, private ParameterBag $submitted, private ParameterBag $labels, private ParameterBag $files, private ParameterBag $originalPostData)
{
private function __construct(
private readonly int $step,
private ParameterBag $submitted,
private ParameterBag $labels,
private ParameterBag $files,
private ParameterBag $originalPostData,
) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class FixedSessionReferenceGenerator implements SessionReferenceGeneratorInterface
{
public function __construct(private string $identifier)
public function __construct(private readonly string $identifier)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Storage/SessionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

class SessionStorage implements StorageInterface
{
public const SESSION_KEY = 'contao.mp_forms';
final public const SESSION_KEY = 'contao.mp_forms';

public function __construct(private Request $request)
public function __construct(private readonly Request $request)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class FixedStorageIdentifierGenerator implements StorageIdentifierGeneratorInterface
{
public function __construct(private string $identifier)
public function __construct(private readonly string $identifier)
{
}

Expand Down
Loading

0 comments on commit 6a724f9

Please # to comment.