From 0ca1ba32116574401e1a9ba990ad015b83656e5c Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 26 Jun 2013 02:20:31 +0200 Subject: [PATCH 01/16] allow callbacks to modify attachements by moving the decision to calculate boundary value into the correct position inside _render() --- lib/Cake/Network/Email/CakeEmail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index a43f10f32..dc1069e41 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1071,7 +1071,6 @@ class CakeEmail { } $this->_textMessage = $this->_htmlMessage = ''; - $this->_createBoundary(); $this->_message = $this->_render($this->_wrap($content)); $contents = $this->transportClass()->send($this); @@ -1447,6 +1446,7 @@ class CakeEmail { $content = implode("\n", $content); $rendered = $this->_renderTemplates($content); + $this->_createBoundary(); $msg = array(); $contentIds = array_filter((array)Hash::extract($this->_attachments, '{s}.contentId')); From b346c4af8e0f927e80e6166a33e402d0f703ee37 Mon Sep 17 00:00:00 2001 From: euromark Date: Sat, 29 Jun 2013 15:16:58 +0200 Subject: [PATCH 02/16] Test to proof that render itself should handle the boundary. --- .../Test/Case/Network/Email/CakeEmailTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 85b9b19b4..a3ace7759 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -65,6 +65,14 @@ class TestCakeEmail extends CakeEmail { return $this->_encode($text); } +/** + * Render to protected method + * + */ + public function render($content) { + return $this->_render($content); + } + } /* @@ -1484,6 +1492,22 @@ class CakeEmailTest extends CakeTestCase { $this->assertSame($expected, $result); } +/** + * testRender method + * + * @return void + */ + public function testRenderWithLayoutAndAttachment() { + $this->CakeEmail->emailFormat('html'); + $this->CakeEmail->template('html', 'default'); + $this->CakeEmail->attachments(array(CAKE . 'basics.php')); + $result = $this->CakeEmail->render(array()); + $this->assertNotEmpty($result); + + $result = $this->CakeEmail->getBoundary(); + $this->assertNotEmpty($result); + } + /** * testConstructWithConfigArray method * From c94fe1b7299fe974b50754e3cae462556c813a20 Mon Sep 17 00:00:00 2001 From: euromark Date: Sat, 29 Jun 2013 16:23:55 +0200 Subject: [PATCH 03/16] also move protected variable resetting into the correct scope --- lib/Cake/Network/Email/CakeEmail.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index dc1069e41..eb2f07fc2 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1070,7 +1070,6 @@ class CakeEmail { $content = implode("\n", $content) . "\n"; } - $this->_textMessage = $this->_htmlMessage = ''; $this->_message = $this->_render($this->_wrap($content)); $contents = $this->transportClass()->send($this); @@ -1443,6 +1442,8 @@ class CakeEmail { * @return array Email body ready to be sent */ protected function _render($content) { + $this->_textMessage = $this->_htmlMessage = ''; + $content = implode("\n", $content); $rendered = $this->_renderTemplates($content); From f930a50805a03ae36b928421873d361f51f2703d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=BCrth?= Date: Wed, 26 Jun 2013 13:36:50 +0200 Subject: [PATCH 04/16] Fix for #3318 Fixes https://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/3318 It seems fixing this in the htaccess file(s) isn't going to work even though a url rewriting based solution was more clean. On the plus side this works for any web server. If a url is called with "index.php" in it then the CakeRequest swallows this part and fixes the path. Any linked url from the requested page will have a clean url. Thus after following one of these urls this problem is gone anyway. Some code docblock improvements to CakeRequestTest.php Added test case for fix Also now you can call just index.php even if you have url rewriting enabled --- lib/Cake/Network/CakeRequest.php | 17 +- .../Test/Case/Network/CakeRequestTest.php | 169 +++++++++++++----- 2 files changed, 139 insertions(+), 47 deletions(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 16871ad39..f7d745f82 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -257,7 +257,12 @@ class CakeRequest implements ArrayAccess { list($uri) = explode('?', $uri, 2); } if (empty($uri) || $uri === '/' || $uri === '//' || $uri === '/index.php') { - return '/'; + $uri = '/'; + } + $endsWithIndex = '/webroot/index.php'; + $endsWithLength = strlen($endsWithIndex); + if (strlen($uri) >= $endsWithLength && substr_compare($uri, $endsWithIndex, -$endsWithLength, $endsWithLength) === 0) { + $uri = '/'; } return $uri; } @@ -265,7 +270,12 @@ class CakeRequest implements ArrayAccess { /** * Returns a base URL and sets the proper webroot * + * If CakePHP is called with index.php in the URL even though + * URL Rewriting is activated (and thus not needed) it swallows + * the unnecessary part from $base to prevent issue #3318. + * * @return string Base URL + * @link https://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/3318 */ protected function _base() { $dir = $webroot = null; @@ -283,6 +293,10 @@ class CakeRequest implements ArrayAccess { if (!$baseUrl) { $base = dirname(env('PHP_SELF')); + $indexPos = strpos($base, '/webroot/index.php'); + if ($indexPos !== false) { + $base = substr($base, 0, $indexPos) . '/webroot'; + } if ($webroot === 'webroot' && $webroot === basename($base)) { $base = dirname($base); } @@ -295,6 +309,7 @@ class CakeRequest implements ArrayAccess { } $base = implode('/', array_map('rawurlencode', explode('/', $base))); $this->webroot = $base . '/'; + return $this->base = $base; } diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index a96bdbb7b..8bdf6b564 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -29,6 +29,12 @@ App::uses('CakeRequest', 'Network'); */ class TestCakeRequest extends CakeRequest { +/** + * reConstruct method + * + * @param string $url + * @param bool $parseEnvironment + */ public function reConstruct($url = 'some/path', $parseEnvironment = true) { $this->_base(); if (empty($url)) { @@ -49,10 +55,13 @@ class TestCakeRequest extends CakeRequest { } +/** + * Class CakeRequestTest + */ class CakeRequestTest extends CakeTestCase { /** - * setup callback + * Setup callback * * @return void */ @@ -69,7 +78,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * tearDown + * TearDown * * @return void */ @@ -82,7 +91,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test that the autoparse = false constructor works. + * Test that the autoparse = false constructor works. * * @return void */ @@ -95,7 +104,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test construction + * Test construction * * @return void */ @@ -153,7 +162,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test addParams() method + * Test addParams() method * * @return void */ @@ -170,7 +179,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test splicing in paths. + * Test splicing in paths. * * @return void */ @@ -190,7 +199,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test parsing POST data into the object. + * Test parsing POST data into the object. * * @return void */ @@ -241,7 +250,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test parsing PUT data into the object. + * Test parsing PUT data into the object. * * @return void */ @@ -315,7 +324,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test parsing json PUT data into the object. + * Test parsing json PUT data into the object. * * @return void */ @@ -332,7 +341,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test parsing of FILES array + * Test parsing of FILES array * * @return void */ @@ -621,7 +630,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test method overrides coming in from POST data. + * Test method overrides coming in from POST data. * * @return void */ @@ -640,7 +649,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test the clientIp method. + * Test the clientIp method. * * @return void */ @@ -663,7 +672,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test the referer function. + * Test the referrer function. * * @return void */ @@ -748,7 +757,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test the method() method. + * Test the method() method. * * @return void */ @@ -760,7 +769,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test host retrieval. + * Test host retrieval. * * @return void */ @@ -772,7 +781,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test domain retrieval. + * Test domain retrieval. * * @return void */ @@ -787,7 +796,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test getting subdomains for a host. + * Test getting subdomains for a host. * * @return void */ @@ -808,7 +817,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test ajax, flash and friends + * Test ajax, flash and friends * * @return void */ @@ -842,7 +851,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test __call expcetions + * Test __call exceptions * * @expectedException CakeException * @return void @@ -853,7 +862,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test is(ssl) + * Test is(ssl) * * @return void */ @@ -886,7 +895,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test getting request params with object properties. + * Test getting request params with object properties. * * @return void */ @@ -921,7 +930,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test the array access implementation + * Test the array access implementation * * @return void */ @@ -952,7 +961,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test adding detectors and having them work. + * Test adding detectors and having them work. * * @return void */ @@ -1009,16 +1018,17 @@ class CakeRequestTest extends CakeTestCase { } /** - * helper function for testing callbacks. + * Helper function for testing callbacks. * - * @return void + * @param $request + * @return bool */ public function detectCallback($request) { return (bool)$request->return; } /** - * test getting headers + * Test getting headers * * @return void */ @@ -1032,7 +1042,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test accepts() with and without parameters + * Test accepts() with and without parameters * * @return void */ @@ -1117,7 +1127,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * testBaseUrlAndWebrootWithModRewrite method + * Test baseUrl and webroot with ModRewrite * * @return void */ @@ -1186,7 +1196,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * testBaseUrlwithModRewriteAlias method + * Test baseUrl with ModRewrite alias * * @return void */ @@ -1214,7 +1224,71 @@ class CakeRequestTest extends CakeTestCase { } /** - * test base, webroot, and url parsing when there is no url rewriting + * Test base, webroot, url and here parsing when there is url rewriting but + * CakePHP gets called with index.php in url nonetheless. + * + * Tests uri with + * - index.php/ + * - index.php/ + * - index.php/apples/ + * - index.php/bananas/eat/tasty_banana + * + * @link https://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/3318 + */ + public function testBaseUrlWithModRewriteAndIndexPhp() { + $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php'; + unset($_SERVER['PATH_INFO']); + $request = new CakeRequest(); + + $this->assertEquals('/cakephp', $request->base); + $this->assertEquals('/cakephp/', $request->webroot); + $this->assertEquals('', $request->url); + $this->assertEquals('/cakephp/', $request->here); + + $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php/'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/'; + $_SERVER['PATH_INFO'] = '/'; + $request = new CakeRequest(); + + $this->assertEquals('/cakephp', $request->base); + $this->assertEquals('/cakephp/', $request->webroot); + $this->assertEquals('', $request->url); + $this->assertEquals('/cakephp/', $request->here); + + $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php/apples'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/apples'; + $_SERVER['PATH_INFO'] = '/apples'; + $request = new CakeRequest(); + + $this->assertEquals('/cakephp', $request->base); + $this->assertEquals('/cakephp/', $request->webroot); + $this->assertEquals('apples', $request->url); + $this->assertEquals('/cakephp/apples', $request->here); + + $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php/melons/share/'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/melons/share/'; + $_SERVER['PATH_INFO'] = '/melons/share/'; + $request = new CakeRequest(); + + $this->assertEquals('/cakephp', $request->base); + $this->assertEquals('/cakephp/', $request->webroot); + $this->assertEquals('melons/share/', $request->url); + $this->assertEquals('/cakephp/melons/share/', $request->here); + + $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php/bananas/eat/tasty_banana'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/bananas/eat/tasty_banana'; + $_SERVER['PATH_INFO'] = '/bananas/eat/tasty_banana'; + $request = new CakeRequest(); + + $this->assertEquals('/cakephp', $request->base); + $this->assertEquals('/cakephp/', $request->webroot); + $this->assertEquals('bananas/eat/tasty_banana', $request->url); + $this->assertEquals('/cakephp/bananas/eat/tasty_banana', $request->here); + } + +/** + * Test base, webroot, and url parsing when there is no url rewriting * * @return void */ @@ -1237,8 +1311,8 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals('posts/index', $request->url); } -/** - * testBaseUrlAndWebrootWithBaseUrl method + /** + * Test baseUrl and webroot with baseUrl * * @return void */ @@ -1287,7 +1361,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test baseUrl with no rewrite and using the top level index.php. + * Test baseUrl with no rewrite and using the top level index.php. * * @return void */ @@ -1325,7 +1399,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts. + * Test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts. * * @return void */ @@ -1371,9 +1445,9 @@ class CakeRequestTest extends CakeTestCase { } /** - * generator for environment configurations + * Generator for environment configurations * - * @return void + * @return array Environment array */ public static function environmentGenerator() { return array( @@ -1745,9 +1819,12 @@ class CakeRequestTest extends CakeTestCase { } /** - * testEnvironmentDetection method + * Test environment detection * * @dataProvider environmentGenerator + * @param $name + * @param $env + * @param $expected * @return void */ public function testEnvironmentDetection($name, $env, $expected) { @@ -1764,7 +1841,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test the query() method + * Test the query() method * * @return void */ @@ -1782,7 +1859,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test the query() method with arrays passed via $_GET + * Test the query() method with arrays passed via $_GET * * @return void */ @@ -1803,7 +1880,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test the data() method reading + * Test the data() method reading * * @return void */ @@ -1822,7 +1899,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test writing with data() + * Test writing with data() * * @return void */ @@ -1844,7 +1921,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test writing falsey values. + * Test writing falsey values. * * @return void */ @@ -1865,7 +1942,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test accept language + * Test accept language * * @return void */ @@ -1908,7 +1985,7 @@ class CakeRequestTest extends CakeTestCase { } /** - * test the here() method + * Test the here() method * * @return void */ @@ -2011,7 +2088,7 @@ XML; } /** - * TestOnlyAllow + * Test onlyAllow method * * @return void */ @@ -2026,7 +2103,7 @@ XML; } /** - * TestOnlyAllow throwing exception + * Test onlyAllow throwing exception * */ public function testOnlyAllowException() { From e84bf6501602215989a2ed5fcb68d95e9a72122e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=BCrth?= Date: Mon, 1 Jul 2013 00:03:03 +0200 Subject: [PATCH 05/16] Typo in FormAuthenticate.php --- lib/Cake/Controller/Component/Auth/FormAuthenticate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Controller/Component/Auth/FormAuthenticate.php b/lib/Cake/Controller/Component/Auth/FormAuthenticate.php index 78e5cbbc4..d1da01f27 100644 --- a/lib/Cake/Controller/Component/Auth/FormAuthenticate.php +++ b/lib/Cake/Controller/Component/Auth/FormAuthenticate.php @@ -61,7 +61,7 @@ class FormAuthenticate extends BaseAuthenticate { /** * Authenticates the identity contained in a request. Will use the `settings.userModel`, and `settings.fields` * to find POST data that is used to find a matching record in the `settings.userModel`. Will return false if - * there is no post data, either username or password is missing, of if the scope conditions have not been met. + * there is no post data, either username or password is missing, or if the scope conditions have not been met. * * @param CakeRequest $request The request that contains login information. * @param CakeResponse $response Unused response object. From dad1f16eaf1c9e83459e35f6286b0c53c8185e9d Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Mon, 1 Jul 2013 14:15:54 +0200 Subject: [PATCH 06/16] Made _stop() usage in Consoles / Tasks more consistent --- lib/Cake/Console/Command/AclShell.php | 2 +- lib/Cake/Console/Command/ApiShell.php | 2 +- lib/Cake/Console/Command/SchemaShell.php | 20 +++++++++---------- .../Console/Command/Task/ControllerTask.php | 2 +- .../Console/Command/Task/DbConfigTask.php | 2 +- lib/Cake/Console/Command/Task/ExtractTask.php | 2 +- lib/Cake/Console/Command/Task/ModelTask.php | 4 ++-- lib/Cake/Console/Command/Task/ProjectTask.php | 2 +- lib/Cake/Console/Command/Task/ViewTask.php | 4 ++-- lib/Cake/Console/ConsoleErrorHandler.php | 4 ++-- lib/Cake/Console/Shell.php | 6 +++--- lib/Cake/Console/ShellDispatcher.php | 2 +- 12 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/Cake/Console/Command/AclShell.php b/lib/Cake/Console/Command/AclShell.php index 364947e79..081eaf349 100644 --- a/lib/Cake/Console/Command/AclShell.php +++ b/lib/Cake/Console/Command/AclShell.php @@ -82,7 +82,7 @@ class AclShell extends AppShell { $out .= __d('cake_console', 'Current ACL Classname: %s', $class) . "\n"; $out .= "--------------------------------------------------\n"; $this->err($out); - $this->_stop(); + return $this->_stop(); } if ($this->command) { diff --git a/lib/Cake/Console/Command/ApiShell.php b/lib/Cake/Console/Command/ApiShell.php index 584d24638..200b67b8b 100644 --- a/lib/Cake/Console/Command/ApiShell.php +++ b/lib/Cake/Console/Command/ApiShell.php @@ -100,7 +100,7 @@ class ApiShell extends AppShell { if (isset($this->params['method'])) { if (!isset($parsed[$this->params['method']])) { $this->err(__d('cake_console', '%s::%s() could not be found', $class, $this->params['method'])); - $this->_stop(); + return $this->_stop(); } $method = $parsed[$this->params['method']]; $this->out($class . '::' . $method['method'] . $method['parameters']); diff --git a/lib/Cake/Console/Command/SchemaShell.php b/lib/Cake/Console/Command/SchemaShell.php index db069fa74..90acff90e 100644 --- a/lib/Cake/Console/Command/SchemaShell.php +++ b/lib/Cake/Console/Command/SchemaShell.php @@ -106,11 +106,11 @@ class SchemaShell extends AppShell { $File = new File($this->Schema->path . DS . $this->params['file']); if ($File->exists()) { $this->out($File->read()); - $this->_stop(); + return $this->_stop(); } else { $file = $this->Schema->path . DS . $this->params['file']; $this->err(__d('cake_console', 'Schema file (%s) could not be found.', $file)); - $this->_stop(); + return $this->_stop(); } } @@ -184,10 +184,10 @@ class SchemaShell extends AppShell { if ($this->Schema->write($content)) { $this->out(__d('cake_console', 'Schema file: %s generated', $content['file'])); - $this->_stop(); + return $this->_stop(); } else { $this->err(__d('cake_console', 'Schema file: %s generated')); - $this->_stop(); + return $this->_stop(); } } @@ -205,7 +205,7 @@ class SchemaShell extends AppShell { $Schema = $this->Schema->load(); if (!$Schema) { $this->err(__d('cake_console', 'Schema could not be loaded')); - $this->_stop(); + return $this->_stop(); } if (!empty($this->params['write'])) { if ($this->params['write'] == 1) { @@ -229,10 +229,10 @@ class SchemaShell extends AppShell { if ($File->write($contents)) { $this->out(__d('cake_console', 'SQL dump file created in %s', $File->pwd())); - $this->_stop(); + return $this->_stop(); } else { $this->err(__d('cake_console', 'SQL dump could not be created')); - $this->_stop(); + return $this->_stop(); } } $this->out($contents); @@ -290,7 +290,7 @@ class SchemaShell extends AppShell { $this->err(__d('cake_console', 'The chosen schema could not be loaded. Attempted to load:')); $this->err(__d('cake_console', 'File: %s', $this->Schema->path . DS . $this->Schema->file)); $this->err(__d('cake_console', 'Name: %s', $this->Schema->name)); - $this->_stop(); + return $this->_stop(); } $table = null; if (isset($this->args[1])) { @@ -323,7 +323,7 @@ class SchemaShell extends AppShell { } if (empty($drop) || empty($create)) { $this->out(__d('cake_console', 'Schema is up to date.')); - $this->_stop(); + return $this->_stop(); } $this->out("\n" . __d('cake_console', 'The following table(s) will be dropped.')); @@ -375,7 +375,7 @@ class SchemaShell extends AppShell { if (empty($contents)) { $this->out(__d('cake_console', 'Schema is up to date.')); - $this->_stop(); + return $this->_stop(); } $this->out("\n" . __d('cake_console', 'The following statements will run.')); diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index 4c59b498b..cd401c487 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -289,7 +289,7 @@ class ControllerTask extends BakeTask { App::uses($modelImport, $plugin . 'Model'); if (!class_exists($modelImport)) { $this->err(__d('cake_console', 'You must have a model for this class to build basic methods. Please try again.')); - $this->_stop(); + return $this->_stop(); } $modelObj = ClassRegistry::init($currentModelName); diff --git a/lib/Cake/Console/Command/Task/DbConfigTask.php b/lib/Cake/Console/Command/Task/DbConfigTask.php index 55076d5fc..d0e4572ac 100644 --- a/lib/Cake/Console/Command/Task/DbConfigTask.php +++ b/lib/Cake/Console/Command/Task/DbConfigTask.php @@ -77,7 +77,7 @@ class DbConfigTask extends AppShell { public function execute() { if (empty($this->args)) { $this->_interactive(); - $this->_stop(); + return $this->_stop(); } } diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index c9fece3f3..4648c1e47 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -207,7 +207,7 @@ class ExtractTask extends AppShell { $response = $this->in($message, null, rtrim($this->_paths[0], DS) . DS . 'Locale'); if (strtoupper($response) === 'Q') { $this->out(__d('cake_console', 'Extract Aborted')); - $this->_stop(); + return $this->_stop(); } elseif ($this->_isPathUsable($response)) { $this->_output = $response . DS; break; diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index d2232b188..0ff102454 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -911,7 +911,7 @@ class ModelTask extends BakeTask { } if (empty($tables)) { $this->err(__d('cake_console', 'Your database does not have any tables.')); - $this->_stop(); + return $this->_stop(); } return $tables; } @@ -933,7 +933,7 @@ class ModelTask extends BakeTask { if ($enteredModel === 'q') { $this->out(__d('cake_console', 'Exit')); - $this->_stop(); + return $this->_stop(); } if (!$enteredModel || intval($enteredModel) > count($this->_modelNames)) { diff --git a/lib/Cake/Console/Command/Task/ProjectTask.php b/lib/Cake/Console/Command/Task/ProjectTask.php index 58fa4e4e4..cc63d0846 100644 --- a/lib/Cake/Console/Command/Task/ProjectTask.php +++ b/lib/Cake/Console/Command/Task/ProjectTask.php @@ -417,7 +417,7 @@ class ProjectTask extends AppShell { $this->out(__d('cake_console', 'You need to enable %s in %s to use prefix routing.', 'Configure::write(\'Routing.prefixes\', array(\'admin\'))', '/app/Config/core.php')); - $this->_stop(); + return $this->_stop(); } return $admin . '_'; } diff --git a/lib/Cake/Console/Command/Task/ViewTask.php b/lib/Cake/Console/Command/Task/ViewTask.php index 98aeb1587..38ceb5c5c 100644 --- a/lib/Cake/Console/Command/Task/ViewTask.php +++ b/lib/Cake/Console/Command/Task/ViewTask.php @@ -267,7 +267,7 @@ class ViewTask extends BakeTask { if (!class_exists($controllerClassName)) { $file = $controllerClassName . '.php'; $this->err(__d('cake_console', "The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", $file)); - $this->_stop(); + return $this->_stop(); } $controllerObj = new $controllerClassName(); $controllerObj->plugin = $this->plugin; @@ -334,7 +334,7 @@ class ViewTask extends BakeTask { $looksGood = $this->in(__d('cake_console', 'Look okay?'), array('y', 'n'), 'y'); if (strtolower($looksGood) === 'y') { $this->bake($action, ' '); - $this->_stop(); + return $this->_stop(); } else { $this->out(__d('cake_console', 'Bake Aborted.')); } diff --git a/lib/Cake/Console/ConsoleErrorHandler.php b/lib/Cake/Console/ConsoleErrorHandler.php index c0ec663a8..1165031d9 100644 --- a/lib/Cake/Console/ConsoleErrorHandler.php +++ b/lib/Cake/Console/ConsoleErrorHandler.php @@ -60,7 +60,7 @@ class ConsoleErrorHandler { $exception->getMessage(), $exception->getTraceAsString() )); - $this->_stop($exception->getCode() ? $exception->getCode() : 1); + return $this->_stop($exception->getCode() ? $exception->getCode() : 1); } /** @@ -88,7 +88,7 @@ class ConsoleErrorHandler { } if ($log === LOG_ERR) { - $this->_stop(1); + return $this->_stop(1); } } diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index 82556223e..dde22dfed 100644 --- a/lib/Cake/Console/Shell.php +++ b/lib/Cake/Console/Shell.php @@ -504,7 +504,7 @@ class Shell extends Object { $result = $this->stdin->read(); if ($result === false) { - $this->_stop(1); + return $this->_stop(1); } $result = trim($result); @@ -618,7 +618,7 @@ class Shell extends Object { if (!empty($message)) { $this->err($message); } - $this->_stop(1); + return $this->_stop(1); } /** @@ -656,7 +656,7 @@ class Shell extends Object { if (strtolower($key) === 'q') { $this->out(__d('cake_console', 'Quitting.'), 2); - $this->_stop(); + return $this->_stop(); } elseif (strtolower($key) !== 'y') { $this->out(__d('cake_console', 'Skip `%s`', $path), 2); return false; diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 5e065711f..16523f357 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -65,7 +65,7 @@ class ShellDispatcher { */ public static function run($argv) { $dispatcher = new ShellDispatcher($argv); - $dispatcher->_stop($dispatcher->dispatch() === false ? 1 : 0); + return $dispatcher->_stop($dispatcher->dispatch() === false ? 1 : 0); } /** From 9754789b697c1d1430e6ca2f62341d405e20f6f4 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 1 Jul 2013 10:34:40 -0400 Subject: [PATCH 07/16] Don't load classnames with `..` in their names. Classnames with . in them are invalid and can be leveraged to load code outside of an application by traversing directories. --- lib/Cake/Core/App.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 9d0309bea..4913c7cc3 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -535,6 +535,9 @@ class App { if (!isset(self::$_classMap[$className])) { return false; } + if (strpos($className, '..')) { + return false; + } $parts = explode('.', self::$_classMap[$className], 2); list($plugin, $package) = count($parts) > 1 ? $parts : array(null, current($parts)); From 521c293eb182257253e4b073f63f0a95b978a0e0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 1 Jul 2013 22:56:00 -0400 Subject: [PATCH 08/16] Fix coding standards. --- .../Test/Case/Network/CakeRequestTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Test/Case/Network/CakeRequestTest.php b/lib/Cake/Test/Case/Network/CakeRequestTest.php index 8bdf6b564..ec70970c3 100644 --- a/lib/Cake/Test/Case/Network/CakeRequestTest.php +++ b/lib/Cake/Test/Case/Network/CakeRequestTest.php @@ -1237,7 +1237,7 @@ class CakeRequestTest extends CakeTestCase { */ public function testBaseUrlWithModRewriteAndIndexPhp() { $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php'; - $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php'; unset($_SERVER['PATH_INFO']); $request = new CakeRequest(); @@ -1247,8 +1247,8 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals('/cakephp/', $request->here); $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php/'; - $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/'; - $_SERVER['PATH_INFO'] = '/'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/'; + $_SERVER['PATH_INFO'] = '/'; $request = new CakeRequest(); $this->assertEquals('/cakephp', $request->base); @@ -1257,8 +1257,8 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals('/cakephp/', $request->here); $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php/apples'; - $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/apples'; - $_SERVER['PATH_INFO'] = '/apples'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/apples'; + $_SERVER['PATH_INFO'] = '/apples'; $request = new CakeRequest(); $this->assertEquals('/cakephp', $request->base); @@ -1267,8 +1267,8 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals('/cakephp/apples', $request->here); $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php/melons/share/'; - $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/melons/share/'; - $_SERVER['PATH_INFO'] = '/melons/share/'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/melons/share/'; + $_SERVER['PATH_INFO'] = '/melons/share/'; $request = new CakeRequest(); $this->assertEquals('/cakephp', $request->base); @@ -1277,8 +1277,8 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals('/cakephp/melons/share/', $request->here); $_SERVER['REQUEST_URI'] = '/cakephp/app/webroot/index.php/bananas/eat/tasty_banana'; - $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/bananas/eat/tasty_banana'; - $_SERVER['PATH_INFO'] = '/bananas/eat/tasty_banana'; + $_SERVER['PHP_SELF'] = '/cakephp/app/webroot/index.php/bananas/eat/tasty_banana'; + $_SERVER['PATH_INFO'] = '/bananas/eat/tasty_banana'; $request = new CakeRequest(); $this->assertEquals('/cakephp', $request->base); @@ -1311,7 +1311,7 @@ class CakeRequestTest extends CakeTestCase { $this->assertEquals('posts/index', $request->url); } - /** +/** * Test baseUrl and webroot with baseUrl * * @return void From 2f57a7fb18cbbe207dcb0f89cd6c66ab6e7e47b1 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 1 Jul 2013 23:06:56 -0400 Subject: [PATCH 09/16] Use simpler and faster code. substr_compare() is up to 2x slower than just substr(). Use a faster, more common, and simpler to read variant of the same thing. --- lib/Cake/Network/CakeRequest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index f7d745f82..8b7e33e42 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -261,7 +261,10 @@ class CakeRequest implements ArrayAccess { } $endsWithIndex = '/webroot/index.php'; $endsWithLength = strlen($endsWithIndex); - if (strlen($uri) >= $endsWithLength && substr_compare($uri, $endsWithIndex, -$endsWithLength, $endsWithLength) === 0) { + if ( + strlen($uri) >= $endsWithLength && + substr($uri, -$endsWithLength) == $endsWithIndex + ) { $uri = '/'; } return $uri; From c671d8da62a2e9c5f9d3d329fa3a1ed99f1a3f58 Mon Sep 17 00:00:00 2001 From: euromark Date: Tue, 2 Jul 2013 11:01:02 +0200 Subject: [PATCH 10/16] use strict comparison for strings --- lib/Cake/Network/CakeRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Network/CakeRequest.php b/lib/Cake/Network/CakeRequest.php index 8b7e33e42..fe47d48fe 100644 --- a/lib/Cake/Network/CakeRequest.php +++ b/lib/Cake/Network/CakeRequest.php @@ -263,7 +263,7 @@ class CakeRequest implements ArrayAccess { $endsWithLength = strlen($endsWithIndex); if ( strlen($uri) >= $endsWithLength && - substr($uri, -$endsWithLength) == $endsWithIndex + substr($uri, -$endsWithLength) === $endsWithIndex ) { $uri = '/'; } From ff1f80349a83b1f44e65614bdc47d9c64f230875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=BCrth?= Date: Tue, 2 Jul 2013 21:00:24 +0200 Subject: [PATCH 11/16] Removed superfluous break In every case of the if clause it will return, so break is not needed. --- lib/Cake/Model/Datasource/Database/Sqlserver.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index 69a61dedc..da3f4920e 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -537,7 +537,6 @@ class Sqlserver extends DboSource { } else { return "SELECT {$limit} {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order}"; } - break; case "schema": extract($data); From 58149f23155cd167ac97302978bf2f3fa2a63fc4 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 2 Jul 2013 16:51:29 -0430 Subject: [PATCH 12/16] Backporting from 2.4 fix for booleans in mysql when running PHP 5.5 --- lib/Cake/Model/Datasource/Database/Mysql.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 80bbceaf1..5bf989080 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -221,10 +221,10 @@ class Mysql extends DboSource { while ($numFields-- > 0) { $column = $results->getColumnMeta($index); - if (empty($column['native_type'])) { - $type = ($column['len'] == 1) ? 'boolean' : 'string'; + if ($column['len'] === 1 && (empty($column['native_type']) || $column['native_type'] === 'TINY')) { + $type = 'boolean'; } else { - $type = $column['native_type']; + $type = empty($column['native_type']) ? 'string' : $column['native_type']; } if (!empty($column['table']) && strpos($column['name'], $this->virtualFieldSeparator) === false) { $this->map[$index++] = array($column['table'], $column['name'], $type); From 7cb19b97db1cef29a3b8b3dcb3ee092004cf2b11 Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 3 Jul 2013 00:52:48 +0200 Subject: [PATCH 13/16] coding standards and simplification of else cases as well as some minor fixes --- lib/Cake/Console/Command/BakeShell.php | 3 +-- lib/Cake/Console/Command/ConsoleShell.php | 23 ++++++++-------- lib/Cake/Console/Command/I18nShell.php | 9 +++---- lib/Cake/Console/Command/SchemaShell.php | 12 ++++----- lib/Cake/Console/Command/Task/FixtureTask.php | 16 +++++------ lib/Cake/Console/Command/Task/PluginTask.php | 3 +-- lib/Cake/Console/Command/Task/ProjectTask.php | 5 +--- lib/Cake/Controller/Scaffold.php | 26 +++++++++--------- lib/Cake/Error/ErrorHandler.php | 23 ++++++++-------- lib/Cake/Model/Behavior/TreeBehavior.php | 19 +++++++------ lib/Cake/Model/Datasource/DataSource.php | 4 +-- lib/Cake/Model/Datasource/Database/Mysql.php | 6 ++--- .../Model/Datasource/Database/Postgres.php | 17 +++++------- lib/Cake/Model/Datasource/DboSource.php | 14 +++++----- lib/Cake/Model/Model.php | 18 ++++++------- .../Case/Model/BehaviorCollectionTest.php | 8 +++--- lib/Cake/TestSuite/Fixture/CakeTestModel.php | 3 +-- lib/Cake/Utility/CakeTime.php | 3 +-- lib/Cake/Utility/Debugger.php | 8 +++--- lib/Cake/Utility/Inflector.php | 3 +-- lib/Cake/Utility/Validation.php | 1 - lib/Cake/View/Helper.php | 11 +++----- lib/Cake/View/Helper/FormHelper.php | 27 +++++++++---------- lib/Cake/View/Helper/JqueryEngineHelper.php | 2 +- lib/Cake/View/Helper/JsBaseEngineHelper.php | 11 ++++---- lib/Cake/View/Helper/MootoolsEngineHelper.php | 6 ++--- lib/Cake/View/Helper/PaginatorHelper.php | 5 ++-- .../View/Helper/PrototypeEngineHelper.php | 6 ++--- lib/Cake/View/Helper/RssHelper.php | 10 +++---- lib/Cake/View/Helper/TimeHelper.php | 3 +-- lib/Cake/basics.php | 6 ++--- 31 files changed, 142 insertions(+), 169 deletions(-) diff --git a/lib/Cake/Console/Command/BakeShell.php b/lib/Cake/Console/Command/BakeShell.php index 93503ef7f..ce12401a9 100644 --- a/lib/Cake/Console/Command/BakeShell.php +++ b/lib/Cake/Console/Command/BakeShell.php @@ -123,8 +123,7 @@ class BakeShell extends AppShell { $this->Test->execute(); break; case 'Q': - exit(0); - break; + return $this->_stop(); default: $this->out(__d('cake_console', 'You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, F, T, or C.')); } diff --git a/lib/Cake/Console/Command/ConsoleShell.php b/lib/Cake/Console/Command/ConsoleShell.php index e6ee110cd..7b97f89db 100644 --- a/lib/Cake/Console/Command/ConsoleShell.php +++ b/lib/Cake/Console/Command/ConsoleShell.php @@ -172,7 +172,7 @@ class ConsoleShell extends AppShell { switch ($command) { case 'help': $this->help(); - break; + break; case 'quit': case 'exit': return true; @@ -182,7 +182,7 @@ class ConsoleShell extends AppShell { foreach ($this->models as $model) { $this->out(" - {$model}"); } - break; + break; case preg_match("/^(\w+) bind (\w+) (\w+)/", $command, $tmp): foreach ($tmp as $data) { $data = strip_tags($data); @@ -200,7 +200,7 @@ class ConsoleShell extends AppShell { } else { $this->out(__d('cake_console', "Please verify you are using valid models and association types")); } - break; + break; case preg_match("/^(\w+) unbind (\w+) (\w+)/", $command, $tmp): foreach ($tmp as $data) { $data = strip_tags($data); @@ -228,7 +228,7 @@ class ConsoleShell extends AppShell { } else { $this->out(__d('cake_console', "Please verify you are using valid models, valid current association, and valid association types")); } - break; + break; case (strpos($command, "->find") > 0): // Remove any bad info $command = strip_tags($command); @@ -285,7 +285,7 @@ class ConsoleShell extends AppShell { $this->out(__d('cake_console', "%s is not a valid model", $modelToCheck)); } - break; + break; case (strpos($command, '->save') > 0): // Validate the model we're trying to save here $command = strip_tags($command); @@ -302,7 +302,7 @@ class ConsoleShell extends AppShell { //@codingStandardsIgnoreEnd $this->out(__d('cake_console', 'Saved record for %s', $modelToSave)); } - break; + break; case preg_match("/^(\w+) columns/", $command, $tmp): $modelToCheck = strip_tags(str_replace($this->badCommandChars, "", $tmp[1])); @@ -321,31 +321,30 @@ class ConsoleShell extends AppShell { } else { $this->out(__d('cake_console', "Please verify that you selected a valid model")); } - break; + break; case preg_match("/^routes\s+reload/i", $command, $tmp): if (!$this->_loadRoutes()) { $this->err(__d('cake_console', "There was an error loading the routes config. Please check that the file exists and is free of parse errors.")); break; } $this->out(__d('cake_console', "Routes configuration reloaded, %d routes connected", count(Router::$routes))); - break; + break; case preg_match("/^routes\s+show/i", $command, $tmp): $this->out(print_r(Hash::combine(Router::$routes, '{n}.template', '{n}.defaults'), true)); - break; + break; case (preg_match("/^route\s+(\(.*\))$/i", $command, $tmp) == true): //@codingStandardsIgnoreStart if ($url = eval('return array' . $tmp[1] . ';')) { //@codingStandardsIgnoreEnd $this->out(Router::url($url)); } - break; + break; case preg_match("/^route\s+(.*)/i", $command, $tmp): $this->out(var_export(Router::parse($tmp[1]), true)); - break; + break; default: $this->out(__d('cake_console', "Invalid command")); $this->out(); - break; } $command = ''; } diff --git a/lib/Cake/Console/Command/I18nShell.php b/lib/Cake/Console/Command/I18nShell.php index bcfca62c4..c0782ba4e 100644 --- a/lib/Cake/Console/Command/I18nShell.php +++ b/lib/Cake/Console/Command/I18nShell.php @@ -76,16 +76,15 @@ class I18nShell extends AppShell { switch ($choice) { case 'e': $this->Extract->execute(); - break; + break; case 'i': $this->initdb(); - break; + break; case 'h': $this->out($this->OptionParser->help()); - break; + break; case 'q': - exit(0); - break; + return $this->_stop(); default: $this->out(__d('cake_console', 'You have made an invalid selection. Please choose a command to execute by entering E, I, H, or Q.')); } diff --git a/lib/Cake/Console/Command/SchemaShell.php b/lib/Cake/Console/Command/SchemaShell.php index 90acff90e..c45988b67 100644 --- a/lib/Cake/Console/Command/SchemaShell.php +++ b/lib/Cake/Console/Command/SchemaShell.php @@ -107,11 +107,10 @@ class SchemaShell extends AppShell { if ($File->exists()) { $this->out($File->read()); return $this->_stop(); - } else { - $file = $this->Schema->path . DS . $this->params['file']; - $this->err(__d('cake_console', 'Schema file (%s) could not be found.', $file)); - return $this->_stop(); } + $file = $this->Schema->path . DS . $this->params['file']; + $this->err(__d('cake_console', 'Schema file (%s) could not be found.', $file)); + return $this->_stop(); } /** @@ -185,10 +184,9 @@ class SchemaShell extends AppShell { if ($this->Schema->write($content)) { $this->out(__d('cake_console', 'Schema file: %s generated', $content['file'])); return $this->_stop(); - } else { - $this->err(__d('cake_console', 'Schema file: %s generated')); - return $this->_stop(); } + $this->err(__d('cake_console', 'Schema file: %s generated')); + return $this->_stop(); } /** diff --git a/lib/Cake/Console/Command/Task/FixtureTask.php b/lib/Cake/Console/Command/Task/FixtureTask.php index 2a3cdce61..d6831325e 100644 --- a/lib/Cake/Console/Command/Task/FixtureTask.php +++ b/lib/Cake/Console/Command/Task/FixtureTask.php @@ -304,7 +304,7 @@ class FixtureTask extends BakeTask { case 'integer': case 'float': $insert = $i + 1; - break; + break; case 'string': case 'binary': $isPrimaryUuid = ( @@ -319,22 +319,22 @@ class FixtureTask extends BakeTask { $insert = substr($insert, 0, (int)$fieldInfo['length'] - 2); } } - break; + break; case 'timestamp': $insert = time(); - break; + break; case 'datetime': $insert = date('Y-m-d H:i:s'); - break; + break; case 'date': $insert = date('Y-m-d'); - break; + break; case 'time': $insert = date('H:i:s'); - break; + break; case 'boolean': $insert = 1; - break; + break; case 'text': $insert = "Lorem ipsum dolor sit amet, aliquet feugiat."; $insert .= " Convallis morbi fringilla gravida,"; @@ -343,7 +343,7 @@ class FixtureTask extends BakeTask { $insert .= " vestibulum massa neque ut et, id hendrerit sit,"; $insert .= " feugiat in taciti enim proin nibh, tempor dignissim, rhoncus"; $insert .= " duis vestibulum nunc mattis convallis."; - break; + break; } $record[$field] = $insert; } diff --git a/lib/Cake/Console/Command/Task/PluginTask.php b/lib/Cake/Console/Command/Task/PluginTask.php index c64cdcaf3..4db5b7d3b 100644 --- a/lib/Cake/Console/Command/Task/PluginTask.php +++ b/lib/Cake/Console/Command/Task/PluginTask.php @@ -65,9 +65,8 @@ class PluginTask extends AppShell { $this->out(__d('cake_console', 'Plugin: %s already exists, no action taken', $plugin)); $this->out(__d('cake_console', 'Path: %s', $pluginPath)); return false; - } else { - $this->_interactive($plugin); } + $this->_interactive($plugin); } else { return $this->_interactive(); } diff --git a/lib/Cake/Console/Command/Task/ProjectTask.php b/lib/Cake/Console/Command/Task/ProjectTask.php index cc63d0846..d8fb25cb5 100644 --- a/lib/Cake/Console/Command/Task/ProjectTask.php +++ b/lib/Cake/Console/Command/Task/ProjectTask.php @@ -368,12 +368,9 @@ class ProjectTask extends AppShell { if ($File->write($result)) { Configure::write('Routing.prefixes', array($name)); return true; - } else { - return false; } - } else { - return false; } + return false; } /** diff --git a/lib/Cake/Controller/Scaffold.php b/lib/Cake/Controller/Scaffold.php index 27aecb8ed..477b8c9d5 100644 --- a/lib/Cake/Controller/Scaffold.php +++ b/lib/Cake/Controller/Scaffold.php @@ -250,9 +250,8 @@ class Scaffold { $success ); return $this->_sendMessage($message); - } else { - return $this->controller->afterScaffoldSaveError($action); } + return $this->controller->afterScaffoldSaveError($action); } else { if ($this->_validSession) { $this->controller->Session->setFlash(__d('cake', 'Please correct errors below.')); @@ -309,14 +308,13 @@ class Scaffold { if ($this->ScaffoldModel->delete()) { $message = __d('cake', 'The %1$s with id: %2$s has been deleted.', Inflector::humanize($this->modelClass), $id); return $this->_sendMessage($message); - } else { - $message = __d('cake', - 'There was an error deleting the %1$s with id: %2$s', - Inflector::humanize($this->modelClass), - $id - ); - return $this->_sendMessage($message); } + $message = __d('cake', + 'There was an error deleting the %1$s with id: %2$s', + Inflector::humanize($this->modelClass), + $id + ); + return $this->_sendMessage($message); } elseif ($this->controller->scaffoldError('delete') === false) { return $this->_scaffoldError(); } @@ -388,21 +386,21 @@ class Scaffold { case 'index': case 'list': $this->_scaffoldIndex($request); - break; + break; case 'view': $this->_scaffoldView($request); - break; + break; case 'add': case 'create': $this->_scaffoldSave($request, 'add'); - break; + break; case 'edit': case 'update': $this->_scaffoldSave($request, 'edit'); - break; + break; case 'delete': $this->_scaffoldDelete($request); - break; + break; } } else { throw new MissingActionException(array( diff --git a/lib/Cake/Error/ErrorHandler.php b/lib/Cake/Error/ErrorHandler.php index 7da8902d5..edb043bd7 100644 --- a/lib/Cake/Error/ErrorHandler.php +++ b/lib/Cake/Error/ErrorHandler.php @@ -198,14 +198,13 @@ class ErrorHandler { 'path' => Debugger::trimPath($file) ); return Debugger::getInstance()->outputError($data); - } else { - $message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']'; - if (!empty($errorConfig['trace'])) { - $trace = Debugger::trace(array('start' => 1, 'format' => 'log')); - $message .= "\nTrace:\n" . $trace . "\n"; - } - return CakeLog::write($log, $message); } + $message = $error . ' (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']'; + if (!empty($errorConfig['trace'])) { + $trace = Debugger::trace(array('start' => 1, 'format' => 'log')); + $message .= "\nTrace:\n" . $trace . "\n"; + } + return CakeLog::write($log, $message); } /** @@ -254,28 +253,28 @@ class ErrorHandler { case E_USER_ERROR: $error = 'Fatal Error'; $log = LOG_ERR; - break; + break; case E_WARNING: case E_USER_WARNING: case E_COMPILE_WARNING: case E_RECOVERABLE_ERROR: $error = 'Warning'; $log = LOG_WARNING; - break; + break; case E_NOTICE: case E_USER_NOTICE: $error = 'Notice'; $log = LOG_NOTICE; - break; + break; case E_STRICT: $error = 'Strict'; $log = LOG_NOTICE; - break; + break; case E_DEPRECATED: case E_USER_DEPRECATED: $error = 'Deprecated'; $log = LOG_NOTICE; - break; + break; } return array($error, $log); } diff --git a/lib/Cake/Model/Behavior/TreeBehavior.php b/lib/Cake/Model/Behavior/TreeBehavior.php index 040aff1c1..1faeec819 100644 --- a/lib/Cake/Model/Behavior/TreeBehavior.php +++ b/lib/Cake/Model/Behavior/TreeBehavior.php @@ -762,17 +762,16 @@ class TreeBehavior extends ModelBehavior { array($Model->escapeField() => $id) ); return $Model->delete($id); - } else { - $edge = $this->_getMax($Model, $scope, $right, $recursive); - if ($node[$right] == $edge) { - $edge = $edge - 2; - } - $Model->id = $id; - return $Model->save( - array($left => $edge + 1, $right => $edge + 2, $parent => null), - array('callbacks' => false, 'validate' => false) - ); } + $edge = $this->_getMax($Model, $scope, $right, $recursive); + if ($node[$right] == $edge) { + $edge = $edge - 2; + } + $Model->id = $id; + return $Model->save( + array($left => $edge + 1, $right => $edge + 2, $parent => null), + array('callbacks' => false, 'validate' => false) + ); } /** diff --git a/lib/Cake/Model/Datasource/DataSource.php b/lib/Cake/Model/Datasource/DataSource.php index 9d091599e..e30353fd5 100644 --- a/lib/Cake/Model/Datasource/DataSource.php +++ b/lib/Cake/Model/Datasource/DataSource.php @@ -357,7 +357,7 @@ class DataSource extends Object { } } $type = $model->getColumnType($model->primaryKey); - break; + break; case '{$__cakeForeignKey__$}': foreach ($model->associations() as $name) { foreach ($model->$name as $assocName => $assoc) { @@ -389,7 +389,7 @@ class DataSource extends Object { } } } - break; + break; } if (empty($val) && $val !== '0') { return false; diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 5bf989080..ed64940d6 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -516,13 +516,13 @@ class Mysql extends DboSource { } $colList[] = $alter; } - break; + break; case 'drop': foreach ($column as $field => $col) { $col['name'] = $field; $colList[] = 'DROP ' . $this->name($field); } - break; + break; case 'change': foreach ($column as $field => $col) { if (!isset($col['name'])) { @@ -530,7 +530,7 @@ class Mysql extends DboSource { } $colList[] = 'CHANGE ' . $this->name($field) . ' ' . $this->buildColumn($col); } - break; + break; } } $colList = array_merge($colList, $this->_alterIndexes($curTable, $indexes)); diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 2c09cfbd8..1977a966f 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -516,13 +516,13 @@ class Postgres extends DboSource { $col['name'] = $field; $colList[] = 'ADD COLUMN ' . $this->buildColumn($col); } - break; + break; case 'drop': foreach ($column as $field => $col) { $col['name'] = $field; $colList[] = 'DROP COLUMN ' . $this->name($field); } - break; + break; case 'change': foreach ($column as $field => $col) { if (!isset($col['name'])) { @@ -552,7 +552,7 @@ class Postgres extends DboSource { } } - break; + break; } } if (isset($indexes['drop']['PRIMARY'])) { @@ -748,21 +748,19 @@ class Postgres extends DboSource { switch ($type) { case 'bool': $resultRow[$table][$column] = is_null($row[$index]) ? null : $this->boolean($row[$index]); - break; + break; case 'binary': case 'bytea': $resultRow[$table][$column] = is_null($row[$index]) ? null : stream_get_contents($row[$index]); - break; + break; default: $resultRow[$table][$column] = $row[$index]; - break; } } return $resultRow; - } else { - $this->_result->closeCursor(); - return false; } + $this->_result->closeCursor(); + return false; } /** @@ -788,7 +786,6 @@ class Postgres extends DboSource { break; default: $result = (bool)$data; - break; } if ($quote) { diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 824bd2869..c82ec3bdf 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -1569,7 +1569,7 @@ class DboSource extends DataSource { } return true; } - break; + break; case 'hasMany': $assocData['fields'] = $this->fields($linkModel, $association, $assocData['fields']); if (!empty($assocData['foreignKey'])) { @@ -1585,7 +1585,7 @@ class DboSource extends DataSource { 'offset' => $assocData['offset'], 'group' => null ); - break; + break; case 'hasAndBelongsToMany': $joinFields = array(); $joinAssoc = null; @@ -1622,7 +1622,7 @@ class DboSource extends DataSource { 'conditions' => $this->getConstraint('hasAndBelongsToMany', $model, $linkModel, $joinAlias, $assocData, $association) )) ); - break; + break; } if (isset($query)) { return $this->buildStatement($query, $model); @@ -2596,22 +2596,22 @@ class DboSource extends DataSource { switch ($operator) { case '=': $operator = 'IN'; - break; + break; case '!=': case '<>': $operator = 'NOT IN'; - break; + break; } $value = "({$value})"; } elseif ($null || $value === 'NULL') { switch ($operator) { case '=': $operator = 'IS'; - break; + break; case '!=': case '<>': $operator = 'IS NOT'; - break; + break; } } if ($virtual) { diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index a0033c818..09418910b 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1058,34 +1058,34 @@ class Model extends Object implements CakeEventListener { switch ($key) { case 'fields': $data = ''; - break; + break; case 'foreignKey': $data = (($type === 'belongsTo') ? Inflector::underscore($assocKey) : Inflector::singularize($this->table)) . '_id'; - break; + break; case 'associationForeignKey': $data = Inflector::singularize($this->{$class}->table) . '_id'; - break; + break; case 'with': $data = Inflector::camelize(Inflector::singularize($this->{$type}[$assocKey]['joinTable'])); $dynamicWith = true; - break; + break; case 'joinTable': $tables = array($this->table, $this->{$class}->table); sort($tables); $data = $tables[0] . '_' . $tables[1]; - break; + break; case 'className': $data = $class; - break; + break; case 'unique': $data = true; - break; + break; } $this->{$type}[$assocKey][$key] = $data; } @@ -2281,7 +2281,7 @@ class Model extends Object implements CakeEventListener { $validationErrors[$association] = $this->{$association}->validationErrors; } $return[$association] = $validates; - break; + break; case 'hasMany': foreach ($values as $i => $value) { if (isset($values[$i][$association])) { @@ -2297,7 +2297,7 @@ class Model extends Object implements CakeEventListener { $validates = false; } $return[$association] = $_return; - break; + break; } } } diff --git a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php index c11940cef..58a667baa 100644 --- a/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php +++ b/lib/Cake/Test/Case/Model/BehaviorCollectionTest.php @@ -142,15 +142,15 @@ class TestBehavior extends ModelBehavior { switch ($settings['afterSave']) { case 'on': $model->data[$model->alias]['aftersave'] = $string; - break; + break; case 'test': unset($model->data[$model->alias]['name']); - break; + break; case 'test2': return false; case 'modify': $model->data[$model->alias]['name'] .= ' ' . $string; - break; + break; } } @@ -241,7 +241,7 @@ class TestBehavior extends ModelBehavior { switch ($settings['afterDelete']) { case 'on': echo 'afterDelete success'; - break; + break; } } diff --git a/lib/Cake/TestSuite/Fixture/CakeTestModel.php b/lib/Cake/TestSuite/Fixture/CakeTestModel.php index 0a0e25645..6e456c1cf 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestModel.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestModel.php @@ -47,10 +47,9 @@ class CakeTestModel extends Model { case (is_string($queryData['fields']) && !($queryData['fields'] == $pk || $queryData['fields'] == $aliasedPk)) || (is_array($queryData['fields']) && !(array_key_exists($pk, $queryData['fields']) || array_key_exists($aliasedPk, $queryData['fields']))): - break; + break; default: $queryData['order'] = array($this->alias . '.' . $this->primaryKey => 'ASC'); - break; } return $queryData; } diff --git a/lib/Cake/Utility/CakeTime.php b/lib/Cake/Utility/CakeTime.php index d2fb91ddf..0804f1644 100644 --- a/lib/Cake/Utility/CakeTime.php +++ b/lib/Cake/Utility/CakeTime.php @@ -97,14 +97,13 @@ class CakeTime { * * @param string $name Variable name * @param mixes $value Variable value + * @return void */ public function __set($name, $value) { switch ($name) { case 'niceFormat': self::${$name} = $value; break; - default: - break; } } diff --git a/lib/Cake/Utility/Debugger.php b/lib/Cake/Utility/Debugger.php index 68417015c..871bd31b7 100644 --- a/lib/Cake/Utility/Debugger.php +++ b/lib/Cake/Utility/Debugger.php @@ -230,24 +230,24 @@ class Debugger { case E_USER_ERROR: $error = 'Fatal Error'; $level = LOG_ERR; - break; + break; case E_WARNING: case E_USER_WARNING: case E_COMPILE_WARNING: case E_RECOVERABLE_ERROR: $error = 'Warning'; $level = LOG_WARNING; - break; + break; case E_NOTICE: case E_USER_NOTICE: $error = 'Notice'; $level = LOG_NOTICE; - break; + break; case E_DEPRECATED: case E_USER_DEPRECATED: $error = 'Deprecated'; $level = LOG_NOTICE; - break; + break; default: return; } diff --git a/lib/Cake/Utility/Inflector.php b/lib/Cake/Utility/Inflector.php index 26e64a283..0fc06af7b 100644 --- a/lib/Cake/Utility/Inflector.php +++ b/lib/Cake/Utility/Inflector.php @@ -308,7 +308,7 @@ class Inflector { } else { self::$_transliteration = $rules + self::$_transliteration; } - break; + break; default: foreach ($rules as $rule => $pattern) { @@ -334,7 +334,6 @@ class Inflector { } } self::${$var}['rules'] = $rules + self::${$var}['rules']; - break; } } diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index 5935ee5b3..e60acd16d 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -255,7 +255,6 @@ class Validation { break; default: self::$errors[] = __d('cake_dev', 'You must define the $operator parameter for Validation::comparison()'); - break; } return false; } diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index 2c88ef0cd..cc3638aed 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -662,18 +662,16 @@ class Helper extends Object { switch ($field) { case '_method': $name = $field; - break; + break; default: $name = 'data[' . implode('][', $this->entity()) . ']'; - break; } if (is_array($options)) { $options[$key] = $name; return $options; - } else { - return $name; } + return $name; } /** @@ -729,9 +727,8 @@ class Helper extends Object { if (is_array($options)) { $options[$key] = $result; return $options; - } else { - return $result; } + return $result; } /** @@ -920,7 +917,7 @@ class Helper extends Object { do { $oldstring = $this->_cleaned; $this->_cleaned = preg_replace('#]*>#i', "", $this->_cleaned); - } while ($oldstring != $this->_cleaned); + } while ($oldstring !== $this->_cleaned); $this->_cleaned = str_replace(array("&", "<", ">"), array("&amp;", "&lt;", "&gt;"), $this->_cleaned); } diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index bc0247926..a97c85217 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -407,7 +407,7 @@ class FormHelper extends AppHelper { switch (strtolower($options['type'])) { case 'get': $htmlAttributes['method'] = 'get'; - break; + break; case 'file': $htmlAttributes['enctype'] = 'multipart/form-data'; $options['type'] = ($created) ? 'put' : 'post'; @@ -420,7 +420,6 @@ class FormHelper extends AppHelper { )); default: $htmlAttributes['method'] = 'post'; - break; } $this->requestType = strtolower($options['type']); @@ -2456,16 +2455,16 @@ class FormHelper extends AppHelper { $selects[] = $this->year( $fieldName, $minYear, $maxYear, $attrs['Year'] ); - break; + break; case 'M': $attrs['Month']['value'] = $month; $attrs['Month']['monthNames'] = $monthNames; $selects[] = $this->month($fieldName, $attrs['Month']); - break; + break; case 'D': $attrs['Day']['value'] = $day; $selects[] = $this->day($fieldName, $attrs['Day']); - break; + break; } } $opt = implode($separator, $selects); @@ -2477,7 +2476,7 @@ class FormHelper extends AppHelper { $attrs['Minute']['value'] = $min; $opt .= $this->hour($fieldName, true, $attrs['Hour']) . ':' . $this->minute($fieldName, $attrs['Minute']); - break; + break; case '12': $attrs['Hour']['value'] = $hour; $attrs['Minute']['value'] = $min; @@ -2485,7 +2484,7 @@ class FormHelper extends AppHelper { $opt .= $this->hour($fieldName, false, $attrs['Hour']) . ':' . $this->minute($fieldName, $attrs['Minute']) . ' ' . $this->meridian($fieldName, $attrs['Meridian']); - break; + break; } return $opt; } @@ -2719,20 +2718,20 @@ class FormHelper extends AppHelper { $data[sprintf('%02d', $i)] = sprintf('%02d', $i); $i += $interval; } - break; + break; case 'hour': for ($i = 1; $i <= 12; $i++) { $data[sprintf('%02d', $i)] = $i; } - break; + break; case 'hour24': for ($i = 0; $i <= 23; $i++) { $data[sprintf('%02d', $i)] = $i; } - break; + break; case 'meridian': $data = array('am' => 'am', 'pm' => 'pm'); - break; + break; case 'day': $min = 1; $max = 31; @@ -2747,7 +2746,7 @@ class FormHelper extends AppHelper { for ($i = $min; $i <= $max; $i++) { $data[sprintf('%02d', $i)] = $i; } - break; + break; case 'month': if ($options['monthNames'] === true) { $data['01'] = __d('cake', 'January'); @@ -2769,7 +2768,7 @@ class FormHelper extends AppHelper { $data[sprintf("%02s", $m)] = strftime("%m", mktime(1, 1, 1, $m, 1, 1999)); } } - break; + break; case 'year': $current = intval(date('Y')); @@ -2791,7 +2790,7 @@ class FormHelper extends AppHelper { if ($options['order'] !== 'asc') { $data = array_reverse($data, true); } - break; + break; } $this->_options[$name] = $data; return $this->_options[$name]; diff --git a/lib/Cake/View/Helper/JqueryEngineHelper.php b/lib/Cake/View/Helper/JqueryEngineHelper.php index 0bbc07c60..b72144a0c 100644 --- a/lib/Cake/View/Helper/JqueryEngineHelper.php +++ b/lib/Cake/View/Helper/JqueryEngineHelper.php @@ -235,7 +235,7 @@ class JqueryEngineHelper extends JsBaseEngineHelper { case 'slideDown': case 'slideUp': $effect = ".$name($speed);"; - break; + break; } return $this->selection . $effect; } diff --git a/lib/Cake/View/Helper/JsBaseEngineHelper.php b/lib/Cake/View/Helper/JsBaseEngineHelper.php index 23c91616d..a7afce88c 100644 --- a/lib/Cake/View/Helper/JsBaseEngineHelper.php +++ b/lib/Cake/View/Helper/JsBaseEngineHelper.php @@ -147,25 +147,24 @@ abstract class JsBaseEngineHelper extends AppHelper { switch (true) { case (is_array($val) || is_object($val)): $val = $this->object($val); - break; + break; case ($val === null): $val = 'null'; - break; + break; case (is_bool($val)): $val = ($val === true) ? 'true' : 'false'; - break; + break; case (is_int($val)): $val = $val; - break; + break; case (is_float($val)): $val = sprintf("%.11f", $val); - break; + break; default: $val = $this->escape($val); if ($quoteString) { $val = '"' . $val . '"'; } - break; } return $val; } diff --git a/lib/Cake/View/Helper/MootoolsEngineHelper.php b/lib/Cake/View/Helper/MootoolsEngineHelper.php index e5058bac5..5d66cf2e5 100644 --- a/lib/Cake/View/Helper/MootoolsEngineHelper.php +++ b/lib/Cake/View/Helper/MootoolsEngineHelper.php @@ -205,10 +205,10 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { switch ($name) { case 'hide': $effect = 'setStyle("display", "none")'; - break; + break; case 'show': $effect = 'setStyle("display", "")'; - break; + break; case 'fadeIn': case 'fadeOut': case 'slideIn': @@ -219,7 +219,7 @@ class MootoolsEngineHelper extends JsBaseEngineHelper { $effect .= "set(\"$effectName\", {duration:$speed})."; } $effect .= "$effectName(\"$direction\")"; - break; + break; } return $this->selection . '.' . $effect . ';'; } diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 09af0d16c..7357abe15 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -628,10 +628,10 @@ class PaginatorHelper extends AppHelper { } $out = $start . $options['separator'][0] . $end . $options['separator'][1]; $out .= $paging['count']; - break; + break; case 'pages': $out = $paging['page'] . $options['separator'] . $paging['pageCount']; - break; + break; default: $map = array( '%page%' => $paging['page'], @@ -648,7 +648,6 @@ class PaginatorHelper extends AppHelper { '{:page}', '{:pages}', '{:current}', '{:count}', '{:start}', '{:end}', '{:model}' ); $out = str_replace($newKeys, array_values($map), $out); - break; } return $out; } diff --git a/lib/Cake/View/Helper/PrototypeEngineHelper.php b/lib/Cake/View/Helper/PrototypeEngineHelper.php index 1807cb765..c20a9f781 100644 --- a/lib/Cake/View/Helper/PrototypeEngineHelper.php +++ b/lib/Cake/View/Helper/PrototypeEngineHelper.php @@ -212,17 +212,17 @@ class PrototypeEngineHelper extends JsBaseEngineHelper { case 'hide': case 'show': $effect = $this->selection . '.' . $name . '();'; - break; + break; case 'slideIn': case 'slideOut': $name = ($name === 'slideIn') ? 'slideDown' : 'slideUp'; $effect = 'Effect.' . $name . '(' . $this->selection . $optionString . ');'; - break; + break; case 'fadeIn': case 'fadeOut': $name = ($name === 'fadeIn') ? 'appear' : 'fade'; $effect = $this->selection . '.' . $name . '(' . substr($optionString, 2) . ');'; - break; + break; } return $effect; } diff --git a/lib/Cake/View/Helper/RssHelper.php b/lib/Cake/View/Helper/RssHelper.php index b3706767f..f1e22faaf 100644 --- a/lib/Cake/View/Helper/RssHelper.php +++ b/lib/Cake/View/Helper/RssHelper.php @@ -208,7 +208,7 @@ class RssHelper extends AppHelper { switch ($key) { case 'pubDate' : $val = $this->time($val); - break; + break; case 'category' : if (is_array($val) && !empty($val[0])) { foreach ($val as $category) { @@ -224,7 +224,7 @@ class RssHelper extends AppHelper { } elseif (is_array($val) && isset($val['domain'])) { $attrib['domain'] = $val['domain']; } - break; + break; case 'link': case 'guid': case 'comments': @@ -234,7 +234,7 @@ class RssHelper extends AppHelper { $val = $val['url']; } $val = $this->url($val, true); - break; + break; case 'source': if (is_array($val) && isset($val['url'])) { $attrib['url'] = $this->url($val['url'], true); @@ -243,7 +243,7 @@ class RssHelper extends AppHelper { $attrib['url'] = $this->url($val[0], true); $val = $val[1]; } - break; + break; case 'enclosure': if (is_string($val['url']) && is_file(WWW_ROOT . $val['url']) && file_exists(WWW_ROOT . $val['url'])) { if (!isset($val['length']) && strpos($val['url'], '://') === false) { @@ -256,7 +256,7 @@ class RssHelper extends AppHelper { $val['url'] = $this->url($val['url'], true); $attrib = $val; $val = null; - break; + break; default: $attrib = $att; } diff --git a/lib/Cake/View/Helper/TimeHelper.php b/lib/Cake/View/Helper/TimeHelper.php index 175dd002a..a5edd8ef3 100644 --- a/lib/Cake/View/Helper/TimeHelper.php +++ b/lib/Cake/View/Helper/TimeHelper.php @@ -75,10 +75,9 @@ class TimeHelper extends AppHelper { switch ($name) { case 'niceFormat': $this->_engine->{$name} = $value; - break; + break; default: $this->{$name} = $value; - break; } } diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index b0b30e937..538de3f00 100644 --- a/lib/Cake/basics.php +++ b/lib/Cake/basics.php @@ -402,13 +402,13 @@ if (!function_exists('cache')) { switch (strtolower($target)) { case 'cache': $filename = CACHE . $path; - break; + break; case 'public': $filename = WWW_ROOT . $path; - break; + break; case 'tmp': $filename = TMP . $path; - break; + break; } $timediff = $expires - $now; $filetime = false; From a90cb29c0f6f40b1605f97f0bba8bc74fff70955 Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 3 Jul 2013 01:14:41 +0200 Subject: [PATCH 14/16] simplify else cases --- lib/Cake/Model/Datasource/Database/Mysql.php | 48 +++++++++---------- .../Model/Datasource/Database/Postgres.php | 3 +- lib/Cake/Model/Datasource/Database/Sqlite.php | 5 +- .../Model/Datasource/Database/Sqlserver.php | 25 +++++----- lib/Cake/Model/Datasource/DboSource.php | 35 +++++++------- lib/Cake/Model/Permission.php | 43 ++++++++--------- .../Model/Validator/CakeValidationRule.php | 3 +- lib/Cake/Network/CakeSocket.php | 7 ++- lib/Cake/Network/Email/CakeEmail.php | 3 +- .../Case/Model/Behavior/AclBehaviorTest.php | 3 +- .../Behavior/ContainableBehaviorTest.php | 9 ++-- lib/Cake/TestSuite/CakeTestSuiteCommand.php | 3 +- lib/Cake/Utility/Folder.php | 10 ++-- lib/Cake/Utility/Validation.php | 3 +- lib/Cake/View/Helper/FormHelper.php | 11 ++--- lib/Cake/View/Helper/PaginatorHelper.php | 29 ++++++----- lib/Cake/View/View.php | 3 +- 17 files changed, 109 insertions(+), 134 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index ed64940d6..099df5d5c 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -195,17 +195,16 @@ class Mysql extends DboSource { if (!$result) { $result->closeCursor(); return array(); - } else { - $tables = array(); - - while ($line = $result->fetch(PDO::FETCH_NUM)) { - $tables[] = $line[0]; - } - - $result->closeCursor(); - parent::listSources($tables); - return $tables; } + $tables = array(); + + while ($line = $result->fetch(PDO::FETCH_NUM)) { + $tables[] = $line[0]; + } + + $result->closeCursor(); + parent::listSources($tables); + return $tables; } /** @@ -679,24 +678,23 @@ class Mysql extends DboSource { if (!$result) { $result->closeCursor(); return array(); - } else { - $tables = array(); - foreach ($result as $row) { - $tables[$row['Name']] = (array)$row; - unset($tables[$row['Name']]['queryString']); - if (!empty($row['Collation'])) { - $charset = $this->getCharsetName($row['Collation']); - if ($charset) { - $tables[$row['Name']]['charset'] = $charset; - } + } + $tables = array(); + foreach ($result as $row) { + $tables[$row['Name']] = (array)$row; + unset($tables[$row['Name']]['queryString']); + if (!empty($row['Collation'])) { + $charset = $this->getCharsetName($row['Collation']); + if ($charset) { + $tables[$row['Name']]['charset'] = $charset; } } - $result->closeCursor(); - if (is_string($name) && isset($tables[$name])) { - return $tables[$name]; - } - return $tables; } + $result->closeCursor(); + if (is_string($name) && isset($tables[$name])) { + return $tables[$name]; + } + return $tables; } /** diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 1977a966f..743feb35e 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -300,9 +300,8 @@ class Postgres extends DboSource { } if (isset($this->_sequenceMap[$table][$field])) { return $this->_sequenceMap[$table][$field]; - } else { - return "{$table}_{$field}_seq"; } + return "{$table}_{$field}_seq"; } /** diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index 6d3e15fcd..eabcb0876 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -362,10 +362,9 @@ class Sqlite extends DboSource { } } return $resultRow; - } else { - $this->_result->closeCursor(); - return false; } + $this->_result->closeCursor(); + return false; } /** diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index da3f4920e..e67038525 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -167,17 +167,16 @@ class Sqlserver extends DboSource { if (!$result) { $result->closeCursor(); return array(); - } else { - $tables = array(); - - while ($line = $result->fetch(PDO::FETCH_NUM)) { - $tables[] = $line[0]; - } - - $result->closeCursor(); - parent::listSources($tables); - return $tables; } + $tables = array(); + + while ($line = $result->fetch(PDO::FETCH_NUM)) { + $tables[] = $line[0]; + } + + $result->closeCursor(); + parent::listSources($tables); + return $tables; } /** @@ -313,9 +312,8 @@ class Sqlserver extends DboSource { $result[] = $prepend . $fields[$i]; } return $result; - } else { - return $fields; } + return $fields; } /** @@ -534,9 +532,8 @@ class Sqlserver extends DboSource { "; } elseif (strpos($limit, 'FETCH') !== false) { return "SELECT {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order} {$limit}"; - } else { - return "SELECT {$limit} {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order}"; } + return "SELECT {$limit} {$fields} FROM {$table} {$alias} {$joins} {$conditions} {$group} {$order}"; case "schema": extract($data); diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index c82ec3bdf..db80a4fa4 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -592,25 +592,23 @@ class DboSource extends DataSource { $recursive = $params[5 + $off]; } return $args[2]->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive')); + } + if (isset($params[3 + $off])) { + $recursive = $params[3 + $off]; + } + return $args[2]->find('first', compact('conditions', 'fields', 'order', 'recursive')); + } + if (isset($args[1]) && $args[1] === true) { + return $this->fetchAll($args[0], true); + } elseif (isset($args[1]) && !is_array($args[1])) { + return $this->fetchAll($args[0], false); + } elseif (isset($args[1]) && is_array($args[1])) { + if (isset($args[2])) { + $cache = $args[2]; } else { - if (isset($params[3 + $off])) { - $recursive = $params[3 + $off]; - } - return $args[2]->find('first', compact('conditions', 'fields', 'order', 'recursive')); - } - } else { - if (isset($args[1]) && $args[1] === true) { - return $this->fetchAll($args[0], true); - } elseif (isset($args[1]) && !is_array($args[1])) { - return $this->fetchAll($args[0], false); - } elseif (isset($args[1]) && is_array($args[1])) { - if (isset($args[2])) { - $cache = $args[2]; - } else { - $cache = true; - } - return $this->fetchAll($args[0], $args[1], array('cache' => $cache)); + $cache = true; } + return $this->fetchAll($args[0], $args[1], array('cache' => $cache)); } } @@ -632,9 +630,8 @@ class DboSource extends DataSource { $this->fetchVirtualField($resultRow); } return $resultRow; - } else { - return null; } + return null; } /** diff --git a/lib/Cake/Model/Permission.php b/lib/Cake/Model/Permission.php index 61044445a..16572eb57 100644 --- a/lib/Cake/Model/Permission.php +++ b/lib/Cake/Model/Permission.php @@ -123,33 +123,32 @@ class Permission extends AppModel { if (empty($perms)) { continue; - } else { - $perms = Hash::extract($perms, '{n}.' . $this->alias); - foreach ($perms as $perm) { - if ($action === '*') { + } + $perms = Hash::extract($perms, '{n}.' . $this->alias); + foreach ($perms as $perm) { + if ($action === '*') { - foreach ($permKeys as $key) { - if (!empty($perm)) { - if ($perm[$key] == -1) { - return false; - } elseif ($perm[$key] == 1) { - $inherited[$key] = 1; - } + foreach ($permKeys as $key) { + if (!empty($perm)) { + if ($perm[$key] == -1) { + return false; + } elseif ($perm[$key] == 1) { + $inherited[$key] = 1; } } + } - if (count($inherited) === count($permKeys)) { + if (count($inherited) === count($permKeys)) { + return true; + } + } else { + switch ($perm['_' . $action]) { + case -1: + return false; + case 0: + continue; + case 1: return true; - } - } else { - switch ($perm['_' . $action]) { - case -1: - return false; - case 0: - continue; - case 1: - return true; - } } } } diff --git a/lib/Cake/Model/Validator/CakeValidationRule.php b/lib/Cake/Model/Validator/CakeValidationRule.php index d9df05f7b..1f8134fb7 100644 --- a/lib/Cake/Model/Validator/CakeValidationRule.php +++ b/lib/Cake/Model/Validator/CakeValidationRule.php @@ -148,9 +148,8 @@ class CakeValidationRule { if (in_array($this->required, array('create', 'update'), true)) { if ($this->required === 'create' && !$this->isUpdate() || $this->required === 'update' && $this->isUpdate()) { return true; - } else { - return false; } + return false; } return $this->required; diff --git a/lib/Cake/Network/CakeSocket.php b/lib/Cake/Network/CakeSocket.php index 231261187..43f5318c4 100644 --- a/lib/Cake/Network/CakeSocket.php +++ b/lib/Cake/Network/CakeSocket.php @@ -382,11 +382,10 @@ class CakeSocket { if ($enableCryptoResult === true) { $this->encrypted = $enable; return true; - } else { - $errorMessage = __d('cake_dev', 'Unable to perform enableCrypto operation on CakeSocket'); - $this->setLastError(null, $errorMessage); - throw new SocketException($errorMessage); } + $errorMessage = __d('cake_dev', 'Unable to perform enableCrypto operation on CakeSocket'); + $this->setLastError(null, $errorMessage); + throw new SocketException($errorMessage); } } diff --git a/lib/Cake/Network/Email/CakeEmail.php b/lib/Cake/Network/Email/CakeEmail.php index eb2f07fc2..2d729427e 100644 --- a/lib/Cake/Network/Email/CakeEmail.php +++ b/lib/Cake/Network/Email/CakeEmail.php @@ -1617,9 +1617,8 @@ class CakeEmail { $charset = strtoupper($this->charset); if (array_key_exists($charset, $this->_contentTypeCharset)) { return strtoupper($this->_contentTypeCharset[$charset]); - } else { - return strtoupper($this->charset); } + return strtoupper($this->charset); } } diff --git a/lib/Cake/Test/Case/Model/Behavior/AclBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/AclBehaviorTest.php index 85234fa08..a971fb507 100644 --- a/lib/Cake/Test/Case/Model/Behavior/AclBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/AclBehaviorTest.php @@ -87,9 +87,8 @@ class AclPerson extends CakeTestModel { } if (!$motherId) { return null; - } else { - return array('AclPerson' => array('id' => $motherId)); } + return array('AclPerson' => array('id' => $motherId)); } } diff --git a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php index 1829e3911..57a390069 100644 --- a/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php +++ b/lib/Cake/Test/Case/Model/Behavior/ContainableBehaviorTest.php @@ -3672,11 +3672,10 @@ class ContainableBehaviorTest extends CakeTestCase { if (!is_array($Model)) { $result = $Model->containments($contain); return $this->_containments($result['models']); - } else { - $result = $Model; - foreach ($result as $i => $containment) { - $result[$i] = array_diff_key($containment, array('instance' => true)); - } + } + $result = $Model; + foreach ($result as $i => $containment) { + $result[$i] = array_diff_key($containment, array('instance' => true)); } return $result; } diff --git a/lib/Cake/TestSuite/CakeTestSuiteCommand.php b/lib/Cake/TestSuite/CakeTestSuiteCommand.php index 5d919020f..ab8fca7c2 100644 --- a/lib/Cake/TestSuite/CakeTestSuiteCommand.php +++ b/lib/Cake/TestSuite/CakeTestSuiteCommand.php @@ -122,9 +122,8 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command { exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); } elseif (!isset($result) || $result->errorCount() > 0) { exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); - } else { - exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } + exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } } diff --git a/lib/Cake/Utility/Folder.php b/lib/Cake/Utility/Folder.php index f50465b2e..ca6c4128d 100644 --- a/lib/Cake/Utility/Folder.php +++ b/lib/Cake/Utility/Folder.php @@ -516,11 +516,10 @@ class Folder { umask($old); $this->_messages[] = __d('cake_dev', '%s created', $pathname); return true; - } else { - umask($old); - $this->_errors[] = __d('cake_dev', '%s NOT created', $pathname); - return false; } + umask($old); + $this->_errors[] = __d('cake_dev', '%s NOT created', $pathname); + return false; } } return false; @@ -810,9 +809,8 @@ class Folder { if (!empty($newparts)) { array_pop($newparts); continue; - } else { - return false; } + return false; } $newparts[] = $part; } diff --git a/lib/Cake/Utility/Validation.php b/lib/Cake/Utility/Validation.php index e60acd16d..322527040 100644 --- a/lib/Cake/Utility/Validation.php +++ b/lib/Cake/Utility/Validation.php @@ -816,9 +816,8 @@ class Validation { protected static function _check($check, $regex) { if (is_string($regex) && preg_match($regex, $check)) { return true; - } else { - return false; } + return false; } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index a97c85217..cea2ea1f1 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -205,9 +205,8 @@ class FormHelper extends AppHelper { return $this->fieldset[$model]['fields']; } elseif (isset($this->fieldset[$model]['fields'][$field])) { return $this->fieldset[$model]['fields'][$field]; - } else { - return isset($object->hasAndBelongsToMany[$field]) ? array('type' => 'multiple') : null; } + return isset($object->hasAndBelongsToMany[$field]) ? array('type' => 'multiple') : null; } if ($key === 'errors' && !isset($this->validationErrors[$model])) { @@ -232,10 +231,9 @@ class FormHelper extends AppHelper { if ($key === 'validates') { if (empty($field)) { return $this->fieldset[$model]['validates']; - } else { - return isset($this->fieldset[$model]['validates'][$field]) ? - $this->fieldset[$model]['validates'] : null; } + return isset($this->fieldset[$model]['validates'][$field]) ? + $this->fieldset[$model]['validates'] : null; } } @@ -2572,9 +2570,8 @@ class FormHelper extends AppHelper { if (is_array($options)) { $options[$key] = $name; return $options; - } else { - return $name; } + return $name; } return parent::_name($options, $field, $key); } diff --git a/lib/Cake/View/Helper/PaginatorHelper.php b/lib/Cake/View/Helper/PaginatorHelper.php index 7357abe15..61c5622fc 100644 --- a/lib/Cake/View/Helper/PaginatorHelper.php +++ b/lib/Cake/View/Helper/PaginatorHelper.php @@ -491,22 +491,21 @@ class PaginatorHelper extends AppHelper { } $link = $this->link($title, $url, compact('escape', 'model') + $options); return $this->Html->tag($tag, $link, compact('class')); - } else { - unset($options['rel']); - if (!$tag) { - if ($disabledTag) { - $tag = $disabledTag; - $disabledTag = null; - } else { - $tag = $_defaults['tag']; - } - } - if ($disabledTag) { - $title = $this->Html->tag($disabledTag, $title, compact('escape') + $options); - return $this->Html->tag($tag, $title, compact('class')); - } - return $this->Html->tag($tag, $title, compact('escape', 'class') + $options); } + unset($options['rel']); + if (!$tag) { + if ($disabledTag) { + $tag = $disabledTag; + $disabledTag = null; + } else { + $tag = $_defaults['tag']; + } + } + if ($disabledTag) { + $title = $this->Html->tag($disabledTag, $title, compact('escape') + $options); + return $this->Html->tag($tag, $title, compact('class')); + } + return $this->Html->tag($tag, $title, compact('escape', 'class') + $options); } /** diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index e5234d44e..962d8168f 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -564,9 +564,8 @@ class View extends Object { //@codingStandardsIgnoreEnd unset($out); return false; - } else { - return substr($out, strlen($match[0])); } + return substr($out, strlen($match[0])); } } From f389435baeba04656a1194f1bcc8592fab9137e7 Mon Sep 17 00:00:00 2001 From: euromark Date: Wed, 3 Jul 2013 19:27:17 +0200 Subject: [PATCH 15/16] coding standards and else block simplification --- lib/Cake/Console/Command/SchemaShell.php | 6 +-- lib/Cake/Console/Command/Task/ModelTask.php | 2 +- lib/Cake/Console/Command/Task/ViewTask.php | 3 +- lib/Cake/Controller/Scaffold.php | 7 ++-- lib/Cake/Model/Model.php | 4 +- lib/Cake/Utility/Hash.php | 1 - lib/Cake/View/Helper/FormHelper.php | 3 +- lib/Cake/View/Helper/HtmlHelper.php | 9 ++-- lib/Cake/basics.php | 46 ++++++++++----------- 9 files changed, 37 insertions(+), 44 deletions(-) diff --git a/lib/Cake/Console/Command/SchemaShell.php b/lib/Cake/Console/Command/SchemaShell.php index c45988b67..314502af4 100644 --- a/lib/Cake/Console/Command/SchemaShell.php +++ b/lib/Cake/Console/Command/SchemaShell.php @@ -327,7 +327,7 @@ class SchemaShell extends AppShell { $this->out("\n" . __d('cake_console', 'The following table(s) will be dropped.')); $this->out(array_keys($drop)); - if ('y' == $this->in(__d('cake_console', 'Are you sure you want to drop the table(s)?'), array('y', 'n'), 'n')) { + if ($this->in(__d('cake_console', 'Are you sure you want to drop the table(s)?'), array('y', 'n'), 'n') === 'y') { $this->out(__d('cake_console', 'Dropping table(s).')); $this->_run($drop, 'drop', $Schema); } @@ -335,7 +335,7 @@ class SchemaShell extends AppShell { $this->out("\n" . __d('cake_console', 'The following table(s) will be created.')); $this->out(array_keys($create)); - if ('y' == $this->in(__d('cake_console', 'Are you sure you want to create the table(s)?'), array('y', 'n'), 'y')) { + if ($this->in(__d('cake_console', 'Are you sure you want to create the table(s)?'), array('y', 'n'), 'y') === 'y') { $this->out(__d('cake_console', 'Creating table(s).')); $this->_run($create, 'create', $Schema); } @@ -378,7 +378,7 @@ class SchemaShell extends AppShell { $this->out("\n" . __d('cake_console', 'The following statements will run.')); $this->out(array_map('trim', $contents)); - if ('y' == $this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n')) { + if ($this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n') === 'y') { $this->out(); $this->out(__d('cake_console', 'Updating Database...')); $this->_run($contents, 'update', $Schema); diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index 0ff102454..525149398 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -657,7 +657,7 @@ class ModelTask extends BakeTask { $prompt = "{$model->name} {$type} {$assoc['alias']}?"; $response = $this->in($prompt, array('y', 'n'), 'y'); - if ('n' == strtolower($response)) { + if (strtolower($response) === 'n') { unset($associations[$type][$i]); } elseif ($type === 'hasMany') { unset($associations['hasOne'][$i]); diff --git a/lib/Cake/Console/Command/Task/ViewTask.php b/lib/Cake/Console/Command/Task/ViewTask.php index 38ceb5c5c..e38fd2ab0 100644 --- a/lib/Cake/Console/Command/Task/ViewTask.php +++ b/lib/Cake/Console/Command/Task/ViewTask.php @@ -335,9 +335,8 @@ class ViewTask extends BakeTask { if (strtolower($looksGood) === 'y') { $this->bake($action, ' '); return $this->_stop(); - } else { - $this->out(__d('cake_console', 'Bake Aborted.')); } + $this->out(__d('cake_console', 'Bake Aborted.')); } /** diff --git a/lib/Cake/Controller/Scaffold.php b/lib/Cake/Controller/Scaffold.php index 477b8c9d5..c63ab7b32 100644 --- a/lib/Cake/Controller/Scaffold.php +++ b/lib/Cake/Controller/Scaffold.php @@ -252,10 +252,9 @@ class Scaffold { return $this->_sendMessage($message); } return $this->controller->afterScaffoldSaveError($action); - } else { - if ($this->_validSession) { - $this->controller->Session->setFlash(__d('cake', 'Please correct errors below.')); - } + } + if ($this->_validSession) { + $this->controller->Session->setFlash(__d('cake', 'Please correct errors below.')); } } diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 09418910b..d90f9e52a 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1255,11 +1255,11 @@ class Model extends Object implements CakeEventListener { isset($data['meridian']) && !empty($data['hour']) && $data['hour'] != 12 && - 'pm' == $data['meridian'] + $data['meridian'] === 'pm' ) { $data['hour'] = $data['hour'] + 12; } - if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] == 12 && 'am' == $data['meridian']) { + if (isset($data['hour']) && isset($data['meridian']) && $data['hour'] == 12 && $data['meridian'] === 'am') { $data['hour'] = '00'; } if ($type === 'time') { diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 607158b94..a0f64ebee 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -54,7 +54,6 @@ class Hash { } else { return null; } - } return $data; } diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index cea2ea1f1..1f6773bd3 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -731,9 +731,8 @@ class FormHelper extends AppHelper { $tag = is_string($options['wrap']) ? $options['wrap'] : 'div'; unset($options['wrap']); return $this->Html->tag($tag, $error, $options); - } else { - return $error; } + return $error; } /** diff --git a/lib/Cake/View/Helper/HtmlHelper.php b/lib/Cake/View/Helper/HtmlHelper.php index 9ad868eac..5dd729f4f 100644 --- a/lib/Cake/View/Helper/HtmlHelper.php +++ b/lib/Cake/View/Helper/HtmlHelper.php @@ -289,9 +289,8 @@ class HtmlHelper extends AppHelper { if (empty($options['block'])) { return $out; - } else { - $this->_View->append($options['block'], $out); } + $this->_View->append($options['block'], $out); } /** @@ -451,9 +450,8 @@ class HtmlHelper extends AppHelper { if (empty($options['block'])) { return $out; - } else { - $this->_View->append($options['block'], $out); } + $this->_View->append($options['block'], $out); } /** @@ -674,9 +672,8 @@ class HtmlHelper extends AppHelper { } } return implode($separator, $out); - } else { - return null; } + return null; } /** diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index 538de3f00..14b31cb14 100644 --- a/lib/Cake/basics.php +++ b/lib/Cake/basics.php @@ -470,29 +470,6 @@ if (!function_exists('clearCache')) { return false; } - foreach ($files as $file) { - if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) { - //@codingStandardsIgnoreStart - @unlink($file); - //@codingStandardsIgnoreEnd - } - } - return true; - } else { - $cache = array( - CACHE . $type . DS . '*' . $params . $ext, - CACHE . $type . DS . '*' . $params . '_*' . $ext - ); - $files = array(); - while ($search = array_shift($cache)) { - $results = glob($search); - if ($results !== false) { - $files = array_merge($files, $results); - } - } - if (empty($files)) { - return false; - } foreach ($files as $file) { if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) { //@codingStandardsIgnoreStart @@ -502,6 +479,29 @@ if (!function_exists('clearCache')) { } return true; } + $cache = array( + CACHE . $type . DS . '*' . $params . $ext, + CACHE . $type . DS . '*' . $params . '_*' . $ext + ); + $files = array(); + while ($search = array_shift($cache)) { + $results = glob($search); + if ($results !== false) { + $files = array_merge($files, $results); + } + } + if (empty($files)) { + return false; + } + foreach ($files as $file) { + if (is_file($file) && strrpos($file, DS . 'empty') !== strlen($file) - 6) { + //@codingStandardsIgnoreStart + @unlink($file); + //@codingStandardsIgnoreEnd + } + } + return true; + } elseif (is_array($params)) { foreach ($params as $file) { clearCache($file, $type, $ext); From 36d8473215007dce853a2c5b8ee1bbad03213844 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 2 Jul 2013 17:28:28 -0400 Subject: [PATCH 16/16] Make check for `..` more specific. A `..` anywhere in the classname is invalid. --- lib/Cake/Core/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Core/App.php b/lib/Cake/Core/App.php index 4913c7cc3..fad7b83a1 100644 --- a/lib/Cake/Core/App.php +++ b/lib/Cake/Core/App.php @@ -535,7 +535,7 @@ class App { if (!isset(self::$_classMap[$className])) { return false; } - if (strpos($className, '..')) { + if (strpos($className, '..') !== false) { return false; }