Permalink
Browse files

- Fixed #9936901: WMCi calculation is incorrect for overwritten methods.

  • Loading branch information...
manuelpichler committed Feb 12, 2011
1 parent 7b367cc commit 69d079a51ccc5b9a7122e448701739109d0e72fd
@@ -360,7 +360,7 @@ private function _calculateWMCi(PHP_Depend_Code_Class $class)
while ($parent !== null) {
// Count all methods
foreach ($parent->getMethods() as $m) {
if (!$m->isPrivate() && !isset($methods[$m->getName()])) {
if (!$m->isPrivate() && !isset($ccn[$m->getName()])) {
$ccn[$m->getName()] = $this->_cyclomaticAnalyzer->getCCN2($m);
}
}
@@ -88,6 +88,7 @@
require_once dirname(__FILE__) . '/ExcludePathFilterShouldFilterByAbsolutePathBug191Test.php';
require_once dirname(__FILE__) . '/ParserBug8927377Test.php';
require_once dirname(__FILE__) . '/ClosureBug9634613Test.php';
require_once dirname(__FILE__) . '/ClassLevelAnalyzerBug09936901Test.php';
/**
* Test suite for bugs meta package.
@@ -154,6 +155,7 @@ public static function suite()
$suite->addTestSuite('PHP_Depend_Input_ExcludePathFilterShouldFilterByAbsolutePathBug191Test');
$suite->addTestSuite('PHP_Depend_Bugs_ParserBug8927377Test');
$suite->addTestSuite('PHP_Depend_Bugs_ClosureBug9634613Test');
$suite->addTestSuite('PHP_Depend_Bugs_ClassLevelAnalyzerBug09936901Test');
return $suite;
}
@@ -0,0 +1,93 @@
<?php
/**
* This file is part of PHP_Depend.
*
* PHP Version 5
*
* Copyright (c) 2008-2011, Manuel Pichler <mapi@pdepend.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Manuel Pichler nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category PHP
* @package PHP_Depend
* @subpackage Bugs
* @author Manuel Pichler <mapi@pdepend.org>
* @copyright 2008-2011 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version SVN: $Id$
* @link https://www.pivotaltracker.com/story/show/9936901
*/
require_once dirname(__FILE__) . '/AbstractTest.php';
/**
* Test case related to bug #9936901.
*
* @category PHP
* @package PHP_Depend
* @subpackage Bugs
* @author Manuel Pichler <mapi@pdepend.org>
* @copyright 2008-2011 Manuel Pichler. All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @version Release: @package_version@
* @link https://www.pivotaltracker.com/story/show/9936901
*
* @ticket 9936901
* @covers stdClass
* @group pdepend
* @group pdepend::bugs
* @group regressiontest
*/
class PHP_Depend_Bugs_ClassLevelAnalyzerBug09936901Test
extends PHP_Depend_Bugs_AbstractTest
{
/**
* testWmciMetricIsCalculatedForCurrentAndNotParentClass
*
* @return void
*/
public function testWmciMetricIsCalculatedForCurrentAndNotParentClass()
{
$packages = self::parseCodeResourceForTest();
$class = $packages->current()
->getClasses()
->current();
$analyzer = new PHP_Depend_Metrics_ClassLevel_Analyzer();
$analyzer->addAnalyzer(new PHP_Depend_Metrics_CyclomaticComplexity_Analyzer());
$analyzer->analyze($packages);
$metrics = $analyzer->getNodeMetrics($class);
self::assertEquals(2, $metrics['wmci']);
}
}
@@ -0,0 +1,28 @@
<?php
class testWmciMetricIsCalculatedForCurrentAndNotParentClass extends testWmciMetricIsCalculatedForCurrentAndNotParentClass_parent
{
public function foo()
{
return 42;
}
public function bar()
{
return 23;
}
}
class testWmciMetricIsCalculatedForCurrentAndNotParentClass_parent
{
public function bar()
{
for ($i = 0; $i < 23; ++$i) {
if ($i % 17 === 3) {
return $i;
} else if ($i % 13 === 11) {
return $i;
}
}
return 23;
}
}
@@ -7,7 +7,13 @@ public function c() {}
class B {
public $c;
private function a3() {}
protected function b2() {}
protected function b2() {
if (time() % 7 === 0) {
return 42;
} else if (time() % 5 === 0) {
return 23;
}
return 17;
}
public function c2() {}
}
?>
}
@@ -13,7 +13,14 @@ public function c() {}
class C {
public $c;
private function a3() {}
protected function b2() {}
protected function b2() {
if (time() % 7 === 0) {
return 42;
} else if (time() % 5 === 0) {
return 23;
}
return 17;
}
public function c2() {}
}
?>

0 comments on commit 69d079a

Please sign in to comment.