TASK: Implement basic structure

* Adjust to latest develop state of project.
* Provide basic implementation.

Relates: #44
This commit is contained in:
Daniel Siepmann 2017-05-04 16:43:09 +02:00
parent c7112c0fae
commit 5adbac1a25
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
10 changed files with 158 additions and 75 deletions

View file

@ -0,0 +1,6 @@
# Breaking changes in 7.0: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Index.html#breaking-changes
'7.0':
perm:
replacement: 'The logic is moved into EXT:beuser'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62339-MoveExtPermIntoExtBeuser.html'

View file

@ -56,6 +56,17 @@ class Options
); );
} }
/**
* @return array<string>
*/
public static function getRemovedExtensionConfigFiles()
{
return static::getOptionFileNames(
'removedExtensionConfigFiles',
__DIR__ . '/Configuration/Removed/Extension/*.yaml'
);
}
/** /**
* Returns an array of absolute file names containing removed function configurations. * Returns an array of absolute file names containing removed function configurations.
* *

View file

@ -66,4 +66,35 @@ trait ExtendedPhpCsSupportTrait
return true; return true;
} }
/**
* Returns all parameters for function call as values.
* Quotes are removed from strings.
*
* @param PhpCsFile $phpcsFile
* @param int $stackPtr
*
* @return array<string>
*/
protected function getFunctionCallParameters(PhpCsFile $phpcsFile, $stackPtr)
{
$start = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr) + 1;
$parameters = explode(',', $phpcsFile->getTokensAsString(
$start,
$phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr) - $start
));
return array_map([$this, 'getStringContent'], $parameters);
}
/**
* Remove special chars like quotes from string.
*
* @param string
* @return string
*/
public function getStringContent($string)
{
return trim($string, " \t\n\r\0\x0B'\"");
}
} }

View file

@ -33,6 +33,23 @@ abstract class AbstractGenericUsage extends BaseAbstractYamlRemovedUsage impleme
*/ */
abstract protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr); abstract protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr);
protected function prepareStructure(array $typo3Versions)
{
$newStructure = [];
foreach ($typo3Versions as $typo3Version => $removals) {
foreach ($removals as $removed => $config) {
$config['name'] = $removed;
$config['identifier'] = $removed;
$config['oldUsage'] = $removed;
$config['versionRemoved'] = $typo3Version;
$newStructure[$removed] = $config;
}
}
return $newStructure;
}
/** /**
* @param PhpCsFile $phpcsFile * @param PhpCsFile $phpcsFile
* @param int $stackPtr * @param int $stackPtr

View file

@ -1,58 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: dah
* Date: 11.04.17
* Time: 12:12
*/
class Typo3Update_Sniffs_Removed_ExtensionKeySniff extends \Typo3Update\Sniffs\Removed\AbstractGenericUsage
{
/**
* Return file names containing removed configurations.
*
* @return array<string>
*/
protected function getRemovedConfigFiles()
{
return [];
}
/**
* The original call, to allow user to check matches.
*
* As we match the name, that can be provided by multiple classes, you
* should provide an example, so users can check that this is the legacy
* one.
*
* @param array $config
*
* @return string
*/
protected function getOldUsage(array $config)
{
return '';
}
/**
* Registers the tokens that this sniff wants to listen for.
*
* An example return value for a sniff that wants to listen for whitespace
* and any comments would be:
*
* <code>
* return array(
* T_WHITESPACE,
* T_DOC_COMMENT,
* T_COMMENT,
* );
* </code>
*
* @return int[]
* @see Tokens.php
*/
public function register()
{
return [];
}
}

View file

@ -0,0 +1,62 @@
<?php
/*
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use PHP_CodeSniffer_File as PhpCsFile;
use Typo3Update\Options;
use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait;
use Typo3Update\Sniffs\Removed\AbstractGenericUsage;
class Typo3Update_Sniffs_Removed_ExtensionSniff extends AbstractGenericUsage
{
use ExtendedPhpCsSupportTrait;
/**
* @var array
*/
public $methodsToCheck = ['isLoaded', 'extPath', 'extRelPath', 'getCN', 'getExtensionVersion'];
public function register()
{
return [T_STRING];
}
protected function getRemovedConfigFiles()
{
return Options::getRemovedExtensionConfigFiles();
}
protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr)
{
$token = $phpcsFile->getTokens()[$stackPtr];
if (!$this->isFunctionCall($phpcsFile, $stackPtr)
|| !in_array($token['content'], $this->methodsToCheck)
) {
return [];
}
$arguments = $this->getFunctionCallParameters($phpcsFile, $stackPtr);
if ($this->configured->isRemoved($arguments[0])) {
return [$this->configured->getRemoved($arguments[0])];
}
return [];
}
}

View file

@ -42,23 +42,6 @@ class Typo3Update_Sniffs_Removed_TypoScriptConstantSniff extends AbstractGeneric
]; ];
} }
protected function prepareStructure(array $typo3Versions)
{
$newStructure = [];
foreach ($typo3Versions as $typo3Version => $removals) {
foreach ($removals as $removed => $config) {
$config['name'] = $removed;
$config['identifier'] = $removed;
$config['oldUsage'] = $removed;
$config['versionRemoved'] = $typo3Version;
$newStructure[$removed] = $config;
}
}
return $newStructure;
}
protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr)
{ {
$removed = []; $removed = [];

View file

@ -19,4 +19,7 @@
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use TYPO3\CMS\Perm\Controller\PermissionModuleController;
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('perm'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('perm');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('perm');

View file

@ -0,0 +1,28 @@
<?php
namespace Typo3Update\Tests\Sniffs\Removed;
/*
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Typo3Update\Tests\SniffsTest;
class ExtensionSniffTest extends SniffsTest
{
}