Skip to content

Commit

Permalink
[TASK] Use and apply TYPO3 coding standards, rector and type hinting
Browse files Browse the repository at this point in the history
This change integrates the typo3/coding-standards
See: https://github.com/TYPO3/coding-standards 
This commit  contains the changes after run of TYPO3 
codings standards and Rector.
Each file was checked manually and the unnecessary changes were rejected.

Relates: #3198
Closes: #3170
Fixes: #3208
  • Loading branch information
RafaelKa authored and dkd-kaehm committed Mar 7, 2022
1 parent 5147178 commit 61076e3
Show file tree
Hide file tree
Showing 400 changed files with 6,159 additions and 5,394 deletions.
34 changes: 31 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# EditorConfig is awesome: http://EditorConfig.org
# TYPO3 Standard: https://github.com/TYPO3/TYPO3.CMS/blob/master/.editorconfig
# TYPO3 Standard: https://github.com/TYPO3/coding-standards

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
Expand All @@ -12,19 +13,37 @@ indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

# TS/JS-Files
[*.{ts,js}]
indent_size = 2

# JSON-Files
[*.json]
indent_size = 2
indent_style = tab

# ReST-Files
[*.rst]
indent_size = 3
indent_size = 4
max_line_length = 80

# YAML-Files
[*.{yaml,yml}]
indent_size = 2

# NEON-Files
[*.neon]
indent_size = 2
indent_style = tab

# package.json
[package.json]
indent_size = 2

# composer.json (Reason: git history in composer.json)
[composer.json]
indent_size = 2
indent_style = space

# TypoScript
[*.{typoscript,tsconfig}]
indent_size = 2
Expand All @@ -33,6 +52,15 @@ indent_size = 2
[*.{xlf,xml}]
indent_style = tab

# SQL-Files
[*.sql]
indent_style = tab
indent_size = 2

# .htaccess
[{_.htaccess,.htaccess}]
indent_style = tab

# Bash scripts
[*.sh]
indent_style = space
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
name: Mount RAMFS
run: |
sudo mkdir -p ${{ env.CI_BUILD_DIRECTORY }}
sudo mount -t tmpfs -o size=2048m none ${{ env.CI_BUILD_DIRECTORY }}
sudo mount -t tmpfs -o size=2560m none ${{ env.CI_BUILD_DIRECTORY }}
sudo mkdir -p ${{ env.CI_BUILD_DIRECTORY }}/data-{solr,mysql} \
&& sudo chown $USER ${{ env.CI_BUILD_DIRECTORY }}/data-mysql \
&& sudo chown 8983:8983 ${{ env.CI_BUILD_DIRECTORY }}/data-solr
Expand Down Expand Up @@ -206,8 +206,8 @@ jobs:
-
name: Upload code coverage to Scrutinizer
run: |
ocular code-coverage:upload --format=php-clover coverage.unit.clover
ocular code-coverage:upload --format=php-clover coverage.integration.clover
.Build/bin/ocular code-coverage:upload --format=php-clover coverage.unit.clover
.Build/bin/ocular code-coverage:upload --format=php-clover coverage.integration.clover
-
name: Clean up
run: |
Expand Down
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
.Build
.buildpath
.DS_Store
.idea/
.php_cs.cache
.project/
.settings/
.idea/
atlassian-ide-plugin.xml
.DS_Store
composer.lock
Documentation/_make
index.php
typo3
typo3_src
typo3conf
typo3temp
typo3_src
uploads
var
vendor
/composer.lock
.Build
Documentation/_make

.php_cs.cache
11 changes: 11 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()
->exclude([
'.Build'
])
->in(__DIR__);
return $config;
22 changes: 1 addition & 21 deletions Build/Test/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,7 @@ then
exit 1
fi

# Install build tools
echo "Install build tools: "
if ! composer global require \
friendsofphp/php-cs-fixer:"$PHP_CS_FIXER_VERSION" \
sclable/xml-lint \
scrutinizer/ocular
then
echo "The build tools(friendsofphp/php-cs-fixer, sclable/xml-lint, scrutinizer/ocular) could not be installed. Please fix this issue."
exit 1
fi
COMPOSER_NO_INTERACTION=1

# Setup TYPO3 environment variables
export TYPO3_PATH_PACKAGES="${EXTENSION_ROOTPATH}.Build/vendor/"
Expand Down Expand Up @@ -123,14 +114,3 @@ then
fi

mkdir -p $TYPO3_PATH_WEB/uploads $TYPO3_PATH_WEB/typo3temp

if [[ $* != *--skip-solr-install* ]]; then
# Setup Solr Using our install script
echo "Setup Solr Using our install script: "
chmod 500 ${EXTENSION_ROOTPATH}Resources/Private/Install/install-solr.sh
if ! ${EXTENSION_ROOTPATH}Resources/Private/Install/install-solr.sh -d "$HOME/solr" -t
then
echo "Apache Solr server could not be installed or started. Please fix this issue."
exit 1
fi
fi
23 changes: 15 additions & 8 deletions Build/Test/cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,34 @@ else
echo "No syntax errors! Great job!"
fi

# use from vendor dir
if ! php-cs-fixer --version > /dev/null 2>&1
echo "Check compliance against TYPO3 Coding Standards"
if ! .Build/bin/php-cs-fixer --version > /dev/null 2>&1
then
echo "PHP CS Fixer not found, skipping PHP linting."
echo "TYPO3 https://github.com/TYPO3/coding-standards is not set properly."
echo "Please fix that asap to avoid unwanted changes in the future."
exit 1
else
echo "Check PSR-2 compliance"
if ! php-cs-fixer fix --diff --verbose --dry-run --rules='{"function_declaration": {"closure_function_spacing": "none"}}' Classes
echo "TYPO3 Coding Standards compliance: See https://github.com/TYPO3/coding-standards"
if ! composer t3:standards:fix -- --diff --verbose --dry-run && rm .php-cs-fixer.cache
then
echo "Some files are not PSR-2 compliant"
echo "Please fix the files listed above"
echo "Some files are not compliant to TYPO3 Coding Standards"
echo "Please fix the files listed above."
echo "Tip for auto fix: "
echo " composer install && composer exec php-cs-fixer fix"
exit 1
else
echo "The code is TYPO3 Coding Standards compliant! Great job!"
fi
fi
echo -e "\n\n"

echo "Run XML Lint"
if ! xmllint --version > /dev/null 2>&1; then
echo "XML Lint not found, skipping XML linting."
else
echo -e "\n\n"
echo "Check syntax of XML files"
if ! xmllint Resources/Private/Language/ -p '*.xlf'
if ! composer lint:xlf
then
echo "Some XML files are not valid"
echo "Please fix the files listed above"
Expand Down
42 changes: 21 additions & 21 deletions Classes/Access/Rootline.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace ApacheSolrForTypo3\Solr\Access;

use RuntimeException;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
Expand Down Expand Up @@ -57,7 +58,6 @@
*/
class Rootline
{

/**
* Delimiter for page and content access right elements in the rootline.
*
Expand All @@ -70,15 +70,15 @@ class Rootline
*
* @var array
*/
protected $rootlineElements = [];
protected array $rootlineElements = [];

/**
* Constructor, turns a string representation of an access rootline into an
* object representation.
*
* @param string $accessRootline Access Rootline String representation.
* @param string|null $accessRootline Access Rootline String representation.
*/
public function __construct($accessRootline = null)
public function __construct(string $accessRootline = null)
{
if (!is_null($accessRootline)) {
$rawRootlineElements = explode(self::ELEMENT_DELIMITER, $accessRootline);
Expand Down Expand Up @@ -121,22 +121,22 @@ public function push(RootlineElement $rootlineElement)
}

/**
* Gets the Access Rootline for a specific page Id.
* Gets the Access Rootline for a specific page id.
*
* @param int $pageId The page Id to generate the Access Rootline for.
* @param int $pageId The page id to generate the Access Rootline for.
* @param string $mountPointParameter The mount point parameter for generating the rootline.
* @return \ApacheSolrForTypo3\Solr\Access\Rootline Access Rootline for the given page Id.
* @return Rootline Access Rootline for the given page id.
*/
public static function getAccessRootlineByPageId(
$pageId,
$mountPointParameter = ''
) {
int $pageId,
string $mountPointParameter = ''
): Rootline {
/* @var Rootline $accessRootline */
$accessRootline = GeneralUtility::makeInstance(Rootline::class);
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId, $mountPointParameter);
try {
$rootline = $rootlineUtility->get();
} catch (\RuntimeException $e) {
} catch (RuntimeException $e) {
$rootline = [];
}
$rootline = array_reverse($rootline);
Expand All @@ -148,20 +148,22 @@ public static function getAccessRootlineByPageId(
) {
$accessRootline->push(GeneralUtility::makeInstance(
RootlineElement::class,
/** @scrutinizer ignore-type */ $pageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $pageRecord['fe_group']
/** @scrutinizer ignore-type */
$pageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $pageRecord['fe_group']
));
}
}

/** @var $pageSelector PageRepository */
/** @var $pageSelector PageRepository */
$pageSelector = GeneralUtility::makeInstance(PageRepository::class);

// current page
$currentPageRecord = $pageSelector->getPage($pageId, true);
if ($currentPageRecord['fe_group']) {
$accessRootline->push(GeneralUtility::makeInstance(
RootlineElement::class,
/** @scrutinizer ignore-type */ $currentPageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $currentPageRecord['fe_group']
/** @scrutinizer ignore-type */
$currentPageRecord['uid'] . RootlineElement::PAGE_ID_GROUP_DELIMITER . $currentPageRecord['fe_group']
));
}

Expand All @@ -185,11 +187,11 @@ public function __toString()
}

/**
* Gets a the groups in the Access Rootline.
* Gets the groups in the Access Rootline.
*
* @return array An array of sorted, unique user group IDs required to access a page.
*/
public function getGroups()
public function getGroups(): array
{
$groups = [];

Expand All @@ -198,19 +200,17 @@ public function getGroups()
$groups = array_merge($groups, $rootlineElementGroups);
}

$groups = $this->cleanGroupArray($groups);

return $groups;
return $this->cleanGroupArray($groups);
}

/**
* Cleans an array of frontend user group IDs. Removes duplicates and sorts
* Cleans an array of frontend user group IDs. Removes the duplicates and sorts
* the array.
*
* @param array $groups An array of frontend user group IDs
* @return array An array of cleaned frontend user group IDs, unique, sorted.
*/
public static function cleanGroupArray(array $groups)
public static function cleanGroupArray(array $groups): array
{
$groups = array_unique($groups); // removes duplicates
sort($groups, SORT_NUMERIC); // sort
Expand Down
6 changes: 3 additions & 3 deletions Classes/Access/RootlineElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ class RootlineElement
/**
* Page Id for the element. NULL for the content type.
*
* @var int
* @var int|null
*/
protected $pageId = null;
protected ?int $pageId = null;

/**
* Set of access groups assigned to the element.
Expand Down Expand Up @@ -116,7 +116,7 @@ public function __construct($element)
);
}

$this->pageId = intval($elementAccess[0]);
$this->pageId = (int)($elementAccess[0]);
$elementGroups = $elementAccess[1];
}

Expand Down
Loading

0 comments on commit 61076e3

Please sign in to comment.