automated-typo3-update/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php
Daniel Siepmann 4ac34503d1
FEATURE: Check removed globals
* Add feature, tests and configuration.
* Refactor to follow DRY, move prepareStructure to abstract.

Resolves: #77
2017-05-09 14:48:44 +02:00

68 lines
2.1 KiB
PHP

<?php
namespace Typo3Update\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 PHP_CodeSniffer_File as PhpCsFile;
use PHP_CodeSniffer_Sniff as PhpCsSniff;
use Typo3Update\AbstractYamlRemovedUsage as BaseAbstractYamlRemovedUsage;
abstract class AbstractGenericUsage extends BaseAbstractYamlRemovedUsage implements PhpCsSniff
{
/**
* @param PhpCsFile $phpcsFile
* @param int $stackPtr
* @return array
*/
abstract protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr);
/**
* @param array $typo3Versions
* @return array
*/
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 int $stackPtr
*/
public function process(PhpCsFile $phpcsFile, $stackPtr)
{
foreach ($this->findRemoved($phpcsFile, $stackPtr) as $removed) {
$this->addWarning($phpcsFile, $stackPtr, $removed);
}
}
}