lithium\test\filter\Complexity::apply()

public static method

Takes an instance of an object (usually a Collection object) containing test instances. Introspects the test subject classes to extract cyclomatic complexity data.

Parameters

  • object $report

    Instance of Report which is calling apply.

  • array $tests

    The test to apply this filter on

  • array $options

    Additional options to overwrite dependencies.

    • 'classes' array: Overwrite default classes array.

Returns

object

Returns the instance of $tests.

Source

	public static function apply($report, $tests, array $options = array()) {
		$results = array();
		$options += array(
			'classes' => array(),
		);
		$classes = $options['classes'] + static::$_classes;
		$inspector = $classes['inspector'];
		$parser = $classes['parser'];

		foreach ($tests->invoke('subject') as $class) {
			$results[$class] = array();

			if (!$methods = $inspector::methods($class, 'ranges', array('public' => false))) {
				continue;
			}
			foreach ($methods as $method => $lines) {
				$lines = $inspector::lines($class, $lines);
				$branches = $parser::tokenize(join("\n", (array) $lines), array(
					'include' => static::$_include
				));
				$results[$class][$method] = count($branches) + 1;
				$report->collect(__CLASS__, $results);
			}
		}
		return $tests;
	}