From 2f74e10d8f5557deda756121c62dce8e79360d44 Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Thu, 7 Mar 2019 19:20:33 -0800 Subject: [PATCH 1/4] Synch --- system/CodeIgniter.php | 2 +- system/Controller.php | 5 +++-- system/Debug/Exceptions.php | 2 +- system/HTTP/Files/UploadedFile.php | 2 +- system/HTTP/Request.php | 2 +- system/Helpers/form_helper.php | 2 +- system/Helpers/text_helper.php | 4 ++-- system/Language/en/HTTP.php | 20 ++++++++++---------- system/Router/RouteCollection.php | 2 +- system/Session/Handlers/MemcachedHandler.php | 4 ++-- system/Session/Session.php | 4 ++-- tests/system/Helpers/FormHelperTest.php | 17 +++++------------ 12 files changed, 30 insertions(+), 36 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 5de6b65b9705..ea3c3514c0ed 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -533,7 +533,7 @@ protected function forceSecureAccess($duration = 31536000) * * @throws \Exception * - * @return bool|\CodeIgniter\HTTP\ResponseInterface + * @return boolean|\CodeIgniter\HTTP\ResponseInterface */ public function displayCache($config) { diff --git a/system/Controller.php b/system/Controller.php index ea5f0f3222e6..e5d03656d64d 100644 --- a/system/Controller.php +++ b/system/Controller.php @@ -35,6 +35,7 @@ * @since Version 3.0.0 * @filesource */ + use CodeIgniter\Config\Services; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; @@ -179,8 +180,8 @@ protected function loadHelpers() * A shortcut to performing validation on input data. If validation * is not successful, a $errors property will be set on this class. * - * @param array|string $rules - * @param array $messages An array of custom error messages + * @param array|string $rules + * @param array $messages An array of custom error messages * * @return boolean */ diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 7942357616ab..41c4bb67904b 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -261,7 +261,7 @@ protected function render(\Throwable $exception, int $statusCode) if (empty($path)) { $paths = new Paths(); - $path = $paths->viewDirectory . '/errors/'; + $path = $paths->viewDirectory . '/errors/'; } $path = is_cli() diff --git a/system/HTTP/Files/UploadedFile.php b/system/HTTP/Files/UploadedFile.php index 5c61f76301f8..b4b97fc3818a 100644 --- a/system/HTTP/Files/UploadedFile.php +++ b/system/HTTP/Files/UploadedFile.php @@ -273,7 +273,7 @@ public function getErrorString() UPLOAD_ERR_NO_FILE => lang('HTTP.uploadErrNoFile'), UPLOAD_ERR_CANT_WRITE => lang('HTTP.uploadErrCantWrite'), UPLOAD_ERR_NO_TMP_DIR => lang('HTTP.uploadErrNoTmpDir'), - UPLOAD_ERR_EXTENSION => lang('HTTP.uploadErrExtension') + UPLOAD_ERR_EXTENSION => lang('HTTP.uploadErrExtension'), ]; $error = is_null($this->error) ? UPLOAD_ERR_OK : $this->error; diff --git a/system/HTTP/Request.php b/system/HTTP/Request.php index 27840e604d1c..a8141637b513 100644 --- a/system/HTTP/Request.php +++ b/system/HTTP/Request.php @@ -409,7 +409,7 @@ public function fetchGlobal($method, $index = null, $filter = null, $flags = nul } } - if (!isset($value)) + if (! isset($value)) { $value = $this->globals[$method][$index] ?? null; } diff --git a/system/Helpers/form_helper.php b/system/Helpers/form_helper.php index 4f21effbc568..f7a299ebb925 100644 --- a/system/Helpers/form_helper.php +++ b/system/Helpers/form_helper.php @@ -65,7 +65,7 @@ function form_open(string $action = '', $attributes = [], array $hidden = []): s $action = site_url($action); } - if(is_array($attributes) && array_key_exists('csrf_id', $attributes)) + if (is_array($attributes) && array_key_exists('csrf_id', $attributes)) { $csrfId = $attributes['csrf_id']; unset($attributes['csrf_id']); diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index 52f61b2afc56..fbf36e7c81cb 100755 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -460,7 +460,7 @@ function convert_accented_characters(string $str): string * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor * will URLs. * - * @param string $str the text string + * @param string $str the text string * @param integer $charlim = 76 the number of characters to wrap at * * @return string @@ -604,7 +604,7 @@ function ellipsize(string $str, int $max_length, $position = 1, string $ellipsis * * Removes slashes contained in a string or in an array * - * @param mixed $str string or array + * @param mixed $str string or array * * @return mixed string or array */ diff --git a/system/Language/en/HTTP.php b/system/Language/en/HTTP.php index eb0b29cdd4f2..6b423bbb8768 100644 --- a/system/Language/en/HTTP.php +++ b/system/Language/en/HTTP.php @@ -64,14 +64,14 @@ 'alreadyMoved' => 'The uploaded file has already been moved.', 'invalidFile' => 'The original file is not a valid file.', 'moveFailed' => 'Could not move file {0} to {1} ({2})', - - 'uploadErrOk' => 'The file uploaded with success.', - 'uploadErrIniSize' => 'The file "%s" exceeds your upload_max_filesize ini directive.', - 'uploadErrFormSize' => 'The file "%s" exceeds the upload limit defined in your form.', - 'uploadErrPartial' => 'The file "%s" was only partially uploaded.', - 'uploadErrNoFile' => 'No file was uploaded.', - 'uploadErrCantWrite' => 'The file "%s" could not be written on disk.', - 'uploadErrNoTmpDir' => 'File could not be uploaded: missing temporary directory.', - 'uploadErrExtension' => 'File upload was stopped by a PHP extension.', - 'uploadErrUnknown' => 'The file "%s" was not uploaded due to an unknown error.' + + 'uploadErrOk' => 'The file uploaded with success.', + 'uploadErrIniSize' => 'The file "%s" exceeds your upload_max_filesize ini directive.', + 'uploadErrFormSize' => 'The file "%s" exceeds the upload limit defined in your form.', + 'uploadErrPartial' => 'The file "%s" was only partially uploaded.', + 'uploadErrNoFile' => 'No file was uploaded.', + 'uploadErrCantWrite' => 'The file "%s" could not be written on disk.', + 'uploadErrNoTmpDir' => 'File could not be uploaded: missing temporary directory.', + 'uploadErrExtension' => 'File upload was stopped by a PHP extension.', + 'uploadErrUnknown' => 'The file "%s" was not uploaded due to an unknown error.', ]; diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index dbe44facd787..3ffde19b1442 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -222,7 +222,7 @@ class RouteCollection implements RouteCollectionInterface /** * Constructor * - * @param FileLocator $locator + * @param FileLocator $locator * @param \Config\Modules $moduleConfig */ public function __construct(FileLocator $locator, $moduleConfig) diff --git a/system/Session/Handlers/MemcachedHandler.php b/system/Session/Handlers/MemcachedHandler.php index d5c9c110c246..8a786e52e2f2 100644 --- a/system/Session/Handlers/MemcachedHandler.php +++ b/system/Session/Handlers/MemcachedHandler.php @@ -94,8 +94,8 @@ public function __construct(BaseConfig $config, string $ipAddress) { $this->keyPrefix .= $this->ipAddress . ':'; } - - if(!empty($this->keyPrefix)) + + if (! empty($this->keyPrefix)) { ini_set('memcached.sess_prefix', $this->keyPrefix); } diff --git a/system/Session/Session.php b/system/Session/Session.php index 3780c2e0f303..4d37ab0c0374 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -303,8 +303,8 @@ protected function configure() { ini_set('session.gc_maxlifetime', (int) $this->sessionExpiration); } - - if(!empty($this->sessionSavePath)) + + if (! empty($this->sessionSavePath)) { ini_set('session.save_path', $this->sessionSavePath); } diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index 4c97b0706233..f5bfaffe8496 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -811,16 +811,14 @@ public function testSetRadioDefault() $this->assertEquals(' checked="checked"', set_radio('code', 'alpha', true)); $this->assertEquals('', set_radio('code', 'beta', false)); } - - + // ------------------------------------------------------------------------ public function testFormParseFormAttributesTrue() { $expected = 'readonly '; $this->assertEquals($expected, parse_form_attributes(['readonly' => true], [])); } - - + // ------------------------------------------------------------------------ public function testFormParseFormAttributesFalse() { @@ -828,23 +826,20 @@ public function testFormParseFormAttributesFalse() $this->assertEquals($expected, parse_form_attributes(['disabled' => false], [])); } - // ------------------------------------------------------------------------ public function testFormParseFormAttributesNull() { $expected = 'bar="" '; $this->assertEquals($expected, parse_form_attributes(['bar' => null], [])); } - - + // ------------------------------------------------------------------------ public function testFormParseFormAttributesStringEmpty() { $expected = 'bar="" '; $this->assertEquals($expected, parse_form_attributes(['bar' => ''], [])); } - - + // ------------------------------------------------------------------------ public function testFormParseFormAttributesStringFoo() { @@ -852,15 +847,13 @@ public function testFormParseFormAttributesStringFoo() $this->assertEquals($expected, parse_form_attributes(['bar' => 'foo'], [])); } - // ------------------------------------------------------------------------ public function testFormParseFormAttributesInt0() { $expected = 'ok="0" '; $this->assertEquals($expected, parse_form_attributes(['ok' => 0], [])); } - - + // ------------------------------------------------------------------------ public function testFormParseFormAttributesInt1() { From abab1912af9c1e0cffa4a3be085f458c06db436f Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Mon, 11 Mar 2019 13:40:21 -0700 Subject: [PATCH 2/4] Test: improve Filters module coverage --- system/Filters/CSRF.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/system/Filters/CSRF.php b/system/Filters/CSRF.php index c9a47d55ede9..914e6191710a 100644 --- a/system/Filters/CSRF.php +++ b/system/Filters/CSRF.php @@ -34,6 +34,10 @@ * @link https://codeigniter.com * @since Version 3.0.0 * @filesource + * + * This filter is not intended to be used from the command line. + * + * @codeCoverageIgnore */ use CodeIgniter\Filters\FilterInterface; @@ -42,6 +46,11 @@ use CodeIgniter\Security\Exceptions\SecurityException; use Config\Services; +/** + * This filter is not intended to be used from the command line. + * + * @codeCoverageIgnore + */ class CSRF implements FilterInterface { /** From 23b42fa31a1ae1de5317edf186b8e53d20f08a78 Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Mon, 11 Mar 2019 14:14:51 -0700 Subject: [PATCH 3/4] Fix: Model::save call to insert --- system/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Model.php b/system/Model.php index 6e31d2887fa8..1a73eecf6b8b 100644 --- a/system/Model.php +++ b/system/Model.php @@ -479,7 +479,7 @@ public function save($data) } else { - $response = $this->insert($data); + $response = $this->insert($data, false); } return $response; From d233bc6e1596b8561a5646afc29496230655fbd0 Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Mon, 11 Mar 2019 14:55:56 -0700 Subject: [PATCH 4/4] Fix: Craft save() response based on insert() --- system/Model.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/Model.php b/system/Model.php index 6e1e42e6451a..b44982b04e86 100644 --- a/system/Model.php +++ b/system/Model.php @@ -480,6 +480,11 @@ public function save($data): bool else { $response = $this->insert($data, false); + // call insert directly if you want the ID or the record object + if ($response !== false) + { + $response = true; + } } return $response;