mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
[BUGFIX] Check if argument is string (#146)
Resolves: https://github.com/rectorphp/rector/issues/6482
This commit is contained in:
parent
1913747f01
commit
df07500a76
|
@ -4,7 +4,7 @@ namespace Rector\Tests\PHPOffice\Rector\StaticCall\ChangePdfWriterRector\Fixture
|
|||
|
||||
final class Fixture
|
||||
{
|
||||
public function run(): void
|
||||
public function run(string $format): void
|
||||
{
|
||||
\PHPExcel_Settings::setPdfRendererName(PHPExcel_Settings::PDF_RENDERER_MPDF);
|
||||
\PHPExcel_Settings::setPdfRenderer($somePath);
|
||||
|
@ -20,7 +20,7 @@ namespace Rector\Tests\PHPOffice\Rector\StaticCall\ChangePdfWriterRector\Fixture
|
|||
|
||||
final class Fixture
|
||||
{
|
||||
public function run(): void
|
||||
public function run(string $format): void
|
||||
{
|
||||
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\PHPOffice\Rector\StaticCall\ChangePdfWriterRector\Fixture;
|
||||
|
||||
final class VariableFormatFixture
|
||||
{
|
||||
public function run(string $format): void
|
||||
{
|
||||
$writer = \PHPExcel_IOFactory::createWriter($spreadsheet, $format);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\PHPOffice\Rector\StaticCall\ChangePdfWriterRector\Fixture;
|
||||
|
||||
final class VariableFormatFixture
|
||||
{
|
||||
public function run(string $format): void
|
||||
{
|
||||
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, $format);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -3,9 +3,18 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use Rector\PHPOffice\Rector\StaticCall\ChangePdfWriterRector;
|
||||
use Rector\Renaming\Rector\Name\RenameClassRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
$services->set(ChangePdfWriterRector::class);
|
||||
|
||||
$services->set(RenameClassRector::class)
|
||||
->call('configure', [[
|
||||
RenameClassRector::OLD_TO_NEW_CLASSES => [
|
||||
'PHPExcel_IOFactory' => 'PhpOffice\PhpSpreadsheet\IOFactory',
|
||||
]
|
||||
]
|
||||
]);
|
||||
};
|
||||
|
|
|
@ -80,6 +80,11 @@ CODE_SAMPLE
|
|||
}
|
||||
|
||||
$secondArgValue = $this->valueResolver->getValue($node->args[1]->value);
|
||||
|
||||
if(! is_string($secondArgValue)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Strings::match($secondArgValue, '#pdf#i')) {
|
||||
return new New_(new FullyQualified('PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf'), [$node->args[0]]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user