Skip to content

Commit

Permalink
Upgraded to rector 0.17 & removed protected function getVarType in th…
Browse files Browse the repository at this point in the history
…e Renderer class
  • Loading branch information
rotimi committed Aug 17, 2023
1 parent 5dd8b37 commit 6064562
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 61 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedCode="false"
findUnusedBaselineEntry="true"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//$containerConfigurator->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);
Expand Down
27 changes: 5 additions & 22 deletions src/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) ) {
Expand Down Expand Up @@ -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.
Expand All @@ -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`
Expand All @@ -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);
}
}
2 changes: 0 additions & 2 deletions tests/FileRendererWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
35 changes: 0 additions & 35 deletions tests/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 6064562

Please sign in to comment.