Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'goto-statement-rule'

  • Loading branch information...
commit 2745a2082fccff7b35e0b797ec8b317eaad9c9ae 2 parents 659231f + 6679e3a
@manuelpichler manuelpichler authored
View
6 CHANGELOG
@@ -1,3 +1,9 @@
+phpmd-1.1.0 (2011/03/ )
+========================
+
+- Implemented #10474873: Add rule for PHP's goto statement. Implemented
+ with commit #.
+
phpmd-1.0.1 (2011/02/12)
========================
View
4 src/bin/phpmd.php
@@ -4,9 +4,9 @@
// PEAR installation workaround
if (strpos('@package_version@', '@package_version') === 0) {
set_include_path(
- dirname(__FILE__) . '/src/main/php' .
+ dirname(__FILE__) . '/../main/php' .
PATH_SEPARATOR .
- dirname(__FILE__) . '/lib/pdepend/src/main/php' .
+ dirname(__FILE__) . '/../../lib/pdepend/src/main/php' .
PATH_SEPARATOR .
'.'
);
View
87 src/main/php/PHP/PMD/Rule/Design/GotoStatement.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * This file is part of PHP_PMD.
+ *
+ * PHP Version 5
+ *
+ * Copyright (c) 2009-2011, Manuel Pichler <mapi@phpmd.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_PMD
+ * @subpackage Rule_Design
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-2011 Manuel Pichler. All rights reserved.
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id$
+ * @link http://phpmd.org
+ * @since 1.1.0
+ */
+
+require_once 'PHP/PMD/AbstractRule.php';
+require_once 'PHP/PMD/Rule/IMethodAware.php';
+require_once 'PHP/PMD/Rule/IFunctionAware.php';
+
+/**
+ * This rule class detects the usage of PHP's goto statement.
+ *
+ * @category PHP
+ * @package PHP_PMD
+ * @subpackage Rule_Design
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-2011 Manuel Pichler. All rights reserved.
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: @package_version@
+ * @link http://phpmd.org
+ * @since 1.1.0
+ */
+class PHP_PMD_Rule_Design_GotoStatement
+ extends PHP_PMD_AbstractRule
+ implements PHP_PMD_Rule_IMethodAware,
+ PHP_PMD_Rule_IFunctionAware
+{
+ /**
+ * This method should implement the violation analysis algorithm of concrete
+ * rule implementations. All extending classes must implement this method.
+ *
+ * @param PHP_PMD_AbstractNode $node The current context for analysis.
+ *
+ * @return void
+ */
+ public function apply(PHP_PMD_AbstractNode $node)
+ {
+ foreach ($node->findChildrenOfType('GotoStatement') as $exit) {
+ $this->addViolation($exit, array($node->getType(), $node->getName()));
+ }
+ }
+
+}
View
47 src/main/resources/rulesets/design.xml
@@ -14,7 +14,7 @@ The Code Size Ruleset contains a collection of rules that find software design r
since="0.2"
message = "The {0} {1}() contains an exit expression."
class="PHP_PMD_Rule_Design_ExitExpression"
- externalInfoUrl="http://phpmd.org/rules/codesize.html#exitexpression">
+ externalInfoUrl="http://phpmd.org/rules/design.html#exitexpression">
<description>
<![CDATA[
An exit-expression within regular code is untestable and therefore it should
@@ -41,7 +41,7 @@ class Foo {
since="0.2"
message = "The {0} {1}() contains an eval expression."
class="PHP_PMD_Rule_Design_EvalExpression"
- externalInfoUrl="http://phpmd.org/rules/codesize.html#evalexpression">
+ externalInfoUrl="http://phpmd.org/rules/design.html#evalexpression">
<description>
<![CDATA[
An eval-expression is untestable, a security risk and bad practice. Therefore
@@ -64,11 +64,50 @@ class Foo {
</example>
</rule>
+ <rule name="GotoStatement"
+ since="1.1.0"
+ message="The {0} {1}() utilizes a goto statement."
+ class="PHP_PMD_Rule_Design_GotoStatement"
+ externalInfoUrl="http://phpmd.org/rules/design.html#gotostatement">
+ <description>
+ <![CDATA[
+Goto makes code harder to read and it is nearly impossible to understand the
+control flow of an application that uses this language construct. Therefore it
+should be avoided. Consider to replace Goto with regular control structures and
+separate methods/function, which are easier to read.
+ ]]>
+ </description>
+ <priority>1</priority>
+ <properties />
+ <example>
+ <![CDATA[
+class Foo {
+ public function bar($param) {
+ A:
+ if ($param === 42) {
+ goto X;
+ }
+ Y:
+ if (time() % 42 === 23) {
+ goto Z;
+ }
+ X:
+ if (time() % 23 === 42) {
+ goto Y;
+ }
+ Z:
+ return 42;
+ }
+}
+ ]]>
+ </example>
+ </rule>
+
<rule name="NumberOfChildren"
since="0.2"
message = "The class {0} has {1} children. Consider to rebalance this class hierarchy."
class="PHP_PMD_Rule_Design_NumberOfChildren"
- externalInfoUrl="http://phpmd.org/rules/codesize.html#numberofchildren">
+ externalInfoUrl="http://phpmd.org/rules/design.html#numberofchildren">
<description>
<![CDATA[
A class with an excessive number of children is an indicator for an unbalanced
@@ -86,7 +125,7 @@ class hierarchy. You should consider to refactor this class hierarchy.
since="0.2"
message = "The class {0} has {1} parents. Consider to reduce the depth of this class hierarchy."
class="PHP_PMD_Rule_Design_DepthOfInheritance"
- externalInfoUrl="http://phpmd.org/rules/codesize.html#depthofinheritance">
+ externalInfoUrl="http://phpmd.org/rules/design.html#depthofinheritance">
<description>
<![CDATA[
A class with many parents is an indicator for an unbalanced and wrong class
View
22 src/test/php/PHP/PMD/AbstractTest.php
@@ -176,12 +176,12 @@ protected function getFunction()
}
/**
- * Parses the source code for the calling test method and returns the first
- * package node found in the parsed file.
+ * Returns the absolute path for a test resource for the current test.
*
- * @return PHP_Depend_Code_Package
+ * @return string
+ * @since 1.1.0
*/
- private function _parseTestCaseSource()
+ protected function createCodeResourceUriForTest()
{
$frame = $this->_getCallingTestCase();
@@ -191,13 +191,23 @@ private function _parseTestCaseSource()
$localPath = strtr(substr($frame['class'], 8, -4), '_', '/');
}
- $sourceFile = sprintf(
+ return sprintf(
'%s/../../../resources/files/%s/%s.php',
dirname(__FILE__),
$localPath,
$frame['function']
);
- return $this->_parseSource($sourceFile);
+ }
+
+ /**
+ * Parses the source code for the calling test method and returns the first
+ * package node found in the parsed file.
+ *
+ * @return PHP_Depend_Code_Package
+ */
+ private function _parseTestCaseSource()
+ {
+ return $this->_parseSource($this->createCodeResourceUriForTest());
}
/**
View
2  src/test/php/PHP/PMD/AllTests.php
@@ -55,6 +55,7 @@
require_once dirname(__FILE__) . '/RuleSetTest.php';
require_once dirname(__FILE__) . '/RuleTest.php';
require_once dirname(__FILE__) . '/RuleViolationTest.php';
+require_once dirname(__FILE__) . '/Integration/AllTests.php';
require_once dirname(__FILE__) . '/Node/AllTests.php';
require_once dirname(__FILE__) . '/Regression/AllTests.php';
require_once dirname(__FILE__) . '/Renderer/AllTests.php';
@@ -92,6 +93,7 @@ public static function suite()
$suite->addTestSuite('PHP_PMD_RuleTest');
$suite->addTestSuite('PHP_PMD_RuleViolationTest');
+ $suite->addTest(PHP_PMD_Integration_AllTests::suite());
$suite->addTest(PHP_PMD_Node_AllTests::suite());
$suite->addTest(PHP_PMD_Regression_AllTests::suite());
$suite->addTest(PHP_PMD_Renderer_AllTests::suite());
View
88 src/test/php/PHP/PMD/Integration/AllTests.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * This file is part of PHP_PMD.
+ *
+ * PHP Version 5
+ *
+ * Copyright (c) 2009-2011, Manuel Pichler <mapi@phpmd.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_PMD
+ * @subpackage Integration
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-2011 Manuel Pichler. All rights reserved.
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id$
+ * @link http://phpmd.org
+ * @since 1.1.0
+ */
+
+require_once 'PHPUnit/Framework/TestSuite.php';
+
+require_once dirname(__FILE__) . '/GotoStatementIntegrationTest.php';
+
+/**
+ * Main test suite for all PHP_PMD integration tests
+ *
+ * @category PHP
+ * @package PHP_PMD
+ * @subpackage Integration
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-2011 Manuel Pichler. All rights reserved.
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: @package_version@
+ * @link http://phpmd.org
+ * @since 1.1.0
+ */
+class PHP_PMD_Integration_AllTests extends PHPUnit_Framework_TestSuite
+{
+ /**
+ * Constructs a new test suite instance.
+ */
+ public function __construct()
+ {
+ parent::__construct('PHP_PMD_Integration - Tests');
+
+ $this->addTestSuite('PHP_PMD_Integration_GotoStatementIntegrationTest');
+ }
+
+ /**
+ * Creates a phpunit test suite.
+ *
+ * @return PHPUnit_Framework_TestSuite
+ */
+ public static function suite()
+ {
+ return new self();
+ }
+}
View
96 src/test/php/PHP/PMD/Integration/GotoStatementIntegrationTest.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * This file is part of PHP_PMD.
+ *
+ * PHP Version 5
+ *
+ * Copyright (c) 2009-2011, Manuel Pichler <mapi@phpmd.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_PMD
+ * @subpackage Integration
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-2011 Manuel Pichler. All rights reserved.
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version SVN: $Id$
+ * @link http://phpmd.org
+ * @since 1.1.0
+ */
+
+require_once dirname(__FILE__) . '/../AbstractTest.php';
+
+require_once 'PHP/PMD/TextUI/Command.php';
+
+/**
+ * Test case for the goto statement GotoStatementIntegrationTest.
+ *
+ * @category PHP
+ * @package PHP_PMD
+ * @subpackage Integration
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-2011 Manuel Pichler. All rights reserved.
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version Release: @package_version@
+ * @link http://phpmd.org
+ * @since 1.1.0
+ *
+ * @group phpmd
+ * @group phpmd::integration
+ * @group integrationtest
+ */
+class PHP_PMD_Integration_GotoStatementIntegrationTest extends PHP_PMD_AbstractTest
+{
+ /**
+ * testReportContainsGotoStatementWarning
+ *
+ * @return void
+ * @outputBuffering enabled
+ */
+ public function testReportContainsGotoStatementWarning()
+ {
+ $file = self::createTempFileUri();
+
+ PHP_PMD_TextUI_Command::main(
+ array(
+ __FILE__,
+ $this->createCodeResourceUriForTest(),
+ 'text',
+ 'design',
+ '--reportfile',
+ $file
+ )
+ );
+
+ self::assertContains('utilizes a goto statement.', file_get_contents($file));
+ }
+}
View
2  src/test/php/PHP/PMD/Rule/Design/AllTests.php
@@ -51,6 +51,7 @@
require_once dirname(__FILE__) . '/DepthOfInheritanceTest.php';
require_once dirname(__FILE__) . '/EvalExpressionTest.php';
require_once dirname(__FILE__) . '/ExitExpressionTest.php';
+require_once dirname(__FILE__) . '/GotoStatementTest.php';
require_once dirname(__FILE__) . '/LongClassTest.php';
require_once dirname(__FILE__) . '/LongMethodTest.php';
require_once dirname(__FILE__) . '/LongParameterListTest.php';
@@ -86,6 +87,7 @@ public static function suite()
$suite->addTestSuite('PHP_PMD_Rule_Design_DepthOfInheritanceTest');
$suite->addTestSuite('PHP_PMD_Rule_Design_EvalExpressionTest');
$suite->addTestSuite('PHP_PMD_Rule_Design_ExitExpressionTest');
+ $suite->addTestSuite('PHP_PMD_Rule_Design_GotoStatementTest');
$suite->addTestSuite('PHP_PMD_Rule_Design_LongClassTest');
$suite->addTestSuite('PHP_PMD_Rule_Design_LongMethodTest');
$suite->addTestSuite('PHP_PMD_Rule_Design_LongParameterListTest');
View
122 src/test/php/PHP/PMD/Rule/Design/GotoStatementTest.php
@@ -0,0 +1,122 @@
+<?php
+/**
+ * This file is part of PHP_PMD.
+ *
+ * PHP Version 5
+ *
+ * Copyright (c) 2009-2011, Manuel Pichler <mapi@phpmd.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_PMD
+ * @subpackage Rule_Design
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-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/10474873
+ * @ticket 10474873
+ */
+
+require_once dirname(__FILE__) . '/../../AbstractTest.php';
+
+require_once 'PHP/PMD/Rule/Design/GotoStatement.php';
+
+/**
+ * Test case for the {@link PHP_PMD_Rule_Design_GotoStatement} class.
+ *
+ * @category PHP
+ * @package PHP_PMD
+ * @subpackage Rule_Design
+ * @author Manuel Pichler <mapi@phpmd.org>
+ * @copyright 2009-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/10474873
+ * @ticket 10474873
+ *
+ * @covers PHP_PMD_Rule_Design_GotoStatement
+ * @group phpmd
+ * @group phpmd::rule
+ * @group phpmd::rule::design
+ * @group unittest
+ */
+class PHP_PMD_Rule_Design_GotoStatementTest extends PHP_PMD_AbstractTest
+{
+ /**
+ * testRuleNotAppliesToMethodWithoutGotoStatement
+ *
+ * @return void
+ */
+ public function testRuleNotAppliesToMethodWithoutGotoStatement()
+ {
+ $rule = new PHP_PMD_Rule_Design_GotoStatement();
+ $rule->setReport($this->getReportMock(0));
+ $rule->apply($this->getMethod());
+ }
+
+ /**
+ * testRuleAppliesToMethodWithGotoStatement
+ *
+ * @return void
+ */
+ public function testRuleAppliesToMethodWithGotoStatement()
+ {
+ $rule = new PHP_PMD_Rule_Design_GotoStatement();
+ $rule->setReport($this->getReportMock(1));
+ $rule->apply($this->getMethod());
+ }
+
+ /**
+ * testRuleNotAppliesToFunctionWithoutGotoStatement
+ *
+ * @return void
+ */
+ public function testRuleNotAppliesToFunctionWithoutGotoStatement()
+ {
+ $rule = new PHP_PMD_Rule_Design_GotoStatement();
+ $rule->setReport($this->getReportMock(0));
+ $rule->apply($this->getFunction());
+ }
+
+ /**
+ * testRuleAppliesToFunctionWithGotoStatement
+ *
+ * @return void
+ */
+ public function testRuleAppliesToFunctionWithGotoStatement()
+ {
+ $rule = new PHP_PMD_Rule_Design_GotoStatement();
+ $rule->setReport($this->getReportMock(1));
+ $rule->apply($this->getFunction());
+ }
+}
View
10 src/test/resources/files/Integration/GotoStatementIntegration/testReportContainsGotoStatementWarning.php
@@ -0,0 +1,10 @@
+<?php
+function testReportContainsGotoStatementWarning()
+{
+ LABEL:
+ echo 'You goto ' . __LINE__;
+
+ if (time() % 42 === 23) {
+ goto LABEL;
+ }
+}
View
10 src/test/resources/files/Rule/Design/GotoStatement/testRuleAppliesToFunctionWithGotoStatement.php
@@ -0,0 +1,10 @@
+<?php
+function testRuleAppliesToFunctionWithGotoStatement()
+{
+ LABEL:
+ echo 'FOOBAR';
+
+ if (time() % 23 === 42) {
+ goto LABEL;
+ }
+}
View
13 src/test/resources/files/Rule/Design/GotoStatement/testRuleAppliesToMethodWithGotoStatement.php
@@ -0,0 +1,13 @@
+<?php
+class testRuleAppliesToMethodWithGotoStatementClass
+{
+ public function testRuleAppliesToMethodWithGotoStatement()
+ {
+ LABEL:
+ echo 'YES';
+
+ if (time() % 42 === 0) {
+ goto LABEL;
+ }
+ }
+}
View
5 src/test/resources/files/Rule/Design/GotoStatement/testRuleNotAppliesToFunctionWithoutGotoStatement.php
@@ -0,0 +1,5 @@
+<?php
+function testRuleNotAppliesToFunctionWithoutGotoStatement($foo)
+{
+ return 42 * $foo;
+}
View
8 src/test/resources/files/Rule/Design/GotoStatement/testRuleNotAppliesToMethodWithoutGotoStatement.php
@@ -0,0 +1,8 @@
+<?php
+class testRuleNotAppliesToMethodWithoutGotoStatementClass
+{
+ public function testRuleNotAppliesToMethodWithoutGotoStatement($foo)
+ {
+ return $foo;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.