Skip to content

Commit

Permalink
TYPO3 v12 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-s-codappix authored Sep 17, 2024
1 parent b087098 commit 891871a
Show file tree
Hide file tree
Showing 30 changed files with 452 additions and 452 deletions.
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Tests export-ignore
.github export-ignore

.gitattributes export-ignore
.gitignore export-ignore

.php-cs-fixer.dist.php export-ignore
phpstan.neon export-ignore
phpunit.xml.dist export-ignore

shell.nix export-ignore
51 changes: 37 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ jobs:
strategy:
matrix:
php-version:
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -78,13 +76,42 @@ jobs:
with:
coverage: none
tools: composer:v2
php-version: "8.2"
php-version: "8.3"

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Coding Guideline
run: ./vendor/bin/ecs
run: ./vendor/bin/php-cs-fixer fix --dry-run

phpstan:
runs-on: ubuntu-latest
needs:
- xml-linting
strategy:
matrix:
include:
- php-version: '8.1'
typo3-version: '^12.4'
- php-version: '8.2'
typo3-version: '^12.4'
- php-version: '8.3'
typo3-version: '^12.4'
steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
tools: composer:v2
php-version: "${{ matrix.php-version }}"

- name: Install dependencies
run: composer req "typo3/cms-core:${{ matrix.typo3-version }}" --prefer-dist --no-progress --no-interaction

- name: PHPStan
run: ./vendor/bin/phpstan

tests:
runs-on: ubuntu-latest
Expand All @@ -93,16 +120,12 @@ jobs:
strategy:
matrix:
include:
- php-version: '7.3'
typo3-version: '^10.4'
- php-version: '7.4'
typo3-version: '^10.4'
- php-version: '7.4'
typo3-version: '^11.5'
- php-version: '8.1'
typo3-version: '^11.5'
typo3-version: '^12.4'
- php-version: '8.2'
typo3-version: '^11.5'
typo3-version: '^12.4'
- php-version: '8.3'
typo3-version: '^12.4'
steps:
- uses: actions/checkout@v3

Expand All @@ -114,7 +137,7 @@ jobs:
php-version: "${{ matrix.php-version }}"

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
run: composer req "typo3/cms-core:${{ matrix.typo3-version }}" --prefer-dist --no-progress --no-interaction

- name: PHPUnit Tests
run: ./vendor/bin/phpunit --testdox
63 changes: 63 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

$finder = (new PhpCsFixer\Finder())
->ignoreVCSIgnored(true)
->in(realpath(__DIR__));

return (new \PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'braces' => ['allow_single_line_closure' => true],
'cast_spaces' => ['space' => 'none'],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'dir_constant' => true,
'function_to_constant' => ['functions' => ['get_called_class', 'get_class', 'get_class_this', 'php_sapi_name', 'phpversion', 'pi']],
'function_typehint_space' => true,
'lowercase_cast' => true,
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'modernize_strpos' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'new_with_braces' => true,
'no_alias_functions' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'php_unit_construct' => ['assertions' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']],
'php_unit_mock_short_will_return' => true,
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'single_quote' => true,
'single_line_comment_style' => ['comment_types' => ['hash']],
'single_trait_insert_per_statement' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'whitespace_after_comma_in_array' => true,
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
])
->setFinder($finder);
56 changes: 39 additions & 17 deletions Classes/Controller/Frontend/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
* 02110-1301, USA.
*/

use Psr\Http\Message\ResponseInterface;
use RuntimeException;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use WerkraumMedia\Calendar\Domain\Model\Context;
use WerkraumMedia\Calendar\Domain\Model\ContextSpecificFactory;
use WerkraumMedia\Calendar\Domain\Model\Day;
Expand All @@ -35,7 +38,7 @@
use WerkraumMedia\Calendar\Domain\Model\Year;
use WerkraumMedia\Calendar\Events\AssignTemplateVariables;

class CalendarController extends ActionController
final class CalendarController extends ActionController
{
/**
* @var ForeignDataFactory
Expand All @@ -55,19 +58,19 @@ public function __construct(
$this->typoScriptService = $typoScriptService;
}

public function initializeAction()
public function initializeAction(): void
{
if ($this->foreignDataFactory instanceof ContextSpecificFactory) {
$this->foreignDataFactory->setContext(
Context::createFromContentObjectRenderer($this->configurationManager->getContentObject())
Context::createFromContentObjectRenderer($this->getContentObjectRenderer())
);
}
}

public function initializeYearAction()
public function initializeYearAction(): void
{
if ($this->request->hasArgument('year') === false) {
$this->request->setArguments([
$this->request = $this->request->withArguments([
'year' => [
'year' => $this->getDefaultArgumentValue('year'),
],
Expand All @@ -82,17 +85,19 @@ public function initializeYearAction()
/**
* @Extbase\IgnoreValidation("year")
*/
public function yearAction(Year $year)
public function yearAction(Year $year): ResponseInterface
{
$this->assignVariables([
'year' => $year,
]);

return $this->htmlResponse();
}

public function initializeMonthAction()
public function initializeMonthAction(): void
{
if ($this->request->hasArgument('month') === false) {
$this->request->setArguments([
$this->request = $this->request->withArguments([
'month' => [
'month' => $this->getDefaultArgumentValue('month'),
'year' => $this->getDefaultArgumentValue('year'),
Expand All @@ -108,17 +113,19 @@ public function initializeMonthAction()
/**
* @Extbase\IgnoreValidation("month")
*/
public function monthAction(Month $month)
public function monthAction(Month $month): ResponseInterface
{
$this->assignVariables([
'month' => $month,
]);

return $this->htmlResponse();
}

public function initializeWeekAction()
public function initializeWeekAction(): void
{
if ($this->request->hasArgument('week') === false) {
$this->request->setArguments([
$this->request = $this->request->withArguments([
'week' => [
'week' => $this->getDefaultArgumentValue('week'),
'year' => $this->getDefaultArgumentValue('year'),
Expand All @@ -134,17 +141,19 @@ public function initializeWeekAction()
/**
* @Extbase\IgnoreValidation("week")
*/
public function weekAction(Week $week)
public function weekAction(Week $week): ResponseInterface
{
$this->assignVariables([
'week' => $week,
]);

return $this->htmlResponse();
}

public function initializeDayAction()
public function initializeDayAction(): void
{
if ($this->request->hasArgument('day') === false) {
$this->request->setArguments([
$this->request = $this->request->withArguments([
'day' => [
'day' => $this->getDefaultArgumentValue('day'),
],
Expand All @@ -167,11 +176,13 @@ public function initializeDayAction()
/**
* @Extbase\IgnoreValidation("day")
*/
public function dayAction(Day $day)
public function dayAction(Day $day): ResponseInterface
{
$this->assignVariables([
'day' => $day,
]);

return $this->htmlResponse();
}

private function assignVariables(array $variables): void
Expand Down Expand Up @@ -202,12 +213,23 @@ private function getDefaultArgumentValue(string $argumentName): string
'day' => date('Y-m-d'),
];

$value = $this->configurationManager->getContentObject()->stdWrapValue(
$value = $this->getContentObjectRenderer()->stdWrapValue(
$argumentName,
$arguments,
$fallbackValues[$argumentName]
);

return $value;
return (string)$value;
}

private function getContentObjectRenderer(): ContentObjectRenderer
{
$contentObjectRenderer = $this->request->getAttribute('currentContentObject');

if (! $contentObjectRenderer instanceof ContentObjectRenderer) {
throw new RuntimeException('Could not fetch currentContentObject from request.', 1726490796);
}

return $contentObjectRenderer;
}
}
4 changes: 1 addition & 3 deletions Classes/Domain/Model/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

class Day
{
Expand All @@ -44,7 +43,6 @@ class Day
public function __construct(
\DateTime $day
) {
$this->periods = new ObjectStorage();
$this->day = \DateTimeImmutable::createFromMutable($day)->modify('midnight');
}

Expand All @@ -58,7 +56,7 @@ public function isActive(): bool
return false;
}

public function getForeignData()
public function getForeignData(): mixed
{
$this->initializeForeignData();

Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/ForeignDataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ interface ForeignDataFactory
* Receives a specific day and may return arbirtrary data.
* This data is attached to the day and available through getter.
*/
public function getData(Day $day);
public function getData(Day $day): mixed;
}
7 changes: 2 additions & 5 deletions Classes/Domain/Model/Month.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
* 02110-1301, USA.
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

class Month
{
/**
Expand Down Expand Up @@ -77,8 +74,8 @@ public function getWeeks(): array

while ($currentDay <= $lastDay) {
$this->weeks[] = new Week(
(int) $currentDay->format('W'),
(int) $currentDay->format('o')
(int)$currentDay->format('W'),
(int)$currentDay->format('o')
);

$currentDay = $currentDay->modify('+7 days');
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/NullDataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class NullDataFactory implements ForeignDataFactory
{
public function getData(Day $day)
public function getData(Day $day): mixed
{
return null;
}
Expand Down
Loading

0 comments on commit 891871a

Please sign in to comment.