Commit ed1fd3a8 authored by crell's avatar crell Committed by Andreas Fernandez
Browse files

[!!!][TASK] Add modern typing to ClassNamingUtility

Simple type additions. Nothing exciting.

Resolves: #97205
Related: #97210
Releases: main
Change-Id: Ic38274300b22f3ce9168e98c13239934c624069a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73987


Tested-by: Simon Schaufelberger's avatarSimon Schaufelberger <simonschaufi+typo3@gmail.com>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Simon Schaufelberger's avatarSimon Schaufelberger <simonschaufi+typo3@gmail.com>
Reviewed-by: Oliver Klee's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Simon Gilli's avatarSimon Gilli <typo3@gilbertsoft.org>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 224befe3
......@@ -26,11 +26,8 @@ class ClassNamingUtility
* Translates a model name to an appropriate repository name
* e.g. Tx_Extbase_Domain_Model_Foo to Tx_Extbase_Domain_Repository_FooRepository
* or \TYPO3\CMS\Extbase\Domain\Model\Foo to \TYPO3\CMS\Extbase\Domain\Repository\FooRepository
*
* @param string $modelName Name of the model to translate
* @return string Name of the repository
*/
public static function translateModelNameToRepositoryName($modelName)
public static function translateModelNameToRepositoryName(string $modelName): string
{
return str_replace(
'\\Domain\\Model',
......@@ -43,11 +40,8 @@ class ClassNamingUtility
* Translates a repository name to an appropriate model name
* e.g. Tx_Extbase_Domain_Repository_FooRepository to Tx_Extbase_Domain_Model_Foo
* or \TYPO3\CMS\Extbase\Domain\Repository\FooRepository to \TYPO3\CMS\Extbase\Domain\Model\Foo
*
* @param string $repositoryName Name of the repository to translate
* @return string Name of the model
*/
public static function translateRepositoryNameToModelName($repositoryName)
public static function translateRepositoryNameToModelName(string $repositoryName): string
{
return preg_replace(
['/\\\\Domain\\\\Repository/', '/Repository$/'],
......@@ -61,24 +55,19 @@ class ClassNamingUtility
* into several pieces like vendorName, extensionName, subpackageKey and controllerName
*
* @param string $controllerObjectName The controller name to be exploded
* @return array An array of controllerObjectName pieces
* @return array<string> An array of controllerObjectName pieces
*/
public static function explodeObjectControllerName($controllerObjectName)
public static function explodeObjectControllerName(string $controllerObjectName): array
{
$matches = [];
if (strpos($controllerObjectName, 'TYPO3\\CMS') === 0) {
$extensionName = '^(?P<vendorName>[^\\\\]+\\\[^\\\\]+)\\\(?P<extensionName>[^\\\\]+)';
} else {
$extensionName = '^(?P<vendorName>[^\\\\]+)\\\\(?P<extensionName>[^\\\\]+)';
}
$extensionName = str_starts_with($controllerObjectName, 'TYPO3\\CMS')
? '^(?P<vendorName>[^\\\\]+\\\[^\\\\]+)\\\(?P<extensionName>[^\\\\]+)'
: '^(?P<vendorName>[^\\\\]+)\\\\(?P<extensionName>[^\\\\]+)';
preg_match(
'/' . $extensionName . '\\\\(Controller|Command|(?P<subpackageKey>.+)\\\\Controller)\\\\(?P<controllerName>[a-z\\\\]+)Controller$/ix',
$controllerObjectName,
$matches
);
return array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY);
return array_filter($matches, is_string(...), ARRAY_FILTER_USE_KEY);
}
}
......@@ -14,6 +14,7 @@ signatures. The types are consistent with existing docblock-documented type
expectations and existing behavior.
- :php:`\TYPO3\CMS\Core\Utility\ArrayUtility`
- :php:`\TYPO3\CMS\Core\Utility\ClassNamingUtility`
- :php:`\TYPO3\CMS\Core\Utility\MathUtility`
......@@ -28,7 +29,7 @@ Before the result of such method calls was undefined or inconsistent.
Affected Installations
======================
Code that are passing an invalid type will need to ensure they pass a correct type.
Code routines that are passing an invalid type will need to ensure they pass a correct type.
If a code file is running with :php:`declare(strict_types=1);`, that includes, for instance,
passing a numeric string to a method that expects an int or float. Those will need to be
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment