Merge remote-tracking branch 'origin/develop' into feature/44-add-checks-for-deprecated-removed-extensions

This commit is contained in:
Daniel Siepmann 2017-05-18 08:39:04 +02:00
commit f5c609e57b
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
10 changed files with 226 additions and 4 deletions

View file

@ -255,6 +255,28 @@ Using ``runtime-set``:
--runtime-set removedExtensionConfigFiles "/Some/Absolute/Path/*.yaml"
.. _configuration-removedGlobalConfigFiles:
removedGlobalConfigFiles
^^^^^^^^^^^^^^^^^^^^^^^^
Configure where to look for configuration files defining the removed globals. Default is
``Configuration/Removed/Globals/*.yaml`` inside the standard itself. We already try to deliver as
much as possible. Globing is used, so placeholders like ``*`` are possible, see
https://secure.php.net/manual/en/function.glob.php
Using :file:`ruleset.xml`:
.. code:: xml
<config name="removedGlobalConfigFiles" value="/Some/Absolute/Path/*.yaml"/>
Using ``runtime-set``:
.. code:: bash
--runtime-set removedGlobalConfigFiles "/Some/Absolute/Path/*.yaml"
.. _configuration-removedTypoScriptConfigFiles:
removedTypoScriptConfigFiles

View file

@ -106,6 +106,9 @@ functions. For configuration options see :ref:`configuration-removedConstantConf
Check for usage of *removed PHP classes*. The classes are configured in same way as removed
functions. For configuration options see :ref:`configuration-removedClassConfigFiles`.
Check for usage of *removed PHP globals*. The globals are configured in same way as removed
functions. For configuration options see :ref:`configuration-removedGlobalConfigFiles`.
Check for usage of *removed TYPO3 extension*. For configuration options see
:ref:`configuration-removedExtensionConfigFiles`.

View file

@ -0,0 +1,8 @@
# Breaking changes in 7.0: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Index.html#breaking-changes
'7.0':
typo3CacheManager:
replacement: 'Use GeneralUtility::makeInstance() instead'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes'
typo3CacheFactory:
replacement: 'Use GeneralUtility::makeInstance() instead'
docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes'

View file

@ -158,6 +158,19 @@ class Options
);
}
/**
* Returns an array of absolute file names containing removed globals configurations.
*
* @return array<string>
*/
public static function getRemovedGlobalConfigFiles()
{
return static::getOptionFileNames(
'removedGlobalConfigFiles',
__DIR__ . '/Configuration/Removed/Globals/*.yaml'
);
}
/**
* Get the option by optionName, if not defined, use default.
*

View file

@ -28,6 +28,28 @@ use PHP_CodeSniffer_Tokens as Tokens;
*/
trait ExtendedPhpCsSupportTrait
{
/**
* Check whether variable at $stackPtr is global.
*
* @param PhpCsFile $phpcsFile
* @param int $stackPtr
*
* @return bool
*/
protected function isGlobalVariable(PhpCsFile $phpcsFile, $stackPtr)
{
$position = $phpcsFile->findPrevious(T_GLOBAL, $stackPtr, null, false, null, true);
if ($position !== false) {
return true;
}
if ($phpcsFile->getTokens()[$stackPtr]['content'] === '$GLOBALS') {
return true;
}
return false;
}
/**
* Check whether current stackPtr is a function call.
*
@ -68,10 +90,6 @@ trait ExtendedPhpCsSupportTrait
}
/**
* Returns all parameters for function call as values.
* Quotes are removed from strings.
*
* @param PhpCsFile $phpcsFile
* @param int $stackPtr
*
* @return array<string>

View file

@ -33,6 +33,10 @@ abstract class AbstractGenericUsage extends BaseAbstractYamlRemovedUsage impleme
*/
abstract protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr);
/**
* @param array $typo3Versions
* @return array
*/
protected function prepareStructure(array $typo3Versions)
{
$newStructure = [];

View file

@ -0,0 +1,66 @@
<?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\Removed\AbstractGenericUsage;
use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait;
class Typo3Update_Sniffs_Removed_GenericGlobalSniff extends AbstractGenericUsage
{
use ExtendedPhpCsSupportTrait;
public function register()
{
return [T_VARIABLE];
}
/**
* @param PhpCsFile $phpcsFile
* @param int $stackPtr
* @return array
*/
protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr)
{
if ($this->isGlobalVariable($phpcsFile, $stackPtr) === false) {
return [];
}
$variableName = substr($phpcsFile->getTokens()[$stackPtr]['content'], 1);
if ($variableName === 'GLOBALS') {
$variableName = trim(
$phpcsFile->getTokens()[$phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr)]['content'],
'\'"'
);
}
if ($this->configured->isRemoved($variableName)) {
return [$this->configured->getRemoved($variableName)];
}
return [];
}
protected function getRemovedConfigFiles()
{
return Options::getRemovedGlobalConfigFiles();
}
}

View file

@ -0,0 +1,33 @@
{
"files": {
"InputFileForIssues.php": {
"errors": 0,
"messages": [
{
"column": 12,
"fixable": false,
"line": 24,
"message": "Calls to removed code are not allowed; found typo3CacheFactory. Removed in 7.0. Use GeneralUtility::makeInstance() instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes",
"severity": 5,
"source": "Typo3Update.Removed.GenericGlobal.typo3CacheFactory",
"type": "WARNING"
},
{
"column": 26,
"fixable": false,
"line": 25,
"message": "Calls to removed code are not allowed; found typo3CacheManager. Removed in 7.0. Use GeneralUtility::makeInstance() instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes",
"severity": 5,
"source": "Typo3Update.Removed.GenericGlobal.typo3CacheManager",
"type": "WARNING"
}
],
"warnings": 2
}
},
"totals": {
"errors": 0,
"fixable": 0,
"warnings": 2
}
}

View file

@ -0,0 +1,27 @@
<?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.
*/
function name()
{
global $typo3CacheFactory;
$typo3CacheManager = $GLOBALS['typo3CacheManager'];
$typo3CacheManager->something();
}

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 GenericGlobalSniffTest extends SniffsTest
{
}