0

There are phpstan configuration files in the phpword sources https://github.com/PHPOffice/PHPWord/tree/0.18.2 , but composer does not include these on phpword installation, thus there are none of these in the vendor directory.

[screenshot]

Any alternative solutions are also welcome.

The root cause is phpstan warning:

 Class PhpOffice\PhpWord\Writer\PDF\MPDF referenced with incorrect case: PhpOffice\PhpWord\Writer\PDF\Mpdf.

Runs on: PHP 8.0, laravel 8, phpstan 1.10.25, phpword 0.18.2

Thanks

  • The `phpstan.neon` file in the PHPWord repository is for PHPWord itself being analysed by PHPStan. It's not relevant to you if you're a user of PHPWord. You're not supposed to include that file in your project that uses PHPWord. – Ondřej Mirtes Jul 25 '23 at 08:26

1 Answers1

0

The phpstan.neon file in the PHPWord repository is for PHPWord itself being analysed by PHPStan. It's not relevant to you if you're a user of PHPWord. You're not supposed to include that file in your project that uses PHPWord.

The error reported by PHPStan is correct:

  Class PhpOffice\PhpWord\Writer\PDF\MPDF referenced with incorrect case: PhpOffice\PhpWord\Writer\PDF\Mpdf.

The class is called MPDF, not Mpdf: https://github.com/PHPOffice/PHPWord/blob/0.18.2/src/PhpWord/Writer/PDF/MPDF.php

So in order to fix the error reported by PHPStan, you need to reference the class by its correct name in your source code: MPDF

Although class names in PHP are case-insensitive, PHPStan chooses to report this as a problem, because historically, there might be problems with certain autoloaders and running PHP applications on file systems with different case sensitivity, like Windows vs. Linux.

So under certain circumstances, Mpdf class might be found on Windows, because MPDF.php is the same as Mpdf.php and the class will load, but the same application might not run on Linux, because Mpdf.php and MPDF.php aren't the same file.

Ondřej Mirtes
  • 5,054
  • 25
  • 36