False positive - duplicated line/block of code

Hi sonar community,

This feels like bug or it can be a misconfiguration issue.
We are working in php and a we have a long mapping declaration which sonarcloud detect:

  • as duplicated block of code.
  • comment as duplicated lines (but are new in reality)

Of course following data is fake. But in reality we have a declaration of almost 100 mapped object inside. and that variable is declared as duplicated code to itself…

public function getResourceMap()
        $mapping = [
            'map_object_1' => [
                'model' => '\App\Models\map_object_1',
                'transformer' => '\App\Transformers\Smart\MapObjectOne'
            // a lot of mapping isn't it?
            // those 2 commented lines are declared as duplicated line
            'map_object_100' => [
                'model' => '\App\Models\map_object_100',
                'transformer' => '\App\Transformers\Smart\MapObjectHundred'

        // Fill endpoints for all routes.
        $endpointBaseUri = request()->route()->getPrefix();
        foreach ($mapping as $key => &$data) {
            // Define endpoint url
            $data['endpoint'] = url('/') . '/' . $endpointBaseUri . '/' . $key;
            // Define resource used for mapping
            $data['resource'] = $key;

        return $mapping;

Is it a bug?

Hey there.

SonarCloud ignores string literals when doing duplication detection. Such a file is probably ideal to exclude from duplication detection, which can be done at the file level!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.