From 6064562284a788d937727c53344b1f4278c29426 Mon Sep 17 00:00:00 2001 From: rotimi Date: Thu, 17 Aug 2023 00:48:53 -0600 Subject: [PATCH] Upgraded to rector 0.17 & removed protected function getVarType in the Renderer class --- composer.json | 2 +- psalm.xml | 2 ++ rector.php | 2 +- src/Renderer.php | 27 +++++---------------------- tests/FileRendererWrapper.php | 2 -- tests/RendererTest.php | 35 ----------------------------------- 6 files changed, 9 insertions(+), 61 deletions(-) diff --git a/composer.json b/composer.json index 38ef9a9..14c2f96 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "phpunit/phpunit": "^9.0", "php-coveralls/php-coveralls": "^2.0", - "rector/rector": "^0.15.0", + "rector/rector": "^0.17.0", "vimeo/psalm": "^5.4" }, "autoload": { diff --git a/psalm.xml b/psalm.xml index 3240886..bd44196 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,8 @@ import(SetList::PHP_80); //$containerConfigurator->import(SetList::PHP_81); - $containerConfigurator->import(SetList::PSR_4); + //$containerConfigurator->import(SetList::PSR_4); $containerConfigurator->import(SetList::DEAD_CODE); $containerConfigurator->import(SetList::CODE_QUALITY); $containerConfigurator->import(SetList::TYPE_DECLARATION); diff --git a/src/Renderer.php b/src/Renderer.php index 0749210..1101b64 100644 --- a/src/Renderer.php +++ b/src/Renderer.php @@ -277,7 +277,7 @@ public function __construct( $this->data_vars_2_html_escape = $data_vars_2_html_escape; $this->data_vars_2_html_attr_escape = $data_vars_2_html_attr_escape; - $encoding = empty($escape_encoding)? 'utf-8' : $escape_encoding; + $encoding = $escape_encoding === ''? 'utf-8' : $escape_encoding; $this->escaper = new Escaper($encoding); } @@ -880,8 +880,8 @@ protected function escapeData( return; } - $final_encoding = (empty($escape_encoding)) - ? ((empty($this->escape_encoding))? 'utf-8' : $this->escape_encoding) + $final_encoding = ($escape_encoding === '') + ? ( ($this->escape_encoding === '') ? 'utf-8' : $this->escape_encoding) : $escape_encoding; if( is_null($escaper) ) { @@ -975,11 +975,11 @@ public function locateFile(string $file_name): string { //Check if file actually exists as is (if a path was prepended to it). $located_file = ( - !empty($file_name) && file_exists($file_name) + $file_name !== '' && file_exists($file_name) && is_file($file_name) && $file_name_contains_path ) ? $file_name : ''; - if( $located_file === '' && !empty($file_name) ) { + if( $located_file === '' && $file_name !== '' ) { //$file_name is not an existent file on its own. //Search for it in the list of paths registered in $this->file_paths. @@ -1005,7 +1005,6 @@ public function locateFile(string $file_name): string { * Trims off the right-most character at the end of the string `$file_path` * if it is a directory separator charater (ie. '\' or '/'). * - * * @return string `$file_path` as is if right-most character at the end of the * string is not a directory separator charater (ie. '\' or '/'). * If the right-most character at the end of the string `$file_path` @@ -1027,20 +1026,4 @@ protected function normalizeFolderPath(string $file_path): string { return $trimed_path; } - - /** - * - * An enhancement to PHP's gettype function that displays the class name of a variable if the variable is an object. - * - * @param mixed $var a variable whose type is to be determined. - * @param bool $cap_first flag to indicate if the variable's type should be returned with the first letter in uppercase. - * - * @return string the variable's type. - */ - protected function getVarType($var, bool $cap_first=false): string { - - if( is_object($var) ) { return $cap_first ? ucfirst(get_class($var)) : get_class($var); } - - return $cap_first ? ucfirst(gettype($var)) : gettype($var); - } } diff --git a/tests/FileRendererWrapper.php b/tests/FileRendererWrapper.php index 49aca00..35a5fdc 100644 --- a/tests/FileRendererWrapper.php +++ b/tests/FileRendererWrapper.php @@ -27,8 +27,6 @@ public function escapeDataPublic( public function normalizeFolderPathPublic($f_path) { return parent::normalizeFolderPath($f_path); } - public function getVarTypePublic($var, $cap_1st=false) { return parent::getVarType($var, $cap_1st); } - public function doRenderPublic(string $file_to_include, array $data) { return parent::doRender($file_to_include, $data); } diff --git a/tests/RendererTest.php b/tests/RendererTest.php index ef176bf..b4723c2 100644 --- a/tests/RendererTest.php +++ b/tests/RendererTest.php @@ -404,41 +404,6 @@ public function testThatNormalizeFolderPathWorksAsExpected() { $this->assertEquals("/var/www/html", $renderer->normalizeFolderPathPublic('/var/www/html/')); } - public function testThatGetVarTypeWorksAsExpected() { - - $renderer = new FileRendererWrapper('file.txt'); - - //object - $this->assertEquals("Rotexsoft\\FileRenderer\\Tests\\FileRendererWrapper", $renderer->getVarTypePublic($renderer)); - $this->assertEquals("Rotexsoft\\FileRenderer\\Tests\\FileRendererWrapper", $renderer->getVarTypePublic($renderer, true)); - - //string - $this->assertEquals("string", $renderer->getVarTypePublic('sfff')); - $this->assertEquals("String", $renderer->getVarTypePublic('sfff', true)); - - //array - $this->assertEquals("array", $renderer->getVarTypePublic([])); - $this->assertEquals("Array", $renderer->getVarTypePublic([], true)); - - //boolean - $this->assertEquals("boolean", $renderer->getVarTypePublic(false)); - $this->assertEquals("Boolean", $renderer->getVarTypePublic(false, true)); - - //int - $this->assertEquals("integer", $renderer->getVarTypePublic(123)); - $this->assertEquals("Integer", $renderer->getVarTypePublic(123, true)); - - //float a.k.a double - $this->assertEquals("double", $renderer->getVarTypePublic(123.456)); - $this->assertEquals("Double", $renderer->getVarTypePublic(123.456, true)); - - //resource - $temp = tmpfile(); - $this->assertEquals("resource", $renderer->getVarTypePublic($temp)); - $this->assertEquals("Resource", $renderer->getVarTypePublic($temp, true)); - fclose($temp); // this removes the file - } - public function testThatLocateFileWorksAsExpected() { $file_name = 'fizaile';