Skip to content

Commit 78e6e16

Browse files
authored
feat!: add typo3 13 and 14 compatibility (#22)
* refactor: add php-cs-fixer and apply rules * refactor: add rector and apply rules * ci: add phpstan and apply fixes * build: remove rector artifacts * build: bump version * refactor: rerun php-cs-fixer with typo3 config
1 parent 1a9de96 commit 78e6e16

9 files changed

Lines changed: 163 additions & 26 deletions

File tree

.editorconfig

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
indent_style = space
11+
indent_size = 4
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
# TS/JS-Files
16+
[*.{ts,js}]
17+
indent_size = 2
18+
19+
# JSON-Files
20+
[*.json]
21+
indent_style = tab
22+
23+
# ReST-Files
24+
[*.{rst,rst.txt}]
25+
indent_size = 4
26+
max_line_length = 80
27+
28+
# Markdown-Files
29+
[*.md]
30+
max_line_length = 80
31+
32+
# YAML-Files
33+
[*.{yaml,yml}]
34+
indent_size = 2
35+
36+
# NEON-Files
37+
[*.neon]
38+
indent_size = 2
39+
indent_style = tab
40+
41+
#.eslintrc.json
42+
[.eslintrc.json]
43+
indent_size = 2
44+
indent_style = space
45+
46+
# stylelint
47+
[.stylelintrc]
48+
indent_size = 2
49+
50+
# package.json
51+
[package.json]
52+
indent_size = 2
53+
54+
# TypoScript
55+
[*.{typoscript,tsconfig}]
56+
indent_size = 2
57+
58+
# XLF-Files
59+
[*.xlf]
60+
indent_style = tab
61+
62+
# SQL-Files
63+
[*.sql]
64+
indent_style = tab
65+
indent_size = 2
66+
67+
# .htaccess
68+
[{_.htaccess,.htaccess}]
69+
indent_style = tab

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
static-analysis:
9+
name: "PHPStan / PHP ${{ matrix.php }} / TYPO3 ${{ matrix.typo3 }}"
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
include:
15+
- php: "8.2"
16+
typo3: "^13.4"
17+
- php: "8.5"
18+
typo3: "^14.3"
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Set up PHP ${{ matrix.php }}
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ matrix.php }}
27+
tools: composer
28+
29+
- name: Require TYPO3 version
30+
run: composer require typo3/cms-core "${{ matrix.typo3 }}" --no-update
31+
32+
- name: Install dependencies
33+
run: composer install --prefer-dist --no-progress --no-plugins
34+
35+
- name: Validate composer.json
36+
run: composer validate --strict
37+
38+
- name: Run PHPStan
39+
run: vendor/bin/phpstan analyse --no-progress

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
vendor
3+
public
4+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$config = \TYPO3\CodingStandards\CsFixerConfig::create();
4+
$config->getFinder()
5+
->in(__DIR__)
6+
;
7+
8+
return $config;

Classes/Service/GeoService.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
* the terms of the GNU General Public License, either version 2
1010
* of the License, or any later version.
1111
*/
12-
1312
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
1413
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
14+
use TYPO3\CMS\Core\Database\Connection;
1515
use TYPO3\CMS\Core\Database\ConnectionPool;
1616
use TYPO3\CMS\Core\Database\Query\QueryHelper;
1717
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
@@ -33,7 +33,8 @@ class GeoService implements SingletonInterface
3333
public function __construct(
3434
protected readonly FrontendInterface $cache,
3535
protected readonly ExtensionConfiguration $extensionConfiguration,
36-
protected readonly RequestFactory $requestFactory
36+
protected readonly RequestFactory $requestFactory,
37+
private readonly ConnectionPool $connectionPool
3738
) {
3839
$geoCodingConfig = $extensionConfiguration->get('geocoding');
3940
// load from extension configuration
@@ -68,7 +69,7 @@ public function getCoordinatesForAddress(?string $street = null, ?string $zip =
6869
}
6970

7071
$address = ltrim(implode(',', $addressParts), ',');
71-
if (empty($address)) {
72+
if ($address === '' || $address === '0') {
7273
return [];
7374
}
7475

@@ -115,7 +116,7 @@ public function calculateCoordinatesForAllRecordsInTable(
115116
string $addWhereClause = ''
116117
): int {
117118
// Fetch all records without latitude/longitude
118-
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName);
119+
$connection = $this->connectionPool->getConnectionForTable($tableName);
119120
$queryBuilder = $connection->createQueryBuilder();
120121
$queryBuilder->getRestrictions()
121122
->removeAll()
@@ -124,18 +125,18 @@ public function calculateCoordinatesForAllRecordsInTable(
124125
->select('*')
125126
->from($tableName)
126127
->where(
127-
$queryBuilder->expr()->orX(
128+
$queryBuilder->expr()->or(
128129
$queryBuilder->expr()->isNull($latitudeField),
129-
$queryBuilder->expr()->eq($latitudeField, $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
130+
$queryBuilder->expr()->eq($latitudeField, $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
130131
$queryBuilder->expr()->eq($latitudeField, 0.00000000000),
131132
$queryBuilder->expr()->isNull($longitudeField),
132-
$queryBuilder->expr()->eq($longitudeField, $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
133+
$queryBuilder->expr()->eq($longitudeField, $queryBuilder->createNamedParameter(0, Connection::PARAM_INT)),
133134
$queryBuilder->expr()->eq($longitudeField, 0.00000000000)
134135
)
135136
)
136137
->setMaxResults(500);
137138

138-
if (!empty($addWhereClause)) {
139+
if ($addWhereClause !== '' && $addWhereClause !== '0') {
139140
$queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($addWhereClause));
140141
}
141142

@@ -147,18 +148,14 @@ public function calculateCoordinatesForAllRecordsInTable(
147148
if (($GLOBALS['TCA'][$tableName]['columns'][$countryField]['config']['type'] ?? '') === 'select') {
148149
foreach ($GLOBALS['TCA'][$tableName]['columns'][$countryField]['config']['items'] ?? [] as $itm) {
149150
if (($itm[1] ?? null) === $country) {
150-
if (is_object($GLOBALS['TSFE'])) {
151-
$country = $GLOBALS['TSFE']->sL($itm[0]);
152-
} else {
153-
$country = $GLOBALS['LANG']->sL($itm[0]);
154-
}
151+
$country = is_object($GLOBALS['TSFE']) ? $GLOBALS['TSFE']->sL($itm[0]) : $GLOBALS['LANG']->sL($itm[0]);
155152
}
156153
}
157154
}
158155
// do the geocoding
159156
if (!empty($record[$zipField]) || !empty($record[$cityField])) {
160157
$coords = $this->getCoordinatesForAddress($record[$streetField] ?? null, $record[$zipField] ?? null, $record[$cityField] ?? null, $country);
161-
if ($coords) {
158+
if ($coords !== []) {
162159
// Update the record to fill in the latitude and longitude values in the DB
163160
$connection->update(
164161
$tableName,

composer.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"license": "GPL-2.0-or-later",
77
"keywords": ["TYPO3 CMS", "TYPO3", "Google Geocoding"],
88
"require": {
9-
"php": "^8.1",
10-
"typo3/cms-core": "^11.5 || ^12.4"
9+
"php": "^8.2",
10+
"typo3/cms-core": "^13.4 || ^14.3"
1111
},
1212
"extra": {
1313
"typo3/cms": {
@@ -18,5 +18,15 @@
1818
"psr-4": {
1919
"B13\\Geocoding\\": "Classes/"
2020
}
21+
},
22+
"require-dev": {
23+
"typo3/coding-standards": "^0.8.0",
24+
"saschaegerer/phpstan-typo3": "^2.0 || ^3.0"
25+
},
26+
"config": {
27+
"allow-plugins": {
28+
"typo3/cms-composer-installers": true,
29+
"typo3/class-alias-loader": true
30+
}
2131
}
2232
}

ext_emconf.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
$EM_CONF[$_EXTKEY] = [
46
'title' => 'Service: Geocoding via Google Maps',
57
'description' => 'Provides services for google maps GeoCoding API and radius search on the database.',
68
'category' => 'sv',
79
'author' => 'Benjamin Mack',
810
'author_email' => 'benjamin.mack@b13.com',
911
'author_company' => 'b13 GmbH',
10-
'shy' => '',
1112
'state' => 'stable',
12-
'uploadfolder' => 0,
13-
'createDirs' => '',
14-
'clearCacheOnLoad' => 0,
15-
'lockType' => '',
16-
'version' => '5.0.0',
13+
'version' => '6.0.0',
1714
'constraints' => [
1815
'depends' => [
19-
'typo3' => '11.5.0-12.4.99',
16+
'typo3' => '13.4.0-14.3.99',
2017
],
2118
'conflicts' => [
2219
],

ext_localconf.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<?php
22

3-
defined('TYPO3') or die();
3+
declare(strict_types=1);
4+
5+
use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
6+
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
7+
8+
defined('TYPO3') || die();
49

510
// Define state cache, if not already defined
611
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['geocoding'] ?? false)) {
712
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['geocoding'] = [
8-
'frontend' => \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class,
9-
'backend' => \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class,
13+
'frontend' => VariableFrontend::class,
14+
'backend' => Typo3DatabaseBackend::class,
1015
];
1116
}

phpstan.neon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
includes:
2+
- vendor/saschaegerer/phpstan-typo3/extension.neon
3+
4+
parameters:
5+
level: 5
6+
paths:
7+
- Classes
8+
treatPhpDocTypesAsCertain: false

0 commit comments

Comments
 (0)