File FeaturesFunctions.php
has 553 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*
* Copyright 2018 Jérôme Gasperi
*
* Licensed under the Apache License, version 2.0 (the "License");
Function featureArrayToKeysValues
has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring. Open
private function featureArrayToKeysValues($collection, $featureArray, $protected, $updatabled)
{
// Initialize
$keysAndValues = array(
'links' => isset($featureArray['links']) ? json_encode($featureArray['links'], JSON_UNESCAPED_SLASHES) : null,
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method search
has 85 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function search($context, $user, $model, $collections, $paramsWithOperation, $sorting)
{
/*
* Check that mandatory filters are set
*/
Function search
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public function search($context, $user, $model, $collections, $paramsWithOperation, $sorting)
{
/*
* Check that mandatory filters are set
*/
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method featureArrayToKeysValues
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function featureArrayToKeysValues($collection, $featureArray, $protected, $updatabled)
{
// Initialize
$keysAndValues = array(
'links' => isset($featureArray['links']) ? json_encode($featureArray['links'], JSON_UNESCAPED_SLASHES) : null,
Method updateFeature
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function updateFeature($feature, $collection, $newFeatureArray)
{
if (!isset($feature)) {
RestoLogUtil::httpError(404);
}
Method storeFeature
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function storeFeature($id, $collection, $featureArray)
{
$keysValues = $this->featureArrayToKeysValues(
$collection,
$featureArray,
Function getSelectClause
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
private function getSelectClause($featureTableName, $featureColumns, $user, $options)
{
$sanitized = $this->sanitizeSQLColumns($featureColumns, isset($options['fields']) ? array_map('trim', explode(',', $options['fields'])) : array());
/*
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function extractHashtagsFromText
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function extractHashtagsFromText($text, $stringOnly)
{
$matches = null;
if (isset($text)) {
preg_match_all("/#([^ ]+)/u", $text, $matches);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getSelectClause
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getSelectClause($featureTableName, $featureColumns, $user, $options)
{
$sanitized = $this->sanitizeSQLColumns($featureColumns, isset($options['fields']) ? array_map('trim', explode(',', $options['fields'])) : array());
/*
Function sanitizeSQLColumns
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function sanitizeSQLColumns($featureColumns, $fields)
{
$discarded = array();
/*
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method updateFeatureDescription
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function updateFeatureDescription($feature, $description)
{
// Get hashtags to remove from feature before update
$hashtagsToRemove = $this->extractHashtagsFromText($feature->toArray()['properties']['description'], true);
$hashtagsToAdd = $this->extractHashtagsFromText($description, true);
Method search
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function search($context, $user, $model, $collections, $paramsWithOperation, $sorting)
Function checkMandatoryFilters
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function checkMandatoryFilters($searchFilters, $paramsWithOperation)
{
$missing = array();
foreach (array_keys($searchFilters) as $filterName) {
if (isset($searchFilters[$filterName])) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getFeatureDescription
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function getFeatureDescription($context, $user, $featureId, $collection, $fields)