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/phar and github phar works differently from vimeo/psalm #9394

Closed
andraaspar opened this issue Feb 24, 2023 · 8 comments · Fixed by #10748
Closed

psalm/phar and github phar works differently from vimeo/psalm #9394

andraaspar opened this issue Feb 24, 2023 · 8 comments · Fixed by #10748

Comments

@andraaspar
Copy link

I have a simple class src\Foo.php:

<?php

/**
 * @template T
 * @implements IteratorAggregate<string,T>
 */
class Foo implements IteratorAggregate
{
	/**
	 * @var array<string, T>
	 */
	private $data;
	
	/**
	 * @param array<string, T> $data
	 */
	public function __construct(array $data = [])
	{
		$this->data = $data;
	}
	
	/**
	 * @return ArrayIterator
	 */
	#[\ReturnTypeWillChange]
	public function getIterator()
	{
		return new ArrayIterator($this->data);
	}
}

And psalm.xml:

<?xml version="1.0"?>
<psalm
	xmlns="https://getpsalm.org/schema/config"
	errorLevel="1"
	ignoreInternalFunctionFalseReturn="false"
	ignoreInternalFunctionNullReturn="false"
	cacheDirectory=".psalm-cache"
	phpVersion="5.6"
	findUnusedCode="false"
>
	<projectFiles>
		<directory name="src"/>
	</projectFiles>
</psalm>

When I install psalm using composer:

> composer require --dev vimeo/psalm
...
Using version ^5.7 for vimeo/psalm
> .\vendor\bin\psalm.bat --no-cache
Warning: "findUnusedBaselineEntry" will be defaulted to "true" in Psalm 6. You should explicitly enable or disable this setting.

Install the opcache extension to make use of JIT on PHP 8.0+ for a 20%+ performance boost!

Target PHP version: 5.6 (set by config file).
Scanning files...
Analyzing files...

░
------------------------------
                              
       No errors found!       
                              
------------------------------

Checks took 0.49 seconds and used 73.594MB of memory
Psalm was able to infer types for 100% of the codebase

If I install psalm/phar instead:

> composer remove --dev vimeo/psalm
> composer require --dev psalm/phar
...
Using version ^5.7 for psalm/phar
> .\vendor\bin\psalm.phar.bat --no-cache
Warning: "findUnusedBaselineEntry" will be defaulted to "true" in Psalm 6. You should explicitly enable or disable this setting.

Install the opcache extension to make use of JIT on PHP 8.0+ for a 20%+ performance boost!

Target PHP version: 5.6 (set by config file).
Scanning files...
Analyzing files...

E

ERROR: TooManyTemplateParams - src/Foo.php:7:22 - Foo has too many template params when extending IteratorAggregate, expecting 0 (see https://psalm.dev/184)
class Foo implements IteratorAggregate


ERROR: InvalidAttribute - src/Foo.php:25:4 - The class ReturnTypeWillChange doesn't have the Attribute attribute (see https://psalm.dev/242)
        #[\ReturnTypeWillChange]


------------------------------
2 errors found
------------------------------

Checks took 0.12 seconds and used 26.961MB of memory
Psalm was able to infer types for 100% of the codebase

The same (2 errors) result is given when I download the PHAR from github.

Why would this happen, and how to work around it using the PHAR?

@psalm-github-bot
Copy link

Hey @andraaspar, can you reproduce the issue on https://psalm.dev ?

@andraaspar
Copy link
Author

No, because it does not support using the PHAR.

@weirdan
Copy link
Collaborator

weirdan commented Feb 24, 2023

Does it also happen with the following phar file (it's master@1b2598c)?

https://output.circle-artifacts.com/output/job/a9c24685-6a9e-4326-9684-5f5249cdc9f9/artifacts/0/build/psalm.phar

@weirdan
Copy link
Collaborator

weirdan commented Feb 24, 2023

Does it also happen with the following phar file (it's master@1b2598c)?

Because it doesn't for me.

@andraaspar
Copy link
Author

@weirdan : Yes, it still happens:

PowerShell 7.3.2
PS D:\Workspaces\psalm-test2> php .\psalm.phar --no-cache
Warning: "findUnusedBaselineEntry" will be defaulted to "true" in Psalm 6. You should explicitly enable or disable this setting.

Install the opcache extension to make use of JIT on PHP 8.0+ for a 20%+ performance boost!

Target PHP version: 5.6 (set by config file).
Scanning files...
Analyzing files...

E

ERROR: TooManyTemplateParams - src/Foo.php:7:22 - Foo has too many template params when extending IteratorAggregate, expecting 0 (see https://psalm.dev/184)
class Foo implements IteratorAggregate


ERROR: InvalidAttribute - src/Foo.php:25:4 - The class ReturnTypeWillChange doesn't have the Attribute attribute (see https://psalm.dev/242)
        #[\ReturnTypeWillChange]


------------------------------
2 errors found
------------------------------

Checks took 0.09 seconds and used 38.036MB of memory
Psalm was able to infer types for 100% of the codebase
PS D:\Workspaces\psalm-test2> php --version
PHP 8.1.13 (cli) (built: Nov 22 2022 15:49:14) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.13, Copyright (c) Zend Technologies

@andraaspar
Copy link
Author

Hint: If I install psalm in the project folder using composer, then running the PHAR in the same folder also results in no issues found.

@andraaspar
Copy link
Author

Here is the repo, with the PHAR you provided: https://github.com/andraaspar/rqqf6z

@weirdan
Copy link
Collaborator

weirdan commented Feb 27, 2023

image

I suppose, now we need someone who runs Windows.

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

Successfully merging a pull request may close this issue.

2 participants