function it_does_complain_if_the_number_of_methods_is_too_large(ReflectionClass $sus, Params $params, Reporter $reporter) { $params->getNumberOfMethods()->willReturn(1); $params->getFilterMethods()->willReturn(null); $sus->getMethods(null)->willReturn(['method 1', 'method 2']); $sus->getName()->willReturn('Enormo Class'); $reporter->act($sus, 'Elfiggo\\Brobdingnagian\\Detector\\NumberOfMethods', 'Enormo Class has too many methods (2)', 'Too many methods')->willThrow(TooManyMethodsDetected::class); $this->shouldThrow(TooManyMethodsDetected::class)->duringCheck($sus, $params, $reporter); }
/** * @param ReflectionClass $sus * @param Params $params * @param Reporter $reporter */ public function check(ReflectionClass $sus, Params $params, Reporter $reporter) { foreach ($sus->getMethods($params->getFilterMethods()) as $method) { $lineSize = $method->getEndLine() - $method->getStartLine(); if ($lineSize > $params->getMethodSize()) { $reporter->act($sus, self::class, "{$method->getName()}() size is {$lineSize} lines long", 'Method size'); } } }
function it_should_analyse_the_number_of_methods_size(SpecificationEvent $specificationEvent, SpecificationNode $specificationNode, Params $params, Reporter $reporter) { $specificationEvent->getSpecification()->willReturn($specificationNode); $specificationNode->getTitle()->willReturn('Elfiggo\\Brobdingnagian\\Detector\\ClassSize'); $this->shouldNotThrow('Elfiggo\\Brobdingnagian\\Exception\\TooManyMethodsDetected'); $params->getFilterMethods()->willReturn(0); $params->getClassSize()->willReturn(200); $params->getDependenciesLimit()->willReturn(2); $params->getNumberOfMethods()->willReturn(5); $params->getMethodSize()->willReturn(10); $params->getNumberOfInterfaces()->willReturn(2); $params->getNumberOfTraits()->willReturn(1); $this->analyse($specificationEvent, $params, $reporter); }
function let(Params $params) { $params->getFilterMethods()->willReturn(0); }
/** * @param ReflectionClass $sus * @param Params $params * @param Reporter $reporter */ public function check(ReflectionClass $sus, Params $params, Reporter $reporter) { if (count($sus->getMethods($params->getFilterMethods())) > $params->getNumberOfMethods()) { $reporter->act($sus, self::class, "{$sus->getName()} has too many methods (" . count($sus->getMethods()) . ')', 'Too many methods'); } }