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

1
  • 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. Commented Jul 25, 2023 at 8:26

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

But it runs perfectly fine in a container based on Linux image
Whats more, it is PhpOffice class that gets reported by PhpStan, not the application one
This is the the problem line : github.com/PHPOffice/PHPWord/blob/…
In that case send a PR to PHPWord that fixes that PHPDoc :) Problem solved.
0

In your phpstan.neon.dist, you can let phpstan ignore certain errors. in your case:

parameters:
    ignoreErrors: 
        - identifier: class.nameCase

This should solve your problem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.