Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues reported by SonarCloud #924

Merged
merged 6 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ protected function negotiateFormat($choices, $accept, $format)
// if there was no proposed format, negotiate a suitable format
header('Vary: Accept'); // inform caches that a decision was made based on Accept header
$best = $this->negotiator->getBest($accept, $choices);
$format = ($best !== null) ? $best->getValue() : null;
return $format;
return ($best !== null) ? $best->getValue() : null;
}

private function isSecure()
Expand All @@ -106,8 +105,7 @@ private function guessBaseHref()
$port = filter_input(INPUT_SERVER, 'SERVER_PORT', FILTER_SANITIZE_STRING);
$disp_port = ($port == 80 || $port == 443) ? '' : ":$port";
$domain = filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_STRING);
$full_url = "$protocol://{$domain}{$disp_port}{$base_url}";
return $full_url;
return "$protocol://{$domain}{$disp_port}{$base_url}";
}

public function getBaseHref()
Expand Down
7 changes: 3 additions & 4 deletions controller/Honeypot.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ public function generate($honey_name, $honey_time)
{
// Encrypt the current time
$honey_time_encrypted = $this->getEncryptedTime();
$html = '<div id="' . $honey_name . '_wrap" style="display:none;">' . "\r\n" .
'<input name="' . $honey_name . '" type="text" value="" id="' . $honey_name . '"/>' . "\r\n" .
'<input name="' . $honey_time . '" type="text" value="' . $honey_time_encrypted . '"/>' . "\r\n" .
return '<div id="' . $honey_name . '_wrap" style="display:none;">' . "\r\n" .
'<input name="' . $honey_name . '" type="text" value="" id="' . $honey_name . '"/>' . "\r\n" .
'<input name="' . $honey_time . '" type="text" value="' . $honey_time_encrypted . '"/>' . "\r\n" .
'</div>';
return $html;
}
/**
* Validate honeypot is empty
Expand Down
6 changes: 2 additions & 4 deletions controller/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,11 @@ private function transformPropertyResults($uri, $lang, $objects, $propname, $pro
$results[] = array('uri' => $objuri, 'prefLabel' => $vals['label']);
}

$ret = array_merge_recursive($this->context, array(
return array_merge_recursive($this->context, array(
'@context' => array('prefLabel' => 'skos:prefLabel', $propname => $propuri, '@language' => $lang),
'uri' => $uri,
$propname => $results)
);
return $ret;
}

private function transformTransitivePropertyResults($uri, $lang, $objects, $tpropname, $tpropuri, $dpropname, $dpropuri)
Expand All @@ -726,12 +725,11 @@ private function transformTransitivePropertyResults($uri, $lang, $objects, $tpro
$results[$objuri] = $result;
}

$ret = array_merge_recursive($this->context, array(
return array_merge_recursive($this->context, array(
'@context' => array('prefLabel' => 'skos:prefLabel', $dpropname => array('@id' => $dpropuri, '@type' => '@id'), $tpropname => array('@id' => $tpropuri, '@container' => '@index'), '@language' => $lang),
'uri' => $uri,
$tpropname => $results)
);
return $ret;
}

/**
Expand Down
3 changes: 1 addition & 2 deletions controller/WebController.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ private function createFeedbackHeaders($fromName, $fromEmail, $toMail, $sender)
}

$service = $this->model->getConfig()->getServiceName();
$headers .= "From: $fromName via $service <$sender>";
return $headers;
return $headers . "From: $fromName via $service <$sender>";
}

/**
Expand Down
11 changes: 3 additions & 8 deletions model/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,7 @@ public function getMappingProperties(array $whitelist = null)
}

// sorting the properties to a order preferred in the Skosmos concept page.
$ret = $this->arbitrarySort($ret);

return $ret;
return $this->arbitrarySort($ret);
}

/**
Expand Down Expand Up @@ -632,8 +630,7 @@ public function getProperties()

$ret = $this->removeDuplicatePropertyValues($ret, $duplicates);
// sorting the properties to the order preferred in the Skosmos concept page.
$ret = $this->arbitrarySort($ret);
return $ret;
return $this->arbitrarySort($ret);
}

/**
Expand Down Expand Up @@ -904,8 +901,6 @@ public function dumpJsonLd() {
}
}
$compactJsonLD = \ML\JsonLD\JsonLD::compact($this->graph->serialise('jsonld'), json_encode($context));
$results = \ML\JsonLD\JsonLD::toString($compactJsonLD);

return $results;
return \ML\JsonLD\JsonLD::toString($compactJsonLD);
}
}
6 changes: 2 additions & 4 deletions model/ConceptMappingPropertyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ private function queryLabel($lang = '', $queryExVocabs = true)
}

// using URI as label if nothing else has been found.
$label = $this->resource->shorten() ? $this->resource->shorten() : $this->resource->getUri();
return $label;
return $this->resource->shorten() ? $this->resource->shorten() : $this->resource->getUri();
}

private function getResourceLabel($res, $lang = '') {
Expand Down Expand Up @@ -108,8 +107,7 @@ public function getUri()

public function getExVocab()
{
$exvocab = $this->model->guessVocabularyFromURI($this->getUri(), $this->vocab->getId());
return $exvocab;
return $this->model->guessVocabularyFromURI($this->getUri(), $this->vocab->getId());
}

public function getVocab()
Expand Down
3 changes: 1 addition & 2 deletions model/ConceptPropertyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public function getLabel($lang = '', $fallbackToUri = 'uri')

if ($fallbackToUri == 'uri') {
// return uri if no label is found
$label = $this->resource->shorten() ? $this->resource->shorten() : $this->getUri();
return $label;
return $this->resource->shorten() ? $this->resource->shorten() : $this->getUri();
}
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions model/ConceptSearchParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function getVocabIds()
return ($vocabs !== null && $vocabs !== '') ? explode(' ', $vocabs) : null;
}
$vocabs = $this->getVocabs();
$ret = isset($vocabs[0]) ? array($vocabs[0]->getId()) : null;
return $ret;
return isset($vocabs[0]) ? array($vocabs[0]->getId()) : null;
}

public function setVocabularies($vocabs)
Expand Down
4 changes: 1 addition & 3 deletions model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,7 @@ public function getVocabularyCategories()
public function getClassificationLabel($lang)
{
$cats = $this->globalConfig->getGraph()->allOfType('skos:ConceptScheme');
$label = $cats ? $cats[0]->label($lang) : null;

return $label;
return $cats ? $cats[0]->label($lang) : null;
}

/**
Expand Down
17 changes: 6 additions & 11 deletions resource/js/docready.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $(function() { // DOCUMENT READY
});
return removeThese.join(' ');
});
if (settings.url.indexOf('index/' !== -1)) {
if (settings.url.indexOf('index/') !== -1) {
$(".sidebar-grey").mCustomScrollbar({
alwaysShowScrollbar: 1,
scrollInertia: 0,
Expand Down Expand Up @@ -247,8 +247,8 @@ $(function() { // DOCUMENT READY
var $delayedSpinner = $("<p class='concept-spinner center-block'>" + loading_text + "&hellip;</p>");

// adds a delay before showing the spinner configured above
function delaySpinner(loading) {
loading = setTimeout(function() { $('.concept-spinner').show() }, 500);
function delaySpinner() {
return setTimeout(function() { $('.concept-spinner').show() }, 500);
}

function ajaxConceptMapping(data) {
Expand Down Expand Up @@ -276,11 +276,10 @@ $(function() { // DOCUMENT READY
var historyUrl = (clang !== lang) ? targetUrl + '?' + parameters : targetUrl;
$('#hier-trigger').attr('href', targetUrl);
var $content = $('.content').empty().append($delayedSpinner.hide());
var loading;
var loading = delaySpinner();
$.ajax({
url : targetUrl,
data: parameters,
beforeSend: delaySpinner(loading),
complete: clearTimeout(loading),
success : function(data) {
$content.empty();
Expand All @@ -307,10 +306,9 @@ $(function() { // DOCUMENT READY
$('.activated-concept').removeClass('activated-concept');
$(this).addClass('activated-concept');
var $content = $('.content').empty().append($delayedSpinner.hide());
var loading;
var loading = delaySpinner();
$.ajax({
url : event.target.href,
beforeSend: delaySpinner(loading),
complete: clearTimeout(loading),
success : function(data) {
if (window.history.pushState) { window.history.pushState({}, null, event.target.href); }
Expand Down Expand Up @@ -433,12 +431,10 @@ $(function() { // DOCUMENT READY
$(document).on('click','div.group-hierarchy a',
function(event) {
var $content = $('.content').empty().append($delayedSpinner.hide());
var loading;
var loading = delaySpinner();
// ajaxing the sidebar content
$.ajax({
url : event.target.href,
beforeSend: delaySpinner(loading),
complete: clearTimeout(loading),
success : function(data) {
initHierarchyQtip();
$('#hier-trigger').attr('href', event.target.href);
Expand Down Expand Up @@ -663,7 +659,6 @@ $(function() { // DOCUMENT READY
},
ajax: {
beforeSend: function(jqXHR, settings) {
wildcard = ($('#search-field').val().indexOf('*') === -1) ? '*' : '';
var vocabString = $('.frontpage').length ? vocabSelectionString : vocab;
var parameters = $.param({'vocab' : vocabString, 'lang' : qlang, 'labellang' : qlang});
// if the search has been targeted at all languages by clicking the checkbox
Expand Down
3 changes: 2 additions & 1 deletion tests/DataObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class DataObjectTest extends PHPUnit\Framework\TestCase
*/
public function testConstructorNoArguments()
{
new DataObject(null, null);
$obj = new DataObject(null, null);
$this->assertNotNull($obj);
}

}
6 changes: 4 additions & 2 deletions tests/GlobalConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,17 @@ public function testGetGlobalPlugins()
*/
public function testInitializeConfigWithoutGraph()
{
new GlobalConfig('/../tests/testconfig-nograph.ttl');
$conf = new GlobalConfig('/../tests/testconfig-nograph.ttl');
$this->assertNotNull($conf);
}

/**
* @expectedException
*/
public function testInexistentFile()
{
new GlobalConfig('/../tests/testconfig-idonotexist.ttl');
$conf = new GlobalConfig('/../tests/testconfig-idonotexist.ttl');
$this->assertNotNull($conf);
}

// --- tests for some default values
Expand Down
3 changes: 2 additions & 1 deletion tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ protected function tearDown() {
*/
public function testConstructorWithConfig()
{
new Model(new GlobalConfig('/../tests/testconfig.ttl'));
$model = new Model(new GlobalConfig('/../tests/testconfig.ttl'));
$this->assertNotNull($model);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/VocabularyCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ protected function setUp() {
* @expectedExceptionMessage Invalid constructor parameter given to DataObject.
*/
public function testConstructorWithInvalidParameters() {
new VocabularyCategory('invalid', 'invalid');
$vcat = new VocabularyCategory('invalid', 'invalid');
$this->assertNotNull($vcat);
}

/**
Expand Down