Property definitions

nitc $ LongParameterList :: defaultinit
class LongParameterList
	super BadConception
	var bad_methods = new Array[MMethodDef]

	redef fun name do return "LONGPL"

	redef fun desc do return "Long parameter list"

	redef fun collect(mclassdef, model_builder): Bool do
		for meth in mclassdef.collect_intro_and_redef_mpropdefs(filter) do
			var threshold_value = 4
			# Get the threshold value from the toolcontext command
			if phase.toolcontext.opt_long_params_threshold.value != 0 then threshold_value = phase.toolcontext.opt_long_params_threshold.value
			# Check if the property is a method definition
			if not meth isa MMethodDef then continue
			# Check if method has a signature
			if meth.msignature == null then continue
			if meth.msignature.mparameters.length <= threshold_value then continue
			self.bad_methods.add(meth)
		end
		self.score_rate
		return self.bad_methods.not_empty
	end

	redef fun print_result do
		print phase.toolcontext.format_h2("{desc}:")
		if self.bad_methods.not_empty then
			print "	Affected method(s):"
			for method in self.bad_methods do
				print "		-{method.name} has {method.msignature.mparameters.length} parameters"
			end
		end
	end

	redef fun score_rate do
		if self.bad_methods.not_empty then
			self.score = self.bad_methods.length.to_f/ phase.average_number_of_method
		end
	end
end
src/metrics/codesmells_metrics.nit:216,1--255,3