File policy.rb
has 400 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Policy < ActiveRecord::Base
has_many :permissions,
:dependent => :destroy,
:order => "created_at ASC",
Method set_attributes_with_sharing
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
def set_attributes_with_sharing sharing, projects
# if no data about sharing is given, it should be some user (not the owner!)
# who is editing the asset - no need to do anything with policy / permissions: return success
self.tap do |policy|
if sharing
- 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
Class Policy
has 34 methods (exceeds 20 allowed). Consider refactoring. Open
class Policy < ActiveRecord::Base
has_many :permissions,
:dependent => :destroy,
:order => "created_at ASC",
Method permissions_to_people_group
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
def permissions_to_people_group permissions, people_in_group
permissions.each do |permission|
contributor_id = permission.contributor_id
access_type = permission.access_type
case permission.contributor_type
- 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 policy_to_people_group
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def policy_to_people_group people_in_group, contributor=User.current_user.person
if sharing_scope == Policy::ALL_SYSMO_USERS
people_in_network = get_people_in_network access_type
people_in_group['Network'] |= people_in_network unless people_in_network.blank?
elsif sharing_scope == Policy::EVERYONE
- 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 concat_roles_to_name
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def concat_roles_to_name grouped_people_by_access_type, creators, asset_managers
creator_id_array = creators.collect{|c| c.id unless c.blank?}
asset_manage_id_array = asset_managers.collect{|am| am.id unless am.blank?}
grouped_people_by_access_type = grouped_people_by_access_type.reject{|key,value| key == Policy::DETERMINED_BY_GROUP}.each_value do |value|
value.each do |person|
- 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 set_attributes_with_sharing
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_attributes_with_sharing sharing, projects
# if no data about sharing is given, it should be some user (not the owner!)
# who is editing the asset - no need to do anything with policy / permissions: return success
self.tap do |policy|
if sharing
Method summarize_permissions
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def summarize_permissions creators=[User.current_user.try(:person)], asset_managers = [], contributor=User.current_user.try(:person)
#build the hash containing contributor_type as key and the people in these groups as value,exception:'Public' holds the access_type as the value
people_in_group = {'Person' => [], 'FavouriteGroup' => [], 'WorkGroup' => [], 'Project' => [], 'Institution' => [], 'WhiteList' => [], 'BlackList' => [],'Network' => [], 'Public' => 0}
#the result return: a hash contain the access_type as key, and array of people as value
grouped_people_by_access_type = {}
- 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 summarize_permissions
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def summarize_permissions creators=[User.current_user.try(:person)], asset_managers = [], contributor=User.current_user.try(:person)
#build the hash containing contributor_type as key and the people in these groups as value,exception:'Public' holds the access_type as the value
people_in_group = {'Person' => [], 'FavouriteGroup' => [], 'WorkGroup' => [], 'Project' => [], 'Institution' => [], 'WhiteList' => [], 'BlackList' => [],'Network' => [], 'Public' => 0}
#the result return: a hash contain the access_type as key, and array of people as value
grouped_people_by_access_type = {}
Method get_access_type_wording
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def self.get_access_type_wording(access_type, downloadable=false)
#MERGENOTE - VLN used hard-coded values here that should be moved into the en.yml file
case access_type
when Policy::DETERMINED_BY_GROUP
return I18n.t('access.determined_by_group')
- 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 get_people_in_network
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_people_in_network access_type
people_in_network = [] #id, name, access_type
projects = Project.all
projects.each do |project|
project.people.each do |person|
- 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 get_people_in_FG
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_people_in_FG contributor, fg_id=nil, is_white_list=nil, is_black_list=nil
if is_white_list
f_group = FavouriteGroup.where(["name = ? AND user_id = ?", "__whitelist__", contributor.user.id]).first
elsif is_black_list
f_group = FavouriteGroup.where(["name = ? AND user_id = ?", "__blacklist__", contributor.user.id]).first
- 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 is_entirely_private?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def is_entirely_private? grouped_people_by_access_type, contributor
entirely_private = true
if access_type > Policy::NO_ACCESS
entirely_private = false
else
- 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
Avoid too many return
statements within this method. Open
return downloadable ? I18n.t('access.editing_downloadable') : I18n.t('access.editing')
Avoid too many return
statements within this method. Open
return "Invalid access type"
Avoid too many return
statements within this method. Open
return I18n.t('access.managing')
Method precedence
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def precedence array1, array2
result = []
result |= array2
array1.each do |a1|
check = false
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
def get_people_in_project project_id, access_type
project = Project.find(project_id)
if project
people_in_project = [] #id, name, access_type
project.people.each do |person|
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 31.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
def get_people_in_institution institution_id, access_type
institution = Institution.find(institution_id)
if institution
people_in_institution = [] #id, name, access_type
institution.people.each do |person|
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 31.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76