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

Psalm support is unclear from README.md #408

Open
alies-dev opened this issue Jan 27, 2023 · 1 comment
Open

Psalm support is unclear from README.md #408

alies-dev opened this issue Jan 27, 2023 · 1 comment

Comments

@alies-dev
Copy link

There is a link to PHPStan plugin for for the package, but Psalm support is unclear from the README. What is the status?

@jack-worman
Copy link

I wrote a plugin that will add all non-safe functions to the forbidden function list.
Feel free to use it:

class Plugin implements PluginEntryPointInterface
{
    public function __invoke(RegistrationInterface $registration, ?\SimpleXMLElement $config = null): void
    {
        /** @psalm-suppress InternalClass,InternalMethod */
        $config = ProjectAnalyzer::getInstance()->getCodebase()->config;
        $forbiddenFunctions = &$config->forbidden_functions;
        $deprecatedSafeFunctions = [
            'safe\\sprintf' => true,
            'safe\\ksort' => true,
            'safe\\usort' => true,
            'safe\\array_flip' => true,
            'safe\\substr' => true,
            'safe\\sort' => true,
            'safe\\asort' => true,
            'safe\\password_hash' => true,
            'safe\\sleep' => true,
        ];
        foreach (\get_defined_functions()['user'] as $functionName) {
            if (!\str_starts_with($functionName, 'safe\\')) {
                continue;
            }
            if (isset($deprecatedSafeFunctions[$functionName])) {
                unset($deprecatedSafeFunctions[$functionName]);
                continue;
            }
            $forbiddenFunctions[\substr($functionName, 5)] = true;
        }
        if ($deprecatedSafeFunctions !== []) {
            throw new \Exception('$deprecatedSafeFunctions has unused keys: ' . \var_export($deprecatedSafeFunctions, true));
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants