[BUGFIX] Respect newlines in method declarations
authorHelmut Hummel <helmut.hummel@typo3.org>
Thu, 18 Oct 2012 13:28:53 +0000 (15:28 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Thu, 18 Oct 2012 18:43:39 +0000 (20:43 +0200)
The compatibility class loader currently fails
to match method declarations that go over multiple
lines.

Add the /s modifier to the pattern and adjust the testcases.

Releases: 6.0
Resolves: #42134

Change-Id: I2671944a80608b9ac585f6b5c586ceb571b82ecb
Reviewed-on: http://review.typo3.org/15800
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Classes/Compatibility/CompatbilityClassLoaderPhpBelow50307.php
typo3/sysext/core/Tests/Unit/Core/ClassLoaderTest.php
typo3/sysext/core/Tests/Unit/Core/Fixtures/LegacyClassFixture.php

index 74a52d0..76f1808 100644 (file)
@@ -125,13 +125,13 @@ class CompatbilityClassLoaderPhpBelow50307 extends \TYPO3\CMS\Core\Core\ClassLoa
                        ini_set('pcre.backtrack_limit', $fileLength);
                }
                $fileContent = preg_replace_callback(
-                       '/function\s+([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\((.*?\$.*?)\)(\s*[{;])/im',
+                       '/function\s+([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\s*\((.*?\$.*?)\)(\s*[{;])/ims',
                        function($matches) use($classAliasMap) {
                        if (isset($matches[1]) && isset($matches[2])) {
                                list($functionName, $argumentList) = array_slice($matches, 1, 2);
                                $arguments = explode(',', $argumentList);
                                $arguments = array_map('trim', $arguments);
-                               $arguments = preg_replace_callback('/([\\a-z0-9_]+\s+)?((\s*[&]*\s*\$[a-z0-9_]+)(\s*=\s*.+)?)/im', function($argumentMatches) use($classAliasMap) {
+                               $arguments = preg_replace_callback('/([\\a-z0-9_]+\s+)?((\s*[&]*\s*\$[a-z0-9_]+)(\s*=\s*.+)?)/ims', function($argumentMatches) use($classAliasMap) {
                                        if (isset($argumentMatches[1]) && isset($argumentMatches[2])) {
                                                $typeHint = strtolower(ltrim(trim($argumentMatches[1]), '\\'));
                                                if (isset($classAliasMap[$typeHint])) {
index f4f8df9..5f2041d 100644 (file)
@@ -440,10 +440,12 @@ class ClassLoaderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $rewrittenContent = $classLoader->_call('rewriteMethodTypeHintsFromClassPath', $classPathOfFileToRewrite);
                $originalContent = file_get_contents($classPathOfFileToRewrite);
                $this->assertNotEquals($originalContent, $rewrittenContent);
-               $this->assertContains('public function foo(\TYPO3\CMS\Core\Utility\GeneralUtility $foo) {', $rewrittenContent);
-               $this->assertContains('abstract public function bar(\TYPO3\CMS\Core\Utility\GeneralUtility $bar);', $rewrittenContent);
-               $this->assertContains('public function nothing() {', $rewrittenContent);
-               $this->assertContains('protected function stillNothing(Tx_Core_Tests_Unit_Core_Fixtures_LegacyClassFixture $nothing) {', $rewrittenContent);
+               $this->assertContains('public function foo(\TYPO3\CMS\Core\Utility\GeneralUtility $foo) {', $rewrittenContent, 'One line and one parameter');
+               $this->assertContains('public function baz(\TYPO3\CMS\Core\Utility\GeneralUtility $foo, $baz) {', $rewrittenContent, 'Multi line and more parameters');
+               $this->assertContains('protected function createConstraintsFromDemand(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, Tx_News_Domain_Model_DemandInterface $demand);', $rewrittenContent, 'Multi line abstract and second parameter with own typehint not in aliasmap');
+               $this->assertContains('abstract public function bar(\TYPO3\CMS\Core\Utility\GeneralUtility $bar);', $rewrittenContent, 'One line abstract function');
+               $this->assertContains('public function nothing() {', $rewrittenContent, 'One line one parameter');
+               $this->assertContains('protected function stillNothing(Tx_Core_Tests_Unit_Core_Fixtures_LegacyClassFixture $nothing) {', $rewrittenContent, 'One line on parameter with typehint not in aliasmap');
        }
 }
 
index 298c521..35bc620 100644 (file)
  * @author Helmut Hummel <helmut.hummel@typo3.org>
  */
 abstract class Tx_Core_Tests_Unit_Core_Fixtures_LegacyClassFixture {
+
+       /**
+        * @param t3lib_div $foo
+        */
        public function foo(t3lib_div $foo) {
        }
+
+       /**
+        * @param t3lib_div $foo
+        * @param $baz
+        */
+       public function baz(t3lib_div $foo,
+                                               $baz) {
+       }
+
+       /**
+        * @param Tx_Extbase_Persistence_QueryInterface $query
+        * @param Tx_News_Domain_Model_DemandInterface $demand
+        */
+       abstract protected function createConstraintsFromDemand(Tx_Extbase_Persistence_QueryInterface $query,
+                                                                                                  Tx_News_Domain_Model_DemandInterface $demand);
+
+       /**
+        * @abstract
+        * @param t3lib_div $bar
+        * @return mixed
+        */
        abstract public function bar(t3lib_div $bar);
+
+       /**
+        *
+        */
        public function nothing() {
        }
+
+       /**
+        * @param Tx_Core_Tests_Unit_Core_Fixtures_LegacyClassFixture $nothing
+        */
        protected function stillNothing(Tx_Core_Tests_Unit_Core_Fixtures_LegacyClassFixture $nothing) {
        }
 }