org.sonar.plugins.php.api.Php Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonar-php-plugin Show documentation
Show all versions of sonar-php-plugin Show documentation
Sonar PHP Plugin is set of tools that brings PHP support to sonar. It relies on Sonar core, PHP Depend, PHPMD, PHP_CodeSniffer and PHPUnit
/*
* SonarQube PHP Plugin
* Copyright (C) 2010 SonarSource and Akram Ben Aissi
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.php.api;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.AbstractLanguage;
import org.sonar.plugins.php.PhpPlugin;
import java.util.List;
/**
* This class defines the PHP language.
*/
public final class Php extends AbstractLanguage {
public static final String NAME = "PHP";
public static final String KEY = "php";
public static final String DEFAULT_FILE_SUFFIXES = "php,php3,php4,php5,phtml,inc";
private Settings settings;
/**
* Construct the PHP language.
*/
public Php(Settings settings) {
super(KEY, NAME);
this.settings = settings;
}
/**
* Only for testing purposes.
*/
public Php() {
this(new Settings());
}
/**
* {@inheritDoc}
*/
public String[] getFileSuffixes() {
String[] suffixes = filterEmptyStrings(settings.getStringArray(PhpPlugin.FILE_SUFFIXES_KEY));
if (suffixes.length == 0) {
suffixes = StringUtils.split(Php.DEFAULT_FILE_SUFFIXES, ",");
}
return suffixes;
}
private String[] filterEmptyStrings(String[] stringArray) {
List nonEmptyStrings = Lists.newArrayList();
for (String string : stringArray) {
if (StringUtils.isNotBlank(string.trim())) {
nonEmptyStrings.add(string.trim());
}
}
return nonEmptyStrings.toArray(new String[nonEmptyStrings.size()]);
}
/**
* Allows to know if the given file name has a valid suffix.
*
* @param fileName String representing the file name
* @return boolean true
if the file name's suffix is known, false
any other way
*/
public boolean hasValidSuffixes(String fileName) {
String pathLowerCase = StringUtils.lowerCase(fileName);
for (String suffix : getFileSuffixes()) {
if (pathLowerCase.endsWith("." + StringUtils.lowerCase(suffix))) {
return true;
}
}
return false;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy