Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform some stan related code updates #92

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
"symfony/polyfill-mbstring": "^1.12"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.3",
"ext-mbstring": "*",
"friendsofphp/php-cs-fixer": "^3",
"ext-mbstring": "*"
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.13.5"
},
"autoload": {
"classmap": [
Expand Down
42 changes: 42 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\FuncCall\IntvalToTypeCastRector;
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Php80\Rector\FunctionLike\UnionTypesRector;
use Rector\PostRector\Rector\NameImportingPostRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rector_config): void {
// Path to phpstan with extensions, that PHPSTan in Rector uses to determine types
$rector_config->phpstanConfig(__DIR__ . '/phpstan.neon');

// Define what rule sets will be applied
$rector_config->import(SetList::DEAD_CODE);
$rector_config->skip([
StringClassNameToClassConstantRector::class,
UnionTypesRector::class,
JsonThrowOnErrorRector::class,

]);

// define sets of rules
$rector_config->sets([
LevelSetList::UP_TO_PHP_81,
]);

$services = $rector_config->services();

$services->set(TypedPropertyRector::class);
$services->set(IntvalToTypeCastRector::class);
$services->set(AddLiteralSeparatorToNumberRector::class);
$services->set(ClosureToArrowFunctionRector::class);
$services->set(NameImportingPostRector::class);
};
2 changes: 1 addition & 1 deletion src/Dom/SaxXmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private function checkEncoding(string $str): string
$forbid = '/((?>[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F]+))/s';

if (preg_match($forbid, $str)) {
$str = preg_replace_callback($forbid, ['self', 'convertBytesToEntities'], $str);
$str = preg_replace_callback($forbid, fn (array $element): string => self::convertBytesToEntities($element), $str);
$this->raiseError('Invalid ISO-8859-1 characters: ' . $str);
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Exception/TemplateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ private function findFileAndLine(): array
}

$eval_line = 0;
$eval_path = null;

// searches backtrace to find template file
foreach ($this->getTrace() as $tr) {
Expand All @@ -135,9 +134,9 @@ private function findFileAndLine(): array

// PHPTAL.php uses eval() on first run to catch fatal errors. This makes template path invisible.
// However, function name matches template path and eval() is visible in backtrace.
if (strpos($tr['file'], 'eval()') !== false) {
if (str_contains($tr['file'], 'eval()')) {
$eval_line = $tr['line'];
} elseif ($eval_line && isset($tr['function'], $tr['args'][0]) &&
} elseif ($eval_line && isset($tr['args'][0]) &&
$this->isTemplatePath('/' . $tr['function'] . '.php') && $tr['args'][0] instanceof PHPTAL) {
return [$tr['args'][0]->getCodePath(), $eval_line];
}
Expand Down